-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodo-bullseye-installer
339 lines (267 loc) · 10.4 KB
/
dodo-bullseye-installer
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
set -e
# ------------------------------------------------------------------------------
# output format
# ------------------------------------------------------------------------------
out() {
printf "\n"
while IFS= read -r line; do
printf "\033[0;31m>>>\033[0m \033[0;33m%s\033[0m\n" "$line"
done
}
# ------------------------------------------------------------------------------
# trap on_exit
# ------------------------------------------------------------------------------
function on_exit {
if [[ "$COMPLETED" != true ]]; then
out <<< "Something went wrong. Not completed!"
exit 1
else
cp $TMPL/var/www/html/index.html /var/www/html/index.html
out <<EOF
############################################################
COMPLETED SUCCESSFULLY
############################################################
Installation Duration: $DURATION
VNC password: $PASSWD
check README-DODO.txt file or GitHub repo to learn
how to connect
GitHub: https://github.com/emrahcom/dodo
EOF
if [[ "$ACTIVE_SESSION" = true ]]; then
out <<EOF
It's detected an already running session.
Please reboot to activate new settings!
EOF
fi
out <<EOF
############################################################
EOF
exit 0
fi
}
COMPLETED=false
trap on_exit EXIT
# ------------------------------------------------------------------------------
# environment
# ------------------------------------------------------------------------------
export START_TIME=$(date +%s)
export APT_PROXY=$APT_PROXY
export DEBIAN_FRONTEND=noninteractive
export BASEDIR=$(pwd)
export REMOTE=https://github.com/emrahcom/dodo.git
export REPO=/tmp/dodo-repo
export TMPL=$REPO/templates/debian-bullseye-mate
# ------------------------------------------------------------------------------
# distro check
# ------------------------------------------------------------------------------
out <<< "distro checking..."
DISTRO=$(lsb_release -c | cut -d: -f2 | xargs)
if [[ "$DISTRO" != "bullseye" ]]; then
out <<< "unsupported distro"
exit 1
fi
# ------------------------------------------------------------------------------
# packages
# ------------------------------------------------------------------------------
out <<< "installing packages..."
for i in $(seq 3); do
apt-get -y --allow-releaseinfo-change update && sleep 3 && break
done
apt-get $APT_PROXY -y install apt-utils \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold"
apt-get $APT_PROXY -y upgrade \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold"
apt-get -y autoremove --purge
apt-get $APT_PROXY -y install apt-transport-https gnupg
apt-get $APT_PROXY -y install wget curl git rsync jq
apt-get $APT_PROXY -y install zsh tmux vim ack autojump htop
apt-get $APT_PROXY -y install ssl-cert ca-certificates openssl
apt-get $APT_PROXY -y install task-desktop task-mate-desktop dconf-cli
apt-get $APT_PROXY -y install chromium firefox-esr
apt-get $APT_PROXY -y install vlc totem ffmpeg
apt-get $APT_PROXY -y install x11vnc pwgen
apt-get $APT_PROXY -y install nginx certbot
apt-get $APT_PROXY -y install python3-pip python3-setuptools \
python3-wheel
pip3 install websockify
apt-get -y purge upower || true
apt-get -y autoremove --purge
# ------------------------------------------------------------------------------
# git clone
# ------------------------------------------------------------------------------
out <<< "cloning Git repo..."
rm -rf $REPO
git clone --depth=1 $REMOTE $REPO
# ------------------------------------------------------------------------------
# disabled desktop services
# ------------------------------------------------------------------------------
out <<< "disabling some desktop services..."
systemctl stop lightdm.service
systemctl disable lightdm.service
systemctl stop ModemManager.service
systemctl disable ModemManager.service
systemctl stop wpa_supplicant.service
systemctl disable wpa_supplicant.service
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
# ------------------------------------------------------------------------------
# dconf
# ------------------------------------------------------------------------------
out <<< "dconf configuration..."
mkdir -p /etc/dconf/profile
mkdir -p /etc/dconf/db/dodo.d
cp $TMPL/etc/dconf/profile/user /etc/dconf/profile/
cp $TMPL/etc/dconf/db/dodo.d/* /etc/dconf/db/dodo.d/
dconf update
# ------------------------------------------------------------------------------
# vnc
# ------------------------------------------------------------------------------
out <<< "VNC..."
cp $TMPL/usr/local/bin/vnc-start /usr/local/bin/
chmod 755 /usr/local/bin/vnc-start
# vnc password
if [[ -f "/root/README-DODO.txt" ]]; then
PASSWD=$(egrep -i '^Default VNC password:' /root/README-DODO.txt | \
cut -d: -f2 | xargs)
fi
[[ -z "$PASSWD" ]] && PASSWD=$(pwgen -B 12)
mkdir -p /etc/skel/.vnc
x11vnc -storepasswd $PASSWD /etc/skel/.vnc/passwd
[[ -f "/root/README-DODO.txt" ]] && \
mv /root/README-DODO.txt /root/README-DODO.txt.$(date +'%Y-%m-%d-%H%M%S')
cp $TMPL/root/README-DODO.txt /root/
sed -i "s/___PASSWD___/$PASSWD/g" /root/README-DODO.txt
# ------------------------------------------------------------------------------
# skel
# ------------------------------------------------------------------------------
out <<< "skel configuration..."
cp -arp $TMPL/etc/skel/.config /etc/skel/
cp $TMPL/etc/skel/.zshrc /etc/skel/
cp $TMPL/etc/skel/.vimrc /etc/skel/
cp $TMPL/etc/skel/.tmux.conf /etc/skel/
# ------------------------------------------------------------------------------
# self-signed certificates
# ------------------------------------------------------------------------------
out <<< "self-signed certificate..."
# the CA key and the CA certificate
[[ ! -d "/root/dodo-ssl" ]] && mkdir /root/dodo-ssl
if [[ ! -f "/root/dodo-ssl/dodo-ca.pem" ]]; then
cd /root/dodo-ssl
rm -f dodo-ca.key
DATE=$(date +"%Y%m%d%H%M%S")
openssl req -nodes -new -x509 -days 10950 \
-keyout dodo-ca.key -out dodo-ca.pem \
-subj "/O=dodo/OU=CA/CN=dodo $DATE-$RANDOM"
fi
# self-signed certificate for the dodo domain
cd /root/dodo-ssl
rm -f /root/dodo-ssl/ssl-dodo.*
# the extension file for multiple hosts:
cat >ssl-dodo.ext <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
EOF
HOSTNAME_SHORT=$(hostname)
HOSTNAME_FQDN=$(hostname -f)
echo "DNS.1 = $HOSTNAME_SHORT" >>ssl-dodo.ext
if [[ -n "$HOSTNAME_FQDN" ]] && [[ "$HOSTNAME_SHORT" != "$HOSTNAME_FQDN" ]]
then
echo "DNS.2 = $HOSTNAME_FQDN" >>ssl-dodo.ext
else
HOSTNAME_FQDN=$HOSTNAME_SHORT
fi
i=1
for ip in $(hostname -I); do
echo "IP.$i = $ip" >>ssl-dodo.ext
((i = i + 1))
done
# the dodo key and the dodo certificate
openssl req -nodes -newkey rsa:2048 \
-keyout ssl-dodo.key -out ssl-dodo.csr \
-subj "/O=dodo/OU=TLS/CN=$HOSTNAME_FQDN"
openssl x509 -req -CA dodo-ca.pem -CAkey dodo-ca.key -CAcreateserial \
-days 10950 -in ssl-dodo.csr -out ssl-dodo.pem \
-extfile ssl-dodo.ext
# copy into /etc/ssl
cp ssl-dodo.pem /etc/ssl/certs/
cp ssl-dodo.key /etc/ssl/private/
# ------------------------------------------------------------------------------
# websockify
# ------------------------------------------------------------------------------
out <<< "websockify config..."
cp $TMPL/usr/local/sbin/websockify-unsecure /usr/local/sbin/
chmod 744 /usr/local/sbin/websockify-unsecure
cp $TMPL/usr/local/sbin/websockify-secure /usr/local/sbin/
chmod 744 /usr/local/sbin/websockify-secure
cp $TMPL/etc/systemd/system/websockify-unsecure.service /etc/systemd/system/
cp $TMPL/etc/systemd/system/websockify-secure.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable websockify-unsecure.service
systemctl start websockify-unsecure.service
systemctl enable websockify-secure.service
systemctl start websockify-secure.service
# ------------------------------------------------------------------------------
# novnc
# ------------------------------------------------------------------------------
out <<< "novnc config..."
if [[ -d "/var/www/novnc" ]]; then
cd /var/www/novnc
git pull
else
git clone --depth=1 https://github.com/novnc/noVNC.git /var/www/novnc
fi
# ------------------------------------------------------------------------------
# nginx
# ------------------------------------------------------------------------------
out <<< "nginx config..."
cp /root/dodo-ssl/dodo-ca.pem /var/www/html/
cp $TMPL/etc/nginx/sites-available/dodo.conf /etc/nginx/sites-available/
ln -sf ../sites-available/dodo.conf /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
systemctl restart nginx
# ------------------------------------------------------------------------------
# certbot
# ------------------------------------------------------------------------------
out <<< "certbox config..."
cp $TMPL/usr/local/sbin/set-letsencrypt-cert /usr/local/sbin/
chmod 744 /usr/local/sbin/set-letsencrypt-cert
mkdir -p /etc/systemd/system/certbot.service.d
cp $TMPL/etc/systemd/system/certbot.service.d/override.conf \
/etc/systemd/system/certbot.service.d/
systemctl daemon-reload
# ------------------------------------------------------------------------------
# user dodo
# ------------------------------------------------------------------------------
out <<< "dodo account..."
# adduser dodo
if [[ -z "$(id dodo 2>/dev/null)" ]]; then
adduser dodo --disabled-password --gecos ""
adduser dodo audio
adduser dodo video
chsh -s /bin/zsh dodo
fi
# ------------------------------------------------------------------------------
# autologin on tty1
# ------------------------------------------------------------------------------
out <<< "tty autostart..."
cp -arp $TMPL/etc/systemd/system/getty@tty1.service.d /etc/systemd/system/
systemctl daemon-reload
# if this is a reinstall time then reboot is needed
if pgrep -u dodo >/dev/null; then
ACTIVE_SESSION=true
else
systemctl restart getty@tty1.service
fi
# ------------------------------------------------------------------------------
# completed
# ------------------------------------------------------------------------------
END_TIME=$(date +%s)
DURATION=$(date -u -d "0 $END_TIME seconds - $START_TIME seconds" +"%H:%M:%S")
COMPLETED=true
# vim: tw=80 ts=4 sw=4 sts=4 et