-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFreeBSD-EasyInstall.sh
307 lines (288 loc) · 7.82 KB
/
FreeBSD-EasyInstall.sh
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/sh
agree=0
if [ "$1" = "-y" ] ;
then
agree=1
fi
welcome_screen() {
clear
echo
echo
echo
echo
echo
echo
echo
echo " ______ ______ ___________ "
echo " | ___| | ___ \\/ ___| _ \\"
echo " | |_ _ __ ___ ___| |_/ /\\ '--.| | | | |-- _ | _ __|_ | |"
echo " | _| '__/ _ \\/ _ \\ ___ \\ '--. \\ | | | |--/\\ ( \\ / | | |( | /\\ | |"
echo " | | | | | __/ __/ |_/ //\__/ / |/ / |__\\/\\_) \\/ | | |_) | \\/\\ \ \\"
echo " \\_| |_| \\___|\\___\\____/ \\____/|___/ V"
echo
echo " by RooiGevaar19, 2023"
}
choose_desktop() {
flag=0
dktop=0
while [ "$flag" != "1" ]
do
clear
echo "What desktop do you want to have?"
echo " 1 - Xfce"
echo " 2 - GNOME"
echo " 3 - KDE Plasma"
echo
echo " 0 - Exit"
read ans_a
echo $ans_a | grep "[^0-3]" > /dev/null 2>&1
if [ "$?" -ne "0" ];
then
flag=1
case $ans_a in
1)
echo "You've picked XFCE."
dktop=1
;;
2)
echo "You've picked GNOME."
dktop=2
;;
3)
echo "You've picked KDE."
dktop=3
;;
0)
echo "Quitting."
exit 0
;;
*)
fatal_error 1 "Error when picking up the desktop. This desktop does not exist or is not supported."
;;
esac
fi
done
return $dktop;
}
fatal_error () {
code=$1
msg=$2
echo $msg
exit $code
}
update_packages () {
if [ "$agree" -eq "1" ] ;
then
pkg upgrade -y
if [ "$?" -ne "0" ] ;
then
fatal_error 2 "Error when updating FreeBSD packages."
# TODO: add continue option
fi
else
pkg upgrade
if [ "$?" -ne "0" ] ;
then
fatal_error 2 "Error when updating FreeBSD packages."
# TODO: add continue option
fi
fi
}
# TODO: Add support for slim, gdm
install_desktop () {
dk=$1
case $dk in
xfce)
if [ "$agree" -eq "1" ] ;
then
pkg install -y xorg lightdm lightdm-gtk-greeter
thunar-archive-plugin xarchiver xfce4-pulseaudio-plugin xfce
else
pkg install xorg lightdm lightdm-gtk-greeter
thunar-archive-plugin xarchiver xfce4-pulseaudio-plugin xfce
fi
;;
gnome)
if [ "$agree" -eq "1" ] ;
then
pkg install -y xorg gdm gnome gnome-desktop gnome-session
else
pkg install xorg gdm gnome gnome-desktop gnome-session
fi
#break
;;
kde)
if [ "$agree" -eq "1" ] ;
then
pkg install -y kde5 plasma5-plasma kde-baseapps sddm xorg
else
pkg install kde5 plasma5-plasma kde-baseapps sddm xorg
fi
;;
*)
fatal_error 3 "Error when searching $dk. This desktop does not exist or is not supported."
;;
esac
if [ "$?" -ne "0" ] ;
then
fatal_error 4 "Error when installing $dk."
fi
}
configure_desktop () {
dk=$1
echo '#------------------------------' >> /etc/rc.conf
echo '# freebsd-easyinstall addition ' >> /etc/rc.conf
echo 'dbus_enable="YES"' >> /etc/rc.conf
echo 'hald_enable="YES"' >> /etc/rc.conf
echo 'moused_enable="YES"' >> /etc/rc.conf
case $dk in
xfce)
echo 'lightdm_enable="YES"' >> /etc/rc.conf
echo 'exec startxfce4' >> /root/.xinitrc
;;
gnome)
echo 'gnome_enable="YES"' >> /etc/rc.conf
echo 'gdm_enable="YES"' >> /etc/rc.conf
echo 'proc /proc procfs rw 0 0' >> /etc/fstab
#break
;;
kde)
echo 'sddm_enable="YES"' >> /etc/rc.conf
echo 'proc /proc procfs rw 0 0' >> /etc/fstab
#break
;;
*)
fatal_error 5 "Error when searching $dk. This desktop does not exist or is not supported."
;;
esac
if [ "$?" -ne "0" ] ;
then
fatal_error 6 "Error when configuring $dk."
fi
# TODO: check if the lines already exist in the files
}
setup_user () {
usern=$1
echo "User: $usern"
home_dir=`getent passwd "$usern" | cut -d : -f 6`
if [ "a$home_dir" != "a" ] ; then
echo "User exists"
echo "Home directory: $home_dir"
cp /root/.xinitrc "$home_dir/.xinitrc"
pw groupmod video -m $usern
pw groupmod wheel -m $usern
echo "Done setting up $usern."
else
echo "Error when setting up $usern. This user probably does not exist."
fi
}
configure_users_dialog () {
dktop_name=$1
ans_a="1"
flag="0"
while [ "$flag" != "1" ]
do
echo
echo "What do you want to do?"
echo " 1 - Make all users be able to log in via $dktop_name"
echo " 2 - Choose which users can log in via $dktop_name"
read ans_a
echo $ans_a | grep "[^(1|2)]" > /dev/null 2>&1
if [ "$?" -ne "0" ];
then
flag="1"
if [ "$ans_a" = "1" ] ;
then
for item in `cat /etc/passwd | awk -F':' '{if ($3 >= 1000 && $3 <= 10000) print $1;}'`
do
setup_user $item
done
else
usern="user"
while [ "s$usern" != "s" ]
do
echo
echo "Type an username of the user (or press RETURN to quit)"
read usern
if [ "s$usern" != "s" ] ;
then
setup_user $usern
fi
done
fi
fi
done
ans_a="1"
flag="0"
while [ "$flag" != "1" ]
do
echo
echo "Do you want to prevent root from logging in via Xfce?"
echo " 0 - No"
echo " 1 - Yes"
read ans_a
echo $ans_a | grep "[^(0|1)]" > /dev/null 2>&1
if [ "$?" -ne "0" ];
then
flag="1"
if [ "$ans_a" = "1" ] ;
then
rm /root/.xinitrc
fi
fi
done
# TODO: add install basic software option
}
# ===========================================================================
#
# MAIN
#
# -----------------------------------------------
# install necessary things
clear
welcome_screen
sleep 1
clear
choose_desktop
opt=$?
dktop=""
case $opt in
1)
dktop="xfce"
dktop_name="XFCE"
;;
2)
dktop="gnome"
dktop_name="GNOME"
;;
3)
dktop="kde"
dktop_name="KDE Plasma"
;;
*)
fatal_error 3 "Error when searching $dktop. This desktop does not exist or is not supported."
;;
esac
echo "------------------------------------------------------------------"
echo "Updating FreeBSD packages..."
update_packages
echo "------------------------------------------------------------------"
echo "Installing $dktop_name..."
install_desktop $dktop
#------------------------------------------------
# set up xfce things
echo "------------------------------------------------------------------"
echo "Applying global $dktop_name settings..."
configure_desktop $dktop
#------------------------------------------------
# set up users that might log in using XFCE
if [ "$dktop" = "xfce" ] ;
then
echo
echo "------------------------------------------------------------------"
echo "Setting up users that may log in via $dktop_name..."
configure_users_dialog $dktop_name
fi
echo
echo "------------------------------------------------------------------"
echo "Done. Please reboot."