-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtd-mc
executable file
·231 lines (197 loc) · 8.91 KB
/
rtd-mc
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
#!/bin/bash
#:: RTD System System Managment Script
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:: Author: SLS
Version=1.01
#::
#::
#:: Purpose: The purpose of the script is to facilitate generating an unattended installation iso file for installing
#:: Ubuntu Linux or any of the derivatives thereof.
#::
#:: This script will:
#:: - Download the latest installation image
#:: - Patch the instllation image with the instructions to complete an install
#:: - The instructios will encrypt the hrddrive and perform a standard installation. Other software will be added later.
#::
#::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#:::::::::::::: Script Settings ::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Variables that govern the behavior or the script and location of files are
# set here. There should be no reason to change any of this to setup and
# get a working Minecraft server on Ubuntu. However, if you have updated scripts
# and need to download yours from someplace else you only need to change these
# setings.
# Set default release version...
RELEASE=focal
TARGET_ISO_FILE_NAME=$RELEASE-netinstall-auto.iso
#SOURCE_ISO_URL="http://archive.ubuntu.com/ubuntu/dists/$RELEASE/main/installer-amd64/current/images/netboot/mini.iso"
SOURCE_ISO_URL="http://archive.ubuntu.com/ubuntu/dists/$RELEASE/main/installer-amd64/current/legacy-images/netboot/mini.iso"
PUT_ISO_FILE_HERE_WHEN_DONE="$HOME"
VOLUME_TITLE="RTD Ubuntu Auto Installer"
COMPLETION_MESSAGE="Your ISO image is ready! It is placed in the folder: $PUT_ISO_FILE_HERE_WHEN_DONE Next steps: \n Add the ISO to a bootable USB (for example MULTIBOOT from Pendrive Linux), or if you are using Virtual Machines select the ISO as install media and install system, login as the temporary user, adjust passwords for the encrypted volume (letmein1234) and login (letmein)... DO NOT leave them as they are!"
BACKTITLE="RTD Media Creator Version: $Version"
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#:::::::::::::: Script Functions ::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
function prepare_environment_for_iso_creation () {
TARGET_ISO="$PUT_ISO_FILE_HERE_WHEN_DONE/$TARGET_ISO_FILE_NAME"
_DEPENDENCIES="dos2unix cpio gzip genisoimage whois pwgen wget fakeroot xorriso"
for i in $_DEPENDENCIES
do
check_dependencies $i
done
: "${BIN_7Z:=$(type -P 7z)}"
: "${BIN_XORRISO:=$(type -P xorriso)}"
: "${BIN_CPIO:=$(type -P gnucpio || type -P cpio)}"
CURRENT_DIR="$(pwd)"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMP_DOWNLOAD_DIR="$(mktemp -d)"
TMP_DISC_DIR="$(mktemp -d)"
TMP_INITRD_DIR="$(mktemp -d)"
}
function check_dependencies (){
# Simple function to check if sofware is available and take action
# if it is not. Software name must match command to envoke it.
#---------------------------------------------------------------
echo "Checking for script dependencies and install if not there..."
#---------------------------------------------------------------
if hash "$1" 2>/dev/null; then
echo "I found that $1 is present on this system... thankyou for that! "
else
echo "You seem to have no $1... I will try to get it... "
sudo apt install -y "$1"
if [ $? != 0 ];
then
echo "That install didn't work out so well."
echo "Please manually try to add the software since I couldn't do it."
read -p "Press any key to EXIT" ; exit 1
fi
echo "OK Done! Continuing..."
fi
}
function download_and_manipulate_iso () {
# This is a simple command sequence to read the preference of distribution to install
# and what release to get... then download the network install file from ubuntu
# and manipulate the iso file to complete the edited instruction in the preseed.cfg...
RELEASE=$1
PREFERENCE=$2
TARGET_ISO="$PUT_ISO_FILE_HERE_WHEN_DONE/$PREFERENCE-$TARGET_ISO_FILE_NAME"
cd "$TMP_DOWNLOAD_DIR" || ( echo Failed to change to download dir: "$TMP_DOWNLOAD_DIR" ; exit 1 )
wget -4 "$SOURCE_ISO_URL" -O "./netboot.iso"
"$BIN_7Z" x "./netboot.iso" "-o$TMP_DISC_DIR"
cd "$TMP_DISC_DIR" || ( echo Failed to change to tem disk dir: "$TMP_DISC_DIR" ; exit 1 )
sed -i s/"menu label ^Install"/"menu label ^Automatic Install"/g "$TMP_DISC_DIR/txt.cfg"
sed -i s/"timeout 0"/"timeout 200"/g "$TMP_DISC_DIR/isolinux.cfg"
sed -i s/"Press ENTER to boot or TAB to edit a menu entry"/"! - This system will be wiped and Ubuntu installed - !"/g "$TMP_DISC_DIR/stdmenu.cfg"
mkdir -p "$TMP_INITRD_DIR/custom"
cat "$SCRIPT_DIR/custom/preseed.ubuntu.template" > "$TMP_INITRD_DIR/preseed.cfg"
sed -i s/oem-replace-me-desktop-selection/$PREFERENCE/g "$TMP_INITRD_DIR/preseed.cfg"
cd "$TMP_INITRD_DIR" || ( echo Failed to change to initrd dir: "$TMP_INITRD_DIR" ; exit 1 )
cat "$TMP_DISC_DIR/initrd.gz" | gzip -d > "./initrd"
echo "./preseed.cfg" | fakeroot "$BIN_CPIO" -o -H newc -A -F "./initrd"
find "./custom" | fakeroot "$BIN_CPIO" -o -H newc -A -F "./initrd"
cat "./initrd" | gzip -9c > "$TMP_DISC_DIR/initrd.gz"
}
function create_iso_image (){
# Delete the old ISO created if it is there, and then generate the new ISO...
if [ -f "$TARGET_ISO" ]; then
rm -f "$TARGET_ISO"
fi
echo going to exe:
cd "$TMP_DISC_DIR" || ( echo Failed to change to temp disk dir: "$TMP_DISC_DIR"; exit 1 )
rm -r '[BOOT]'
"$BIN_XORRISO" -as mkisofs -r -V "$VOLUME_TITLE" -J -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -input-charset utf-8 -isohybrid-mbr "$SCRIPT_DIR/custom/isohdpfx.bin" -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -o "$TARGET_ISO" ./
chmod 777 "$TARGET_ISO"
}
function cleanup_and_finish () {
# go back to initial directory, remove temp folders and notify user of completion...
cd "$CURRENT_DIR" || echo Failed to change to current dir: "$TMP_DISC_DIR"
rm -r "$TMP_DOWNLOAD_DIR"
rm -r "$TMP_DISC_DIR"
rm -r "$TMP_INITRD_DIR"
dialog --backtitle "$BACKTITLE" --title "DONE" --msgbox "$COMPLETION_MESSAGE" 0 0
clear
}
function _show_gui () {
# prompt for the desired Ubuntu configuration (KDE, Gnome or Default)
check_dependencies dialog
BRANDING="RTD: Ubuntu Blind Installatioin ISO"
DIALOG_CANCEL=1
DIALOG_ESC=255
while true; do
exec 3>&1
selection=$(dialog \
--backtitle "$BACKTITLE" \
--title "$BRANDING" \
--menu "Select task:" 0 0 10 \
"1" "Genterate an Automatic Standard Ubuntu Installer ISO (Burn to CD, USB, or use with VM)" \
"2" "Genterate an Automatic KDE Ubuntu Installer ISO (Burn to CD, USB, or use with VM)" \
"3" "Genterate an Automatic Gnome Ubuntu Installer ISO (Burn to CD, USB, or use with VM)" \
2>&1 1>&3)
exit_status=$?
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
clear
rm -f ~/.dialogrc
echo "Program terminated."
exit
;;
$DIALOG_ESC)
clear
rm -f ~/.dialogrc
echo "Program aborted." >&2
exit 1
;;
esac
case $selection in
0 )
clear
echo "Program terminated by user..."
;;
1 )
clear
prepare_environment_for_iso_creation
download_and_manipulate_iso $RELEASE ubuntu-desktop
create_iso_image
cleanup_and_finish
clear
;;
2 )
clear
prepare_environment_for_iso_creation
download_and_manipulate_iso $RELEASE kubuntu-desktop
create_iso_image
cleanup_and_finish
clear
;;
3 )
clear
prepare_environment_for_iso_creation
download_and_manipulate_iso $RELEASE ubuntu-gnome-desktop
create_iso_image
cleanup_and_finish
clear
;;
esac
done
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#:::::::::::::: Script Executive ::::::::::::::::::::::
#:::::::::::::: ::::::::::::::::::::::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Execute the steps to create a new automatic ubuntu based installation ISO.
# To skip a step, simply momment out the funcion call you want to exclude below:
_show_gui
# Clear the screen on exit...
clear