-
Notifications
You must be signed in to change notification settings - Fork 7
/
createVM.sh
212 lines (179 loc) · 7.77 KB
/
createVM.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
#!/bin/bash
################################################################################
#
# BrowserBox, a VM with Firefox preinstalled and preconfigured
#
# (c) 2020,2021 Tom Stöveken
#
# License: GPLv3 ff
#
# This file downloads an ISO image of Debian Netinstaller,
# remasters a new ISO that installs and configures the VM unattended.
#
# Firefox is protected and configured with:
# - Firefox runs inside a VM, so the HOST system is protected
# - Firejail (limits permissions to essential ones)
# - important extensions like uBlock, PrivacyBadger, ...
# - arkenfox/user.js (improves privacy, reduces telemetry)
#
# To start the process run:
# $ bash createVM.sh
#
# Once the VM is created you can use the BrowserBox
#
################################################################################
ISO="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-11.3.0-amd64-netinst.iso"
BASEFOLDER="$(pwd)"
################################################################################
cd "$BASEFOLDER"
# required programs that must be installed manually, I assume coreutils is present anyway
REQUIRED_PROGRAMS=(
"zenity|zenity is missing, please install it with \"sudo apt install zenity\""
"wget|wget is missing, please install it with \"sudo apt install wget\""
"xorriso|xorriso is missing, please install with \"sudo apt install xorriso\""
"VBoxManage|VirtualBox is missing, please install with \"sudo apt install virtualbox virtualbox-guest-additions-iso\""
"qemu-img|qemu-img is missing, please install with \"sudo apt install qemu-utils\""
"vmdb2|vmdb2 is missing, please install with \"sudo apt-get install vmdb2\""
"sudo|sudo is missing, please install with \"apt-get install sudo\""
)
SUCCESS="yes"
for i in "${REQUIRED_PROGRAMS[@]}"; do
# we change $IFS here, but BASH restores it - so no need to save/restore it ourselves
echo "$i" | while IFS="|" read PROG HINT; do
hash $PROG > /dev/null 2>&1
#To find out which package contains the command:
#dpkg -S $(realpath $(which $PROG))
if [ $? -ne 0 ]; then
echo "$HINT"
SUCCESS="no"
fi
done
done
if [ "$SUCCESS" == "no" ]; then
exit 1
fi
# vmdb2 requires root rights, thus we need to use sudo
# Ask now or otherwise the user is not there to answer the prompt
PASSWD="$(zenity --password --title="required for vmdb2")" || exit 1
# create a window with a progress bar, get texts through filedescriptor 3
exec 3> >(zenity --progress --title="Create VM" --percentage=0 --width=800 --no-cancel --auto-close)
# little helper function for the progress bar window
function msg {
echo "# $@" >&3
}
function percent {
echo "$1" >&3
}
# clean any Releases to avoid confusion with previous runs
rm -rf "$BASEFOLDER/Releases/"
################################################################################
# Create modified debian ISO:
# - Unpack,
# - Change image content,
# - Remaster
################################################################################
PERCENT_START=0
PERCENT_END=10
percent $PERCENT_START
msg "downloading ISO"
if [ ! -f "$BASEFOLDER/${ISO##*/}" ]; then
wget --no-verbose --show-progress "$ISO" 2>&1 | while read line; do
DWN=$(echo "$line" | sed -E 's/[^0-9]*([0-9]{1,})%[^0-9]*/---\1---/' | sed 's/.*---\(.*\)---.*/\1/g')
percent "$(( PERCENT_START + (DWN*(PERCENT_END-PERCENT_START)/100) ))"
msg "downloaded $DWN % of ${ISO##*/}"
done
fi
if [ ! -f "$BASEFOLDER/${ISO##*/}" ]; then
msg "Error: Downloading ISO failed"
percent 99
sleep 5
percent 100
exit 1
fi
percent PERCENT_END
#unpack the ISO
percent 20
cd $BASEFOLDER || exit 1
TMPFOLDER=$(mktemp -d ISO_XXXX) || exit 1
msg "extracting ISO image to $TMPFOLDER"
xorriso -osirrox on -indev "$BASEFOLDER/${ISO##*/}" -extract / "$TMPFOLDER"
# change the CD contents
percent 30
msg "modifying CD content"
chmod -R +w "$TMPFOLDER"
cp postinst.sh "$TMPFOLDER/"
#download arkenfox user.js updater script
wget -O files/home/bbuser/.mozilla/firefox/bbuser.default/updater.sh https://raw.githubusercontent.com/arkenfox/user.js/master/updater.sh
# download Add-Ons aka Extensions
msg "downloading extensions"
# The method used below works for FF-Debian-Buster-Version which happens to be "68.xx" (must be <= 73),
# however more recent versions (version >= 74) must use "policies" to install extensions unattended
# (the news: https://blog.mozilla.org/addons/2019/10/31/firefox-to-discontinue-sideloaded-extensions/)
# (the new way for FF-version >= 74: https://github.com/mozilla/policy-templates/#extensions)
# (the old way for FF-version <= 73: https://extensionworkshop.com/documentation/publish/distribute-sideloading/#standard-extension-folders)
# The IDs of the extensions can be found after installing them and then navigating to "about:support" --> table "Add-Ons"
FF_EXTENSIONS_FOLDER="$BASEFOLDER/files/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
mkdir -p "$FF_EXTENSIONS_FOLDER"
#delete all previous (maybe outdated) XPI files in that folder
find "$FF_EXTENSIONS_FOLDER/" -mindepth 1 -delete
# uBlock
if [ ! -f "$FF_EXTENSIONS_FOLDER/[email protected]" ]; then
wget -O "$FF_EXTENSIONS_FOLDER/[email protected]" https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi
fi
# Privacy Badger
if [ ! -f "$FF_EXTENSIONS_FOLDER/[email protected]" ]; then
wget -O "$FF_EXTENSIONS_FOLDER/[email protected]" https://addons.mozilla.org/firefox/downloads/latest/privacy-badger17/
fi
# Decentral Eyes
if [ ! -f "$FF_EXTENSIONS_FOLDER/[email protected]" ]; then
wget -O "$FF_EXTENSIONS_FOLDER/[email protected]" https://addons.mozilla.org/firefox/downloads/latest/decentraleyes/latest.xpi
fi
# NoScript
if [ ! -f "$FF_EXTENSIONS_FOLDER/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi" ]; then
wget -O "$FF_EXTENSIONS_FOLDER/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi" https://addons.mozilla.org/firefox/downloads/latest/noscript/latest.xpi
fi
#modify syslinux to make it automatically run the text based installer
sed -i 's/timeout 0/timeout 20/g' "$TMPFOLDER/isolinux/isolinux.cfg"
sed -i 's/default installgui/default install/g' "$TMPFOLDER/isolinux/gtk.cfg"
sed -i 's/menu default//g' "$TMPFOLDER/isolinux/gtk.cfg"
sed -i 's/label install/label install\n\tmenu default/g' "$TMPFOLDER/isolinux/txt.cfg"
cp "$TMPFOLDER/isolinux/txt.cfg" "$TMPFOLDER/isolinux/txt.cfg.pre"
for LANG in "en" "de"; do
case "$LANG" in
de)
cp "$TMPFOLDER/isolinux/txt.cfg.pre" "$TMPFOLDER/isolinux/txt.cfg"
sed -i 's/append \(.*\)/append preseed\/file=\/cdrom\/preseed.cfg locale=de_DE.UTF-8 keymap=de language=de country=DE \1/g' "$TMPFOLDER/isolinux/txt.cfg"
cp preseed_de.cfg "$TMPFOLDER/preseed.cfg"
;;
en)
cp "$TMPFOLDER/isolinux/txt.cfg.pre" "$TMPFOLDER/isolinux/txt.cfg"
sed -i 's/append \(.*\)/append preseed\/file=\/cdrom\/preseed.cfg locale=en_GB.UTF-8 keymap=en language=en country=GB \1/g' "$TMPFOLDER/isolinux/txt.cfg"
cp preseed_en.cfg "$TMPFOLDER/preseed.cfg"
;;
*)
echo "unknown language"
exit 1
;;
esac
msg "combining files as tarball"
# make folder "files" a tarball and add it to the new ISOs root folder
tar -czvf "$TMPFOLDER/files.tgz" files/
#create ISO from folder with CD content
percent 40
msg "creating modified CD as new ISO"
#cp /usr/lib/ISOLINUX/isohdpfx.bin .
dd if="$BASEFOLDER/${ISO##*/}" bs=1 count=432 of=isohdpfx.bin
mkdir "$BASEFOLDER/Releases"
xorriso -as mkisofs -isohybrid-mbr isohdpfx.bin -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o "$BASEFOLDER/Releases/BrowserBox_$LANG.iso" "$TMPFOLDER"
percent 50
msg "creating VirtualBox VM"
bash VirtualBox/make.sh "$LANG" "$BASEFOLDER" "$BASEFOLDER/Releases/BrowserBox_$LANG.iso"
percent 70
msg "creating QEMU VM"
bash QEMU/make.sh "$LANG" "$BASEFOLDER" "$TMPFOLDER" "$PASSWD"
done
rm -rf "$TMPFOLDER"
rm isohdpfx.bin
percent 100
msg "Finished"
exec 3>&-