-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy patharch-anywhere-creator.sh
More file actions
executable file
·225 lines (182 loc) · 6.72 KB
/
arch-anywhere-creator.sh
File metadata and controls
executable file
·225 lines (182 loc) · 6.72 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
#!/bin/bash
# Set the ISO name and version here eg: "this_iso-2.0.iso"
export version=""
# Set the ISO label here eg: "ISO_LABEL"
export iso_label=""
# Set creation directory to pwd - set customiso variable - search for archiso in creation directory
export aa=$(pwd)
export customiso="$aa/customiso"
export iso=$(ls "$aa"/archlinux-* | tail -n1 | sed 's!.*/!!')
update=false
# Check depends
if [ ! -f /usr/bin/gtk3-demo ] || [ ! -f /usr/bin/7z ] || [ ! -f /usr/bin/mksquashfs ] || [ ! -f /usr/bin/xorriso ] || [ ! -f /usr/bin/wget ] || [ ! -f /usr/bin/arch-chroot ] || [ ! -f /usr/bin/xxd ]; 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+="libisoburn "; fi
if [ ! -f /usr/bin/mksquashfs ]; then query+="squashfs-tools "; fi
if [ ! -f /usr/bin/7z ]; then query+="p7zip " ; fi
if [ ! -f /usr/bin/arch-chroot ]; then query+="arch-install-scripts "; fi
if [ ! -f /usr/bin/xxd ]; then query+="xxd "; fi
if [ ! -f /usr/bin/gtk3-demo ]; then query+="gtk3 "; 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
# Link to the archiso
echo "Checking for updated ISO..."
export archiso_link=$(lynx -dump $(lynx -dump http://arch.localmsp.org/arch/iso | grep "8\. " | awk '{print $2}') | grep "7\. " | awk '{print $2}')
if [ -z "$archiso_link" ]; then
echo -e "ERROR: archiso link not found\nRequired for updating archiso.\nPlease install 'lynx' to resolve this issue"
sleep 4
else
iso_ver=$(<<<"$archiso_link" sed 's!.*/!!')
fi
if [ "$iso_ver" != "$iso" ]; then
if [ -z "$iso" ]; then
echo -en "\nNo archiso found under $aa\nWould you like to download now? [y/N]: "
read input
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY) update=true
;;
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
else
echo -en "An updated verison of the archiso is available for download\n'$iso_ver'\nDownload now? [y/N]: "
read input
case "$input" in
y|Y|yes|Yes|yY|Yy|yy|YY) update=true
;;
n|N|no|No|nN|Nn|nn|NN) echo -e "Continuing using old iso\n'$iso'"
sleep 1
;;
esac
fi
if "$update" ; then
cd "$aa"
wget "$archiso_link"
if [ "$?" -gt "0" ]; then
echo "Error: requires wget, exiting"
exit 1
fi
export iso=$(ls "$aa"/archlinux-* | tail -n1 | sed 's!.*/!!')
fi
fi
init() {
if [ -d "$customiso" ]; then
sudo rm -rf "$customiso"
fi
# Extract archiso to mntdir and continue with build
7z x "$iso" -o"$customiso"
prepare_sys
}
prepare_sys() {
sys=x86_64
while (true)
do
### 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 $sys"
cd "$customiso"/arch/"$sys"
sudo unsquashfs airootfs.sfs
########################################## Start changes here
### To install packages onto customiso uncomment and use the following commands (#1 install #2 update package list #3 clean customiso cache)
# 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.${sys}.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/"$sys"/squashfs-root/var/cache/pacman/pkg/*
### Copy any files you would like over to custom iso like so:
# sudo cp "$aa"/etc/file_to_copy.txt "$customiso"/arch/"$sys"/squashfs-root/etc
### You may also chroot into the customiso system like so:
# sudo arch-chroot squashfs-root /bin/bash command_here
########################################### End changes here
### cd back into root system directory, remove old system
cd "$customiso"/arch/"$sys"
rm airootfs.sfs
### Recreate the ISO using compression remove unsquashed system generate checksums and continue to i686
echo "Recreating $sys..."
sudo mksquashfs squashfs-root airootfs.sfs -b 1024k -comp xz
sudo rm -r squashfs-root
md5sum airootfs.sfs > airootfs.md5
if [ "$sys" == "i686" ]; then break ; fi
sys=i686
done
configure_boot
}
configure_boot() {
archiso_label=$(<"$customiso"/loader/entries/archiso-x86_64.conf awk 'NR==5{print $NF}' | sed 's/.*=//')
archiso_hex=$(<<<"$archiso_label" xxd -p)
iso_hex=$(<<<"$iso_label" xxd -p)
cp "$aa"/boot/iso/archiso_head.cfg "$customiso"/arch/boot/syslinux
sed -i "s/$archiso_label/$iso_label/" "$customiso"/loader/entries/archiso-x86_64.conf
sed -i "s/$archiso_label/$iso_label/" "$customiso"/arch/boot/syslinux/archiso_sys64.cfg
sed -i "s/$archiso_label/$iso_label/" "$customiso"/arch/boot/syslinux/archiso_sys32.cfg
cd "$customiso"/EFI/archiso/
echo -e "Replacing label hex in efiboot.img...\n$archiso_label $archiso_hex > $iso_label $iso_hex"
xxd -p efiboot.img | sed "s/$archiso_hex/$iso_hex/" | xxd -r -p > efiboot1.img
mv efiboot1.img efiboot.img
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"
check_sums
;;
n|N|no|No|nN|Nn|nn|NN)
check_sums
;;
esac
else
echo "Error: ISO creation failed, please email the developer: deadhead3492@gmail.com"
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 checksums.txt"
echo
echo "$version ISO generated successfully! Exiting ISO creator."
echo
exit
}
init