-
Notifications
You must be signed in to change notification settings - Fork 88
/
TorBOX_ModifyISO
395 lines (318 loc) · 11.6 KB
/
TorBOX_ModifyISO
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
# Safe as /home/username/TorBOX_source/TorBOX_ModifyISO
# Version: TorBOX 0.2.1
# Copyright: proper
#
# License: GPL v3 or any later
#
# Any changes you pull changes into this source will be also licensed
# under GPL v3 or any later. Additionally you grant proper the right to
# re-license your work under a different license. If that is not acceptable,
# you can either fork this source under GPL v3 or any later or contact proper.
# Contact proper, if you require this source code under different license.
script_help() {
echo "
# TorBOX_ModifyISO available commands:
#
# -create
# creates preseed.iso
#
# -delete
# unmounts and deletes ISO and build folder
#
# -help
# shows this help
"
}
# Enable debugging.
set -x
# Exit if there is an error
set -e
USERNAME="user"
# Thanks to
# http://askubuntu.com/questions/122505/how-do-i-create-completely-unattended-install-for-ubuntu
##############################################################################################
# error_handler
##############################################################################################
error_handler() {
echo "
#!!! ERROR in TorBOX_ModifyISO !!!#
#!!! ERROR in TorBOX_ModifyISO !!!#
#!!! ERROR in TorBOX_ModifyISO !!!#
"
echo "TorBOX_ModifyISO: unmounting iso..."
unmount_iso
echo "TorBOX_ModifyISO: Done."
touch /home/$USERNAME/TorBOX_binary/TORBOX_BUILD_FAILED
exit 1
}
root_check() {
######################################################
# Checking script environment
######################################################
# Check if we are root
if [ "$(id -u)" != "0" ]; then
echo "ERROR: This must be run as root (sudo)!"
exit 1
else
echo "INFO: Script running as root."
fi
}
##############################################################################################
# mount_and_copy_iso
##############################################################################################
mount_and_copy_iso() {
trap "error_handler" ERR INT TERM
mkdir -p /home/$USERNAME/TorBOX_binary/original_iso
# Ubuntu:
mount -o loop /home/$USERNAME/TorBOX_binary/ubuntu-12.04-server-i386.iso /home/$USERNAME/TorBOX_binary/original_iso
# Debian:
#mount -o loop /home/$USERNAME/TorBOX_binary/debian-6.0.5-i386-CD-1.iso /home/$USERNAME/TorBOX_binary/original_iso
mkdir -p /home/$USERNAME/TorBOX_binary/modified_iso
cp -rT /home/$USERNAME/TorBOX_binary/original_iso /home/$USERNAME/TorBOX_binary/modified_iso
}
##############################################################################################
# unmount_iso
##############################################################################################
unmount_iso() {
umount /home/user/TorBOX_binary/original_iso
rm -r /home/user/TorBOX_binary/original_iso
}
##############################################################################################
# modify_iso_general
##############################################################################################
modify_iso_general() {
trap "error_handler" ERR INT TERM
# This function...
# Is suboptimal, but it works.
#
# Please, if you make changes to this file, document your changes.
# Preseeding is not the most bugfree or easy thing.
# Changes my break it.
# If you make changes, please test if they are working!
#################################################################################
# lang
#################################################################################
echo en > /home/$USERNAME/TorBOX_binary/modified_iso/isolinux/lang
#################################################################################
# isolinux.cfg
#################################################################################
echo '
#Generated by TorBOX
default 1
prompt 1
timeout 5
label 1
# Ubuntu Precise
kernel /install/vmlinuz
append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/preseed.cfg --
# Or Debian Squeeze NOT WORKING YET
#kernel /install.386/vmlinuz
#append preseed/file=/cdrom/preseed.cfg initrd=/install.386/initrd.gz --
' > /home/$USERNAME/TorBOX_binary/modified_iso/isolinux/isolinux.cfg
#################################################################################
# ks.cfg
#################################################################################
# Create kickstart configuration file.
# Due to bugs in Ubuntu preseed we have to combine kickstart with preseed.
# Bugs such as choosing the language does not work with preseed alone.
echo '
#Generated by TorBOX
#Generated by Kickstart Configurator
#platform=x86
#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone --utc America/New_York
#Root password
rootpw --disabled
#Initial user
user user --fullname "user" --iscrypted --password $1$FfTFybF6$FCXsl5qUXudXAapnGj2mB/
#Use text mode install
text
#Install OS instead of upgrade
install
#Use CDROM installation media
cdrom
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
#zerombr yes
#Partition clearing information
#clearpart --all --initlabel
#Disk partitioning information
#part / --fstype ext4 --size 1 --grow --asprimary
#System authorization infomation
auth --useshadow --enablemd5
#Firewall configuration
firewall --disabled
#Do not configure the X Window System
skipx
' > /home/$USERNAME/TorBOX_binary/modified_iso/ks.cfg
#################################################################################
# preseed.cfg
#################################################################################
# Comment (proper):
# This file could look better. As soon as we move to file separeated source,
# we can keep more comments.
#
# Note:
# "" and $$ must be escaped!
#
# Thanks to:
# http://ubuntuforums.org/showthread.php?t=1145188
echo "
### Misc
d-i hw-detect/load_firmware boolean true
d-i pkgsel/install-language-support boolean false
d-i debian-installer/quiet boolean false
d-i debian-installer/splash boolean false
d-i pkgsel/update-policy select none
d-i popularity-contest popularity-contest/participate boolean false
### Network settings
#d-i netcfg/no_interfaces boolean true
#d-i netcfg/enable boolean false
#d-i netcfg/dhcp_failed note
#d-i netcfg/disable_dhcp boolean true
#d-i netcfg/dhcp_options select \"Do not configure the network at this time\"
#d-i netcfg/choose_interface select eth1
#
# This is a workaround.
# Only one network adapter attached while installing with preseed.
# The network cable is NOT attached.
# We still need to configure the network manually to *something*,
# due to limitations in upstream preseed netcfg.
# ("Do not configure network at this time" does not work.)
#
d-i netcfg/dhcp_failed note
d-i netcfg/disable_dhcp boolean true
d-i netcfg/dhcp_options select Configure network manually
d-i netcfg/get_nameservers string 192.168.0.1
d-i netcfg/get_ipaddress string 192.168.0.2
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.0.1
d-i netcfg/confirm_static boolean true
### Localization
# Preseeding only locale sets language, country and locale.
d-i debian-installer/country string US
d-i debian-installer/language string en
d-i debian-installer/locale string en_US.UTF-8
### Keyboard selection.
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
#d-i keyboard-configuration/variantcode string dvorak
### Mirror settings
#d-i mirror/protocol string ftp
#d-i mirror/country string manual
#d-i mirror/http/hostname string archive.ubuntu.com
#d-i mirror/http/directory string /ubuntu
#d-i mirror/http/proxy string
### Apt settings
d-i apt-setup/use_mirror boolean false
### Clock settings
d-i clock-setup/utc boolean true
d-i time/zone string UTC
d-i clock-setup/ntp boolean false
#d-i clock-setup/ntp-server string ntp.example.com
### Partitioning
d-i partman-auto/init_automatically_partition select biggest_free
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
# Thanks to https://bugs.launchpad.net/omsk/+bug/551947/comments/3
d-i partman-basicfilesystems/no_swap boolean false
# First example in partman-auto-recipe.txt without swap.
d-i partman-auto/expert_recipe string \
partman-auto/text/atomic_scheme :: \
500 10000 1000000 ext4 \
$primary{ } \
$bootable{ } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext4 } \
mountpoint{ / } .
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
### Base system installation
d-i base-installer/install-recommends boolean false
#d-i base-installer/kernel/image string linux-generic
### Account setup
#d-i passwd/root-login boolean false
#d-i passwd/make-user boolean false
d-i passwd/user-fullname string user
d-i passwd/username string user
d-i passwd/user-password password changeme
d-i passwd/user-password-again password changeme
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
### Grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/timeout string 2
### Finishing up the installation
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/poweroff boolean true
### X configuration
xserver-xorg xserver-xorg/config/device/driver select vesa
xserver-xorg xserver-xorg/autodetect_mouse boolean true
xserver-xorg xserver-xorg/autodetect_monitor boolean true
xserver-xorg xserver-xorg/config/monitor/selection-method \
select medium
xserver-xorg xserver-xorg/config/monitor/mode-list \
select 1024x768 @ 60 Hz
" > /home/$USERNAME/TorBOX_binary/modified_iso/preseed.cfg
}
##############################################################################################
# rebuild_iso
##############################################################################################
rebuild_iso() {
trap "error_handler" ERR INT TERM
mkisofs -D -r -V "ATTENDLESS_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /home/$USERNAME/TorBOX_binary/$ISO_NAME /home/$USERNAME/TorBOX_binary/modified_iso/
}
################################################################
# -create #
################################################################
if [[ "$1" = "-create" ]]; then
root_check
mount_and_copy_iso
unmount_iso
modify_iso_general
ISO_NAME="preseed.iso"
rebuild_iso
echo "BUILD INFO: Done, if success, next stept should be sudo ./TorBOX_CreateVM -tg-pre"
exit 0
fi
################################################################
# -delete #
################################################################
if [[ "$1" = "-delete" ]]; then
root_check
unmount_iso
rm -r /home/$USERNAME/TorBOX_binary/modified_iso
rm /home/$USERNAME/TorBOX_binary/preseed.iso
echo "Done."
exit 0
fi
################################################################
# -help #
################################################################
if [[ "$1" = "-help" ]]; then
script_help
exit 0
fi
################################################################
# no option chosen #
################################################################
echo "No option choosen. Use -help for help."
touch /home/$USERNAME/TorBOX_binary/TORBOX_BUILD_FAILED
exit 1