forked from iPublicis/Distro-Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdist_Builder.sh
More file actions
executable file
·272 lines (236 loc) · 8.74 KB
/
dist_Builder.sh
File metadata and controls
executable file
·272 lines (236 loc) · 8.74 KB
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
#!/bin/bash
. CONFIG
rootNisoChk() {
if [ "$(id -u)" -eq 0 ]; then
softChk
else
echo "Sorry, you need to use sudo."
exit 1
fi
}
softChk() {
xyphr=$(which Xephyr) ## Chroot view window || alt desktop window
sysLnx=$(which syslinux) ## Casper stuff
squash=$(which unsquashfs) ## Squashfs-tools
genIso=$(which genisoimage) ## Iso maker
clear
if [[ $xyphr == "" ]] || [[ $sysLnx == "" ]] || \
[[ $squash == "" ]] || [[ $genIso == "" ]]; then
echo -e "## Missing some packages ##\n" \
"Xephyr :" "${xyphr}\n" \
"Syslinux :" "${sysLnx}\n" \
"Squashfs-tools :" "${squash}\n" \
"Genisoimage :" "${genIso}\n" \
"Going to run :\n" \
" apt-get install xserver-xephyr syslinux squashfs-tools genisoimage -y"
sleep 4
apt-get install xserver-xephyr syslinux squashfs-tools genisoimage -y
getIso
else
getIso
fi
}
getIso() {
clear
echo -e "## Download Ubuntu Mini Remix ##\n" \
"Would you like to download an Ubuntu Mini Iso?"
read -p "(yY/Nn) --> " ANSR
while [[ $ANSR != "y" ]] && [[ $ANSR != "Y" ]] && \
[[ $ANSR != "n" ]] && [[ $ANSR != "N" ]]
do
read -p "(yY/Nn) --> " ANSR
done
## Check if dl iso is wanted then dl it
if [[ $ANSR == "Y" ]] || [[ $ANSR == "y" ]]; then
clear
echo -e "## Default Settings Or Set Version And Arch #\n" \
"Would you like to use the default choices? "
read -p "(yY/Nn) --> " ANSR
while [[ $ANSR != "y" ]] && [[ $ANSR != "Y" ]] && \
[[ $ANSR != "n" ]] && [[ $ANSR != "N" ]]
do
read -p "(yY/Nn) --> " ANSR
done
if [ "${ANSR}" == "N" ] || [ "${ANSR}" == "n" ]; then
clear
echo -e "## Get Version ##\n" \
"What version would you like?\n" \
"Examples :\n" \
" LTS : 16.04\n" \
" Non-LTS : 15.10\n" \
"Be very sure you are correctly entering the version."
read -p "Version --> : " VERSION
clear
echo -e "## Get Architect ##\n" \
"What version would you like?\n" \
" 32bit : i386\n" \
" 64bit : amd64\n" \
"Be very sure you are correctly entering the architect."
read -p "Arch --> : " ARCH
wget http://ubuntu-mini-remix.mirror.garr.it/mirrors/ubuntu-mini-remix/"${VERSION}"/ubuntu-mini-remix-"${VERSION}"-"${ARCH}".iso
else
wget http://ubuntu-mini-remix.mirror.garr.it/mirrors/ubuntu-mini-remix/"${VERSION}"/ubuntu-mini-remix-"${VERSION}"-"${ARCH}".iso
main
fi
else
mkdir squashfs-root/
sudo debootstrap --components=main,contrib,nonfree \
--variant=minbase \
--include=linux-generic,grub-pc \
--arch=amd64 bionic \
./squashfs-root/
main
fi
}
main() {
list=$(find . -maxdepth 1 -name "*.iso" -printf '%P\n')
if [[ "${list}" == "" ]] && [ ! -d squashfs-root ]; then
clear
echo -e "Sorry, there is no iso or squashfs-root dir to work with in the current directory.\n"
"Going back to download an Ubuntu Mini Iso..."
sleep 4
getIso
elif [[ "${list}" != "" ]] && [ -d squashfs-root ]; then
ANSR=""
while [[ $ANSR != "1" ]] && [[ $ANSR != "2" ]] && [[ $ANSR != "3" ]]; do
clear
echo -e "Both an iso(s) and squashfs-root are present...\n" \
"Which do you wish to use?\n" \
"1.) Use ISO(s)\n" \
"2.) Use former session: squashfs-root\n" \
"3.) Exit"
read -p "--> : " ANSR
done
if [[ $ANSR == "1" ]]; then
bash cleanup.sh
mountAndCopy
elif [[ $ANSR == "2" ]]; then
chrootr
elif [[ $ANSR == "3" ]]; then
exit
fi
elif [ -d squashfs-root ]; then
clear
echo "Squashfs-root directory found. Chrooting to directory."
sleep 4
chrootr
elif [[ "${list}" != "" ]]; then
clear
echo -e "Iso(s) found. Will mount one and copying to proper file structure.\n" \
"Then will chroot in..."
sleep 4
mountAndCopy
chrootr
fi
}
mountAndCopy() {
## Prep dirs
mkdir iso/ mnt/
## Prep filesystem
isoList=($(find . -maxdepth 1 -name "*.iso" -printf '%P\n'))
count="${#isoList[@]}"
ANSR=""
while [[ "${ANSR}" > "${count}" || "${ANSR}" < "0" ]]; do
x=0;
clear
for i in "${isoList[@]}"; do
echo "$x - ${i}"
((x++))
done
echo "Chose the ISO from above using the number."
read -p "-->: " ANSR
done
echo "You chose : ${isoList[$ANSR]}"
mount -o loop ./"${isoList[$ANSR]}" mnt/
cp -r mnt/. iso/ && \
mv iso/casper/filesystem.squashfs .
## Unspuashfs the squashfs
unsquashfs filesystem.squashfs && rm filesystem.squashfs
## Cleanup some prep items
umount mnt/ && rmdir mnt/
## Copy over build files 'n scripts
cp AUTO_INSTALL.sh squashfs-root/
cp -r COPY_OVER_TO_CHROOT/ squashfs-root/
}
chrootr() {
## Set Xephyr and set chrooting mounts
Xephyr -resizeable -screen "${RES}" "${ID}" &
cd squashfs-root/
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
cp /etc/resolv.conf etc/
## Enter env with chroot
chroot . bash
## Unmount binds
umount -lf dev/
umount -lf proc/
umount -lf sys/
cd ..
ANSR=""
while [[ $ANSR != "1" ]] && [[ $ANSR != "2" ]] && [[ $ANSR != "3" ]]; do
clear
echo -e "Are you using an extracted Ubuntu's iso/ or Boot_Structure/ folder?\n" \
"Which do you wish to use?\n" \
"1.) Use Ubuntu's\n" \
"2.) Use Boot_Structure/\n" \
"3.) Exit"
read -p "--> : " ANSR
done
if [[ $ANSR == "1" ]]; then
setConfigs
elif [[ $ANSR == "2" ]]; then
genSqush
elif [[ $ANSR == "3" ]]; then
exit
fi
}
setConfigs() {
## Edit Iso boot info bits
sed -i 3s/Ubuntu/"${NAME}"/g iso/isolinux/txt.cfg
sed -i 7s/Ubuntu/"${NAME}"/g iso/isolinux/txt.cfg
## Set Live user and Hostename
sed -i 14s/Ubuntu/"${lvUSER}"/g squashfs-root/etc/casper.conf
sed -i 5,7s/ubuntu/"${lvUSER}"/g squashfs-root/etc/casper.conf
## Recreate manifest and clean it Note: MUST be after all setting changes
chroot squashfs-root/ dpkg-query -W --showformat="${Package} ${VERSION}\n" | sudo tee iso/casper/filesystem.manifest
cp -v iso/casper/filesystem.manifest iso/casper/filesystem.manifest-desktop
for i in $REMOVE; do
sed -i "/${i}/d" iso/casper/filesystem.manifest-desktop
done
genSqushUbuntu
}
genSqush() {
## Recreate squashfs
mksquashfs squashfs-root/ Boot_Structure/images/filesystem.squashfs -b 1048576 -comp xz -Xdict-size 100% -e squashfs-root/boot
## Write the filesystem.size file, which is needed by the installer:
sudo du -sx --block-size=1 squashfs-root/ | cut -f1 > Boot_Structure/casper/filesystem.size
chmod 444 Boot_Structure/casper/filesystem.size
## Calculate MD5
(cd Boot_Structure/ && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > SHA256SUMS)
genIsoImg
}
genIsoImg() {
## Generate Iso
cd Boot_Structure/
./makeIso.sh
}
genSqushUbuntu() {
## Recreate squashfs
mksquashfs squashfs-root/ iso/casper/filesystem.squashfs -b 1048576 -comp xz -Xdict-size 100% -e squashfs-root/boot
## Write the filesystem.size file, which is needed by the installer:
chmod 644 iso/casper/filesystem.size
sudo du -sx --block-size=1 squashfs-root/ | cut -f1 > iso/casper/filesystem.size
chmod 444 iso/casper/filesystem.size
## Calculate MD5
(cd iso && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > SHA256SUMS)
genIsoImgUbuntu
}
genIsoImgUbuntu() {
## Generate Iso
cd iso/
sudo mkisofs -D -r -cache-inodes -J -l -b isolinux/isolinux.bin -c \
isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o \
../"${NAME}".iso .
}
rootNisoChk