-
Notifications
You must be signed in to change notification settings - Fork 12
/
instant-workstation
executable file
·279 lines (255 loc) · 6.71 KB
/
instant-workstation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#! /bin/sh
#
# SPDX-FileCopyrightText: 2019 Adriaan de Groot <adridg@FreeBSD.org>
# SPDX-License-Identifier: BSD-2-Clause
#
### USAGE
#
# This shell script can be run on a freshly-installed FreeBSD system
# to create an "instant-workstation". It uses dialog(1) for user-input,
# and does a best-effort to install what's needed.
# - a desktop environment
# - a display manager (and X and the rest)
# - graphics drivers
# - tooling for various tasks
#
#
# Usage:
# instant-workstation [-h] [--selfupdate|-U]
#
# Usage:
# -h show this help
# -U, --selfupdate update the script and run it again
#
# Run with --selfupdate to update the script from its canonical source
# (useful for testing updates to the script itself).
#
### END USAGE
if test "x$1" = "x-h" ; then
sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0"
exit 0
fi
# Get a temporary location for dialog output
base=`basename $0`
CONFIG=`mktemp /tmp/${base}.XXXXXX` || { echo "! Cannot create temporary file." ; exit 1 ; }
setup_polkit=false
### SELF-UPDATE
#
#
if test "x$1" = "x--selfupdate" -o "x$1" = "x-U"
then
/usr/bin/fetch -o "${CONFIG}" https://raw.githubusercontent.com/adriaandegroot/FreeBSDTools/main/bin/instant-workstation
/bin/mv "${CONFIG}" "$0" ; exit 0
fi
### USER INPUT
#
# Pick one or more DE's, and exactly one DM
# NOTE: each ID should be distinct
#
/usr/bin/dialog --no-tags --separate-output \
--checklist "Desktop Environment" 0 0 0 \
kde5 "KDE Plasma Desktop" 0 \
gnome3 "GNOME Desktop" 0 \
xfce4 "XFCE Desktop" 0 \
mate "MATE Desktop" 0 \
stump "STUMP WM" 0 \
twm "TWM, X like the '90s" 0 \
--checklist "Extra Software for .." 0 0 0 \
kdedevel "C++ Development" 0 \
telegram "Telegram" 0 \
matrix "Matrix" 0 \
irc "IRC" 0 \
latex "LaTeX" 0 \
management "Host Management" 0 \
--radiolist "Display Manager" 0 0 0 \
sddm "SDDM" 1 2> ${CONFIG}
### PACKAGE SELECTION
#
# Turn the user input into specific packages and sysrc
# commands to execute.
#
packages=""
sysrc=""
sysctl=""
for line in `cat "${CONFIG}"`
do
case "x$line" in
"xkde5")
packages="$packages x11/kde5 devel/dbus www/falkon"
sysrc="$sysrc dbus_enable=YES"
sysctl="$sysctl net.local.stream.recvspace=65536 net.local.stream.sendspace=65536"
;;
"xgnome3")
packages="$packages x11/gnome3"
;;
"xxfce4")
packages="$packages x11-wm/xfce4"
;;
"xmate")
packages="$packages x11/mate-desktop"
;;
"xstump")
packages="$packages x11-wm/stumpwm"
;;
"xtwm")
packages="$packages x11-wm/twm x11/xterm x11-fonts/xfontsel"
;;
"xsddm")
packages="$packages x11/sddm"
sysrc="$sysrc sddm_enable=YES"
setup_polkit=true
;;
"xkdedevel")
# TODO: distinguish DE and install matching gitk and IDE?
packages="$packages devel/ccache devel/cmake devel/git devel/kdevelop devel/qgit devel/ninja"
;;
"xtelegram")
packages="$packages net-im/telegram-desktop"
;;
"xmatrix")
packages="$packages net-im/nheko"
;;
"xirc")
packages="$packages irc/quassel irc/irssi"
;;
"xlatex")
packages="$packages print/texlive-base print/tex-basic-engines print/tex-formats"
;;
"xmanagement")
packages="$packages sysutils/screen sysutils/ezjail"
;;
"*")
echo "! Unrecognized tag '${line}' in ${CONFIG}"
exit 1
;;
esac
done
rm "${CONFIG}"
### HARDWARE SUPPORT
#
# Best-guess for necessary hardware drivers
#
fbsd_version=$( /usr/bin/uname -r | /usr/bin/sed 's/-.*//' )
# The reporting from pciconf has changed, too
case "x${fbsd_version}" in
"x1[12]."*)
vga_product=$( /usr/sbin/pciconf -l | /usr/bin/awk '/^vgapci/{ print substr($4,length($4)-3); }' )
vga_vendor=$( /usr/sbin/pciconf -l | /usr/bin/awk '/^vgapci/{ print substr($4,8,4); }' )
;;
"x13."*)
vga_product=$( /usr/sbin/pciconf -l | /usr/bin/awk '/^vgapci/{ for(i=2; i<=NF; i++) { if ( substr($i,0,7)=="device=" ) print substr($i,10); } }' )
vga_vendor=$( /usr/sbin/pciconf -l | /usr/bin/awk '/^vgapci/{ for(i=2; i<=NF; i++) { if ( substr($i,0,7)=="vendor=" ) print substr($i,10); } }' )
;;
*)
echo "Unrecognized FreeBSD version '${fbsd_version}'"
exit 1
;;
esac
# Look for Intel graphics
if test 8086 = "${vga_product}"
then
case "x${fbsd_version}" in
"x12."[012])
packages="$packages graphics/drm-fbsd12.0-kmod"
;;
"x11."[234])
packages="$packages graphics/drm-fbsd11.2-kmod"
;;
"x13."*)
:
;;
*)
echo "Unrecognized FreeBSD version '${fbsd_version}'"
exit 1
;;
esac
fi
# Look for NVidia graphics
if test 10de = "${vga_vendor}"
then
packages="nvidia-driver nvidia-xconfig"
fi
### VIRTUALBOX
#
#
if test beef = "${vga_vendor}"
then
# Virtualbox Support
packages="$packages emulators/virtualbox-ose-additions"
sysrc="$sysrc vboxguest_enable=YES vboxservice_enable=YES"
fi
### VMWARE
#
#
if test 0405 = "${vga_vendor}"
then
# VMWare Workstation Support
packages="$packages open-vm-tools xf86-input-vmmouse xf86-video-vmware"
sysrc="$sysrc dbus_enable=YES moused_enable=YES vmware_guest_vmblock_enable=YES vmware_guest_vmhgfs_enable=YES vmware_guest_vmmemctl_enable=YES vmware_guest_vmxnet_enable=YES vmware_guestd_enable=YES"
fi
### X11
#
#
packages="$packages x11/xorg"
### INSTALLATION
#
#
if test -z "$packages"
then
echo "! No packages selected for installation."
exit 1
fi
command="/usr/sbin/pkg install $packages"
if test -n "$sysrc"
then
command="$command ; /usr/sbin/sysrc $sysrc";
fi
if test -n "$sysctl"
then
for l in $sysctl ; do
command="$command ; echo \"$l\" >> /etc/sysctl.conf"
done
fi
echo "su root for installation and configuration"
su root -c "$command"
### VMWARE Post installation
#
#
if test 0405 = "${vga_vendor}"
then
echo 'Updating vmware X configuration'
mkdir -p /usr/local/etc/X11/xorg.conf.d
# X11 configuration
echo '# Temporary fix to set vmmouse
Section "ServerFlags"
Option "AutoAddDevices" "false"
EndSection
Section "InputDevice"
Identifier "Mouse0"
Driver "vmmouse"
Option "Device" "/dev/sysmouse"
EndSection
Section "Device"
Identifier "Card0"
Driver "vmware"
EndSection' > /usr/local/etc/X11/xorg.conf.d/vmware.conf
# Enable 3D acceleration when available
echo 'To enable 3D acceleration, add your username(s) to the ''video'' group with:'
echo ' pw groupmod video -m <username>'
fi
### SDDM Post installation
#
#
if $setup_polkit ; then
echo 'Allowing the ''operator'' group to shut modify system state from SDDM.'
polkit_file="/usr/local/etc/polkit-1/rules.d/40-operator-group-sddm.rules"
su root -c "cat > $polkit_file" <<EOF
// Operators may stop the machine -- that is both restart and shutdown
// from inside the KDE Plasma desktop, when used with SDDM
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.consolekit.system.stop" && subject.isInGroup("operator")) {
return polkit.Result.YES;
}
});
EOF
fi