forked from AnarchyLinux/installer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
arch-anywhere-creator.sh
executable file
·316 lines (273 loc) · 12.9 KB
/
arch-anywhere-creator.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
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
#!/bin/bash
# Set the version here
export version="arch-anywhere-2.2.3-dual.iso"
# Set the ISO label here
export iso_label="aaiso2"
# Location variables all directories must exist
export aa="`dirname $(readlink -f "$0")`"
export customiso="$aa/customiso"
export mntdir="$aa/mnt"
# Link to the iso used to create Arch Anywhere
export archiso_link="http://arch.localmsp.org/arch/iso/2016.09.03/archlinux-2016.09.03-dual.iso"
init() {
if [ -d "$customiso" ]; then
sudo rm -rf "$customiso"
fi
if [ ! -d "$mntdir" ]; then
mkdir "$mntdir"
fi
if [ -d "$mntdir"/arch ]; then
cp -a "$mntdir" "$customiso"
else
mounted=false
echo -n "ISO not mounted would you like to mount it now? [y/n]: "
read input
until "$mounted"
do
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY)
if [ -f "$aa"/archlinux-*.iso ]; then
sudo mount -t iso9660 -o loop "$aa"/archlinux-*.iso "$mntdir"
if [ "$?" -eq "0" ]; then
mounted=true
else
echo "Error: failed mounting the archiso, exiting."
exit 1
fi
cp -a "$mntdir" "$customiso"
else
echo
echo -n "No archiso found under $aa would you like to download now? [y/N]"
read input
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY)
cd "$aa"
wget "$archiso_link"
if [ "$?" -gt "0" ]; then
echo "Error: requires wget, exiting"
exit 1
fi
;;
n|N|no|No|nN|Nn|nn|NN)
echo "Error: Creating the ISO requires the official archiso to be located at $aa, exiting."
exit 1
;;
esac
fi
;;
n|N|no|No|nN|Nn|nn|NN)
echo "Error: archiso must be mounted at $mntdir, exiting."
exit1
;;
esac
done
fi
# Check depends
if [ ! -f /usr/bin/mksquashfs ] || [ ! -f /usr/bin/xorriso ] || [ ! -f /usr/bin/wget ] || [ ! -f /usr/bin/arch-chroot ]; then
depends=false
until "$depends"
do
echo
echo -n "ISO creation requires arch-install-scripts, mksquashfs-tools, libisoburn, and wget, would you like to install missing dependencies now? [y/N]: "
read input
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY)
if [ ! -f "/usr/bin/wget" ]; then query="wget"; fi
if [ ! -f /usr/bin/xorriso ]; then query="$query libisoburn"; fi
if [ ! -f /usr/bin/mksquashfs ]; then query="$query squashfs-tools"; fi
if [ ! -f /usr/bin/arch-chroot ]; then query="$query arch-install-scripts"; fi
sudo pacman -Syy $(echo "$query")
depends=true
;;
n|N|no|No|nN|Nn|nn|NN)
echo "Error: missing depends, exiting."
exit 1
;;
*)
echo
echo "$input is an invalid option"
;;
esac
done
fi
builds
}
builds() {
if [ ! -d /tmp/fetchmirrors ]; then
### Build fetchmirrors
cd /tmp
wget "https://aur.archlinux.org/cgit/aur.git/snapshot/fetchmirrors.tar.gz"
tar -xf fetchmirrors.tar.gz
cd fetchmirrors
makepkg -s
fi
if [ ! -d /tmp/arch-wiki-cli ]; then
### Build arch-wiki
cd /tmp
wget "https://aur.archlinux.org/cgit/aur.git/snapshot/arch-wiki-cli.tar.gz"
tar -xf arch-wiki-cli.tar.gz
cd arch-wiki-cli
makepkg -s
fi
prepare_x86_64
}
prepare_x86_64() {
### Change directory into the ISO where the filesystem is stored.
### Unsquash root filesystem 'airootfs.sfs' this creates a directory 'squashfs-root' containing the entire system
echo "Preparing x86_64..."
cd "$customiso"/arch/x86_64
sudo unsquashfs airootfs.sfs
### Install fonts onto system and cleanup
sudo pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf --noconfirm -Syyy terminus-font
sudo pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf -Sl | awk '/\[installed\]$/ {print $1 "/" $2 "-" $3}' > "$customiso"/arch/pkglist.x86_64.txt
sudo pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf --noconfirm -Scc
sudo rm -f "$customiso"/arch/x86_64/squashfs-root/var/cache/pacman/pkg/*
### Copy over vconsole.conf (sets font at boot) & locale.gen (enables locale(s) for font)
sudo cp "$aa"/etc/{vconsole.conf,locale.gen} "$customiso"/arch/x86_64/squashfs-root/etc
sudo arch-chroot squashfs-root /bin/bash locale-gen
### Copy over main arch anywhere config, installer script, and arch-wiki, make executeable
sudo cp "$aa"/etc/arch-anywhere.conf "$customiso"/arch/x86_64/squashfs-root/etc/
# sudo cp "$aa"/etc/arch-anywhere.service "$customiso"/arch/x86_64/squashfs-root/usr/lib/systemd/system/
# sudo cp "$aa"/arch-anywhere-init.sh "$customiso"/arch/x86_64/squashfs-root/usr/bin/arch-anywhere-init
sudo cp "$aa"/arch-installer.sh "$customiso"/arch/x86_64/squashfs-root/usr/bin/arch-anywhere
sudo cp "$aa"/extra/{arch-wiki,fetchmirrors,sysinfo,iptest} "$customiso"/arch/x86_64/squashfs-root/usr/bin/
sudo chmod +x "$customiso"/arch/x86_64/squashfs-root/usr/bin/{arch-anywhere,arch-wiki,fetchmirrors,sysinfo,iptest}
# sudo arch-chroot "$customiso"/arch/x86_64/squashfs-root /bin/bash -c "systemctl enable arch-anywhere.service"
### Create arch-anywhere directory and lang directory copy over all lang files
sudo mkdir -p "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/{lang,pkg}
sudo cp "$aa"/lang/* "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/lang
sudo cp /tmp/fetchmirrors/*.pkg.tar.xz "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/pkg
sudo cp /tmp/arch-wiki-cli/*.pkg.tar.xz "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/pkg
### Copy over extra files (dot files, desktop configurations, help file, issue file, hostname file)
sudo cp "$aa"/extra/{.zshrc,.help,.dialogrc} "$customiso"/arch/x86_64/squashfs-root/root/
sudo cp "$aa"/extra/{.bashrc,.bashrc-root,.tcshrc,.tcshrc.conf,.mkshrc} "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere
sudo cp "$aa"/extra/.zshrc-sys "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/.zshrc
# sudo mkdir "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/pkg
# sudo mv /tmp/*.pkg.tar.xz "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/pkg
sudo cp -r "$aa"/extra/desktop "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/
sudo cp "$aa"/boot/{issue,hostname} "$customiso"/arch/x86_64/squashfs-root/etc/
sudo cp -r "$aa"/boot/loader/syslinux "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/
sudo cp "$aa"/boot/splash.png "$customiso"/arch/x86_64/squashfs-root/usr/share/arch-anywhere/syslinux
### cd back into root system directory, remove old system
cd "$customiso"/arch/x86_64
rm airootfs.sfs
### Recreate the ISO using compression remove unsquashed system generate checksums and continue to i686
echo "Recreating x86_64..."
sudo mksquashfs squashfs-root airootfs.sfs -b 1024k -comp xz
sudo rm -r squashfs-root
md5sum airootfs.sfs > airootfs.md5
prepare_i686
}
prepare_i686() {
echo "Preparing i686..."
cd "$customiso"/arch/i686
sudo unsquashfs airootfs.sfs
sudo sed -i 's/\$arch/i686/g' squashfs-root/etc/pacman.d/mirrorlist
sudo sed -i 's/auto/i686/' squashfs-root/etc/pacman.conf
sudo setarch i686 pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf --noconfirm -Syyy terminus-font
sudo setarch i686 pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf -Sl | awk '/\[installed\]$/ {print $1 "/" $2 "-" $3}' > "$customiso"/arch/pkglist.i686.txt
sudo setarch i686 pacman --root squashfs-root --cachedir squashfs-root/var/cache/pacman/pkg --config squashfs-root/etc/pacman.conf --noconfirm -Scc
sudo rm -f "$customiso"/arch/i686/squashfs-root//var/cache/pacman/pkg/*
# sudo cp "$aa"/etc/arch-anywhere.service "$customiso"/arch/i686/squashfs-root/etc/systemd/system/
# sudo cp "$aa"/arch-anywhere-init.sh "$customiso"/arch/i686/squashfs-root/usr/bin/arch-anywhere-init
sudo cp "$aa"/etc/arch-anywhere.conf "$customiso"/arch/i686/squashfs-root/etc/
sudo cp "$aa"/etc/locale.gen "$customiso"/arch/i686/squashfs-root/etc
sudo arch-chroot squashfs-root /bin/bash locale-gen
sudo cp "$aa"/etc/vconsole.conf "$customiso"/arch/i686/squashfs-root/etc
sudo cp "$aa"/arch-installer.sh "$customiso"/arch/i686/squashfs-root/usr/bin/arch-anywhere
sudo mkdir "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere
sudo mkdir "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/{lang,pkg}
sudo cp "$aa"/lang/* "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/lang
sudo cp /tmp/fetchmirrors/*.pkg.tar.xz "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/pkg
sudo cp /tmp/arch-wiki-cli/*.pkg.tar.xz "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/pkg
sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/arch-anywhere
sudo cp "$aa"/extra/arch-wiki "$customiso"/arch/i686/squashfs-root/usr/bin/arch-wiki
sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/arch-wiki
sudo cp "$aa"/extra/fetchmirrors "$customiso"/arch/i686/squashfs-root/usr/bin/fetchmirrors
sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/fetchmirrors
sudo cp "$aa"/extra/sysinfo "$customiso"/arch/i686/squashfs-root/usr/bin/sysinfo
sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/sysinfo
sudo cp "$aa"/extra/iptest "$customiso"/arch/i686/squashfs-root/usr/bin/iptest
sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/iptest
# sudo chmod +x "$customiso"/arch/i686/squashfs-root/usr/bin/arch-anywhere-init
# sudo arch-chroot "$customiso"/arch/i686/squashfs-root /bin/bash -c "systemctl enable arch-anywhere.service"
sudo cp "$aa"/extra/{.zshrc,.help,.dialogrc} "$customiso"/arch/i686/squashfs-root/root/
sudo cp "$aa"/extra/{.bashrc,.bashrc-root,.tcshrc,.tcshrc.conf,.mkshrc} "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere
sudo cp "$aa"/extra/.zshrc-sys "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/.zshrc
sudo cp -r "$aa"/extra/desktop "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/
sudo cp "$aa"/boot/issue "$customiso"/arch/i686/squashfs-root/etc/
sudo cp "$aa"/boot/hostname "$customiso"/arch/i686/squashfs-root/etc/
sudo cp -r "$aa"/boot/loader/syslinux "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/
sudo cp "$aa"/boot/splash.png "$customiso"/arch/i686/squashfs-root/usr/share/arch-anywhere/syslinux
cd "$customiso"/arch/i686
rm airootfs.sfs
echo "Recreating i686..."
sudo mksquashfs squashfs-root airootfs.sfs -b 1024k -comp xz
sudo rm -r squashfs-root
md5sum airootfs.sfs > airootfs.md5
configure_boot
}
configure_boot() {
sudo mkdir "$customiso"/EFI/archiso/mnt
sudo mount -o loop "$customiso"/EFI/archiso/efiboot.img "$customiso"/EFI/archiso/mnt
sed -i "s/archisolabel=.*/archisolabel=$iso_label/" "$aa"/boot/iso/archiso-x86_64.CD.conf
sed -i "s/archisolabel=.*/archisolabel=$iso_label/" "$aa"/boot/iso/archiso-x86_64.conf
sed -i "s/archisolabel=.*/archisolabel=$iso_label/" "$aa"/boot/iso/archiso_sys64.cfg
sed -i "s/archisolabel=.*/archisolabel=$iso_label/" "$aa"/boot/iso/archiso_sys32.cfg
sudo cp "$aa"/boot/iso/archiso-x86_64.CD.conf "$customiso"/EFI/archiso/mnt/loader/entries/archiso-x86_64.conf
sudo umount "$customiso"/EFI/archiso/mnt
sudo rmdir "$customiso"/EFI/archiso/mnt
cp "$aa"/boot/iso/archiso-x86_64.conf "$customiso"/loader/entries/
cp "$aa"/boot/splash.png "$customiso"/arch/boot/syslinux
cp "$aa"/boot/iso/archiso_head.cfg "$customiso"/arch/boot/syslinux
cp "$aa"/boot/iso/archiso_sys64.cfg "$customiso"/arch/boot/syslinux
cp "$aa"/boot/iso/archiso_sys32.cfg "$customiso"/arch/boot/syslinux
create_iso
}
create_iso() {
cd "$aa"
xorriso -as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "$iso_label" \
-eltorito-boot isolinux/isolinux.bin \
-eltorito-catalog isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-isohybrid-mbr customiso/isolinux/isohdpfx.bin \
-eltorito-alt-boot \
-e EFI/archiso/efiboot.img \
-no-emul-boot -isohybrid-gpt-basdat \
-output "$version" \
"$customiso"
if [ "$?" -eq "0" ]; then
echo -n "ISO creation successful, would you like to remove the $customiso directory and cleanup? [y/N]: "
read input
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY)
rm -rf "$customiso"
sudo umount "$mntdir"
check_sums
;;
n|N|no|No|nN|Nn|nn|NN)
check_sums
;;
esac
else
echo "Error: ISO creation failed, please email the developer: [email protected]"
exit 1
fi
}
check_sums() {
echo
echo "Generating ISO checksums..."
md5_sum=$(md5sum "$version" | awk '{print $1}')
sha1_sum=$(sha1sum "$version" | awk '{print $1}')
timestamp=$(timedatectl | grep "Universal" | awk '{print $4" "$5" "$6}')
echo "Checksums generated. Saved to arch-anywhere-checksums.txt"
echo -e "- Arch Anywhere is licensed under GPL v2\n- Developer: Dylan Schacht ([email protected])\n- Webpage: http://arch-anywhere.org\n- ISO timestamp: $timestamp\n- $version Official Check Sums:\n\n* md5sum: $md5_sum\n* sha1sum: $sha1_sum" > arch-anywhere-checksums.txt
echo
echo "$version ISO generated successfully! Exiting ISO creator."
echo
exit
}
init