This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
compile.sh
executable file
·691 lines (612 loc) · 24.5 KB
/
compile.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
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#!/usr/bin/env bash
# Copyright (C) 2018 Dylan Schacht
# Error codes:
# * Exit 1: Missing dependencies (check_dependencies)
# * Exit 2: Missing Arch iso (update_arch_iso)
# * Exit 3: Checksum did not match for Arch ISO (check_arch_iso)
# * Exit 4: Failed to create iso (create_iso)
# * Exit 5: Docker is not installed (compile_in_docker)
# * Exit 6: Failed to build/remove docker image (build_docker_image)
# Exit on error
set -o errexit
set -o errtrace
# Enable tracing of what gets executed
#set -o xtrace
# Declare important variables
working_dir="$(pwd)"
log_dir="${working_dir}"/logs
out_dir="${working_dir}"/out # Directory for generated ISOs
docker_repo="anarchy:latest" # Local image
# Define colors depending on script arguments
colors() {
if [ "${show_color}" = true ]; then
color_blank='\e[0m'
color_green='\e[1;32m'
color_red='\e[1;31m'
color_white="\e[1m"
else
# Replace all colors with reset codes
color_blank='\e[0m'
color_green='\e[0m'
color_red='\e[0m'
color_white="\e[0m"
fi
}
set_up_logging() {
if [ ! -d "${log_dir}" ]; then
mkdir "${log_dir}"
fi
log_file="${log_dir}"/iso-generator-"$(date +%d%m%y)".log
# Remove existing logs and create a new one
if [ -e "${log_dir}"/"${log_file}" ]; then
rm "${log_dir}"/"${log_file}"
fi
touch "${log_file}"
}
log() {
local entry
read entry
echo -e "$(date -u "+%d/%m/%Y %H:%M") : ${entry}" | tee -a "${log_file}"
}
# Clears the screen and adds a banner
prettify() {
# Source colors
colors
clear
echo -e "${color_white}-- Anarchy Linux --${color_blank}"
echo -e ""
}
set_version() {
# Label must be up to 11 chars long (incremental numbers)
anarchy_iso_label="ANARCHY110"
anarchy_iso_release="1.1.0"
anarchy_iso_name="anarchy-${anarchy_iso_release}-x86_64.iso"
}
init() {
# Location variables
custom_iso="${working_dir}"/customiso
squashfs="${custom_iso}"/arch/x86_64/squashfs-root
# Check for existing Arch iso
if (ls "${working_dir}"/archlinux-*-x86_64.iso &>/dev/null); then
local_arch_iso="$(ls "${working_dir}"/archlinux-*-x86_64.iso | tail -n1 | sed 's!.*/!!')" # Outputs Arch iso filename prev: iso
fi
if [ ! -d "${out_dir}" ]; then
mkdir "${out_dir}"
fi
# Remove existing Anarchy iso with same name
if [ -e "${out_dir}"/"${anarchy_iso_name}" ]; then
rm "${out_dir}"/"${anarchy_iso_name}"
fi
# Link to AUR snapshots
aur_snapshot_link="https://aur.archlinux.org/cgit/aur.git/snapshot/"
# Packages to add to local repo
local_aur_packages=(
'numix-icon-theme-git'
'numix-circle-icon-theme-git'
'oh-my-zsh-git'
'opensnap'
'perl-linux-desktopfiles'
'obmenu-generator'
'yay-bin'
'openbox-themes'
'arch-wiki-cli'
'pygtk'
'python2-distutils-extra'
'oblogout'
)
update_arch_iso
check_arch_iso
compile_in_docker
check_dependencies
local_repo_builds
}
check_dependencies() {
echo -e "Checking dependencies ..." | log
# Dependencies with same name packages
dependencies=(
'wget'
'libisoburn'
'squashfs-tools'
'p7zip'
'arch-install-scripts'
'xxd'
'gtk3'
'pacman-contrib'
'pkgconf'
'patch'
'gcc'
'make'
'binutils'
'file'
)
for dep in "${dependencies[@]}"; do
if ! pacman -Qi ${dep} > /dev/null; then
missing_deps+=("${dep}")
fi
done
if [ "${#missing_deps[@]}" -ne 0 ]; then
echo -e "Missing dependencies: ${missing_deps[*]}" | log
if [ "${user_input}" = true ]; then
echo -e "Install them now? [y/N]: "
local input
read -r input
case "${input}" in
y|Y|yes|YES|Yes)
echo -e "Chose to install dependencies" | log
for pkg in "${missing_deps[@]}"; do
echo -e "Installing ${pkg} ..." | log
if [ "${show_color}" = true ]; then
sudo pacman --noconfirm -Sy "${pkg}"
else
sudo pacman --noconfirm --color never -Sy "${pkg}"
fi
echo -e "${pkg} installed" | log
done
;;
*)
echo -e "Chose not to install dependencies" | log
echo -e "${color_red}Error: Missing dependencies, exiting.${color_blank}" | log
exit 1
;;
esac
else
for pkg in "${missing_deps[@]}"; do
echo -e "Installing ${pkg} ..." | log
if [ "${show_color}" = true ]; then
sudo pacman --noconfirm -Sy "${pkg}"
else
sudo pacman --noconfirm --color never -Sy "${pkg}"
fi
echo -e "${pkg} installed" | log
done
fi
fi
echo -e "Done installing dependencies"
echo -e ""
}
update_arch_iso() {
update=false
# Check for latest Arch Linux iso
arch_iso_latest="$(curl -s https://www.archlinux.org/download/ | grep "Current Release" | awk '{print $3}' | sed -e 's/<.*//')"
arch_iso_link="https://mirrors.kernel.org/archlinux/iso/${arch_iso_latest}/archlinux-${arch_iso_latest}-x86_64.iso"
arch_checksum_link="https://mirrors.edge.kernel.org/archlinux/iso/${arch_iso_latest}/sha1sums.txt"
echo -e "Checking for updated Arch Linux image ..." | log
iso_date="$(<<<"${arch_iso_link}" sed 's!.*/!!')"
if [ "${iso_date}" != "${local_arch_iso}" ]; then
if [ -z "${local_arch_iso}" ]; then
echo -e "No Arch Linux image found under ${working_dir}" | log
if [ "${user_input}" = "true" ]; then
echo -e "Download it? [y/N]: "
local input
read -r input
case "${input}" in
y|Y|yes|YES|Yes)
echo -e "Chose to download image" | log
update=true
;;
*)
echo -e "Chose not to download image" | log
echo -e "${color_red}Error: iso-generator requires an Arch Linux image located in: ${working_dir}, exiting.${color_blank}" | log
exit 2
;;
esac
else
update=true
fi
else
echo -e "Updated Arch Linux image available: ${arch_iso_latest}" | log
if [ "${user_input}" = true ]; then
echo -e "Download it? [y/N]: "
local input
read -r input
case "${input}" in
y|Y|yes|YES|Yes)
echo -e "Chose to update image" | log
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
update=true
;;
*)
echo -e "Chose not to update image" | log
echo -e "Using old image: ${local_arch_iso}" | log
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
sleep 1
;;
esac
else
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
update=true
fi
fi
if "${update}" ; then
cd "${working_dir}" || exit
echo -e ""
echo -e "Downloading Arch Linux image and checksum ..." | log
echo -e "(Don't resize the window or it will mess up the progress bar)"
wget -c -q --show-progress "${arch_checksum_link}"
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
wget -c -q --show-progress "${arch_iso_link}"
local_arch_iso="$(ls "${working_dir}"/archlinux-*-x86_64.iso | tail -n1 | sed 's!.*/!!')"
fi
fi
echo -e "Done checking for Arch Linux image"
echo -e ""
}
check_arch_iso() {
echo -e "Comparing Arch Linux checksums ..." | log
checksum=false
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
# Check if checksum exists
if [ -e "${local_arch_checksum}" ]; then
if [ "$(sha1sum --check --ignore-missing "${local_arch_checksum}")" ]; then
echo -e "${local_arch_iso}: OK" | log
checksum=true
fi
else
echo -e "No checksum found!" | log
if [ "${user_input}" = true ]; then
echo -e "Download it? [Y/n]: "
local input
read -r input
case "${input}" in
n|N|no|NO|No)
echo -e "Chose not to download checksum" | log
;;
*)
echo -e "Chose to download checksum" | log
wget -c -q --show-progress "${arch_checksum_link}"
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
if [ "$(sha1sum --check --ignore-missing "${local_arch_checksum}")" ]; then
echo -e "${local_arch_iso}: OK" | log
checksum=true
fi
;;
esac
else
# Automatically download and compare checksum
wget -c -q --show-progress "${arch_checksum_link}"
local_arch_checksum="$(ls "${working_dir}"/sha1sums.txt | tail -n1 | sed 's!.*/!!')"
if [ "$(sha1sum --check --ignore-missing "${local_arch_checksum}")" ]; then
echo -e "${local_arch_iso}: OK" | log
checksum=true
fi
fi
fi
if [ "${checksum}" = false ]; then
echo -e "Checksum did not match ISO file!" | log
if [ "${user_input}" = true ]; then
echo -e "Continue anyway? [y/N]: "
local input
read -r input
case "${input}" in
y|Y|yes|YES|Yes)
echo -e "Chose to continue" | log
;;
*)
echo -e "Chose not to continue" | log
echo -e "${color_red}Error: Checksum did not match file, exiting!${color_blank}" | log
exit 3
;;
esac
else
echo -e "${color_red}Error: Checksum did not match file, exiting!${color_blank}" | log
exit 3
fi
fi
}
# Build local docker image
build_docker_image() {
cd "${working_dir}"
echo -e "\nBuilding docker image..." | log
docker build -t "${docker_repo}" .
if [ "$?" -eq 0 ]; then
echo -e "${color_green}\""${docker_repo}"\" image created successfully.${color_blank}" | log
else
echo -e "${color_red}Error: Docker image creation failed, exiting.${color_blank}" | log
exit 6
fi
}
# Spin up a docker container for compilation
compile_in_docker() {
if [ "${docker_compile}" = true ]; then
# Make sure docker is installed
if [ $(command -v docker) ]; then
# anarchy_docker_images=$(docker images | grep anarchy | awk '{print $1":"$2}' )
if [ -z $(docker images -q "${docker_repo}") ]; then
echo -e "Local docker image \"${docker_repo}\" does not exist. Creating..." | log
build_docker_image
else
echo -e "Removing old docker image \"${docker_repo}\"." | log
docker rmi -f "${docker_repo}"
if [ "$?" -eq 0 ]; then
echo -e "${color_green}\""${docker_repo}"\" image removed successfully.${color_blank}" | log
build_docker_image
else
echo -e "${color_red}Error: Docker image removal failed, exiting.${color_blank}" | log
exit 6
fi
fi
echo -e "Compiling inside docker..." | log
docker run --rm --privileged \
--device-cgroup-rule='b 7:* rmw' \
-v "${PWD}":/project \
-e anarchy_iso_label="${anarchy_iso_label}" \
-e anarchy_iso_release="${anarchy_iso_release}" \
"${docker_repo}"
exit 0
else
echo -e "Docker is not installed\!" | log
exit 5
fi
fi
}
local_repo_builds() {
echo -e "Updating pacman databases ..." | log
sudo pacman -Sy --noconfirm
echo -e "Done updating pacman databases"
echo -e "Building AUR packages for local repo ..." | log
# Begin build loop checking /tmp for existing builds, then build packages & install if required
if [ ! "$(ls /tmp | grep "${local_aur_packages[8]}")" ]; then
for pkg in "${local_aur_packages[@]}"; do
echo -e "Making ${pkg} ..." | log
wget -qO- "${aur_snapshot_link}/${pkg}.tar.gz" | tar xz -C /tmp
cd /tmp/"${pkg}" || exit
if [ "${show_color}" = true ]; then
makepkg -sif --noconfirm --nocheck
else
makepkg -sif --noconfirm --nocheck --nocolor
fi
echo -e "${pkg} made successfully" | log
done
fi
echo -e "Done making packages"
echo -e ""
}
extract_arch_iso() {
cd "${working_dir}" || exit
if [ -d "${custom_iso}" ]; then
sudo rm -rf "${custom_iso}"
fi
echo -e "Extracting Arch Linux image ..." | log
# Extract Arch iso to mount directory and continue with build
7z x "${local_arch_iso}" -o"${custom_iso}"
echo -e "Done extracting image"
echo -e ""
}
copy_config_files() {
# 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 -e "Unsquashing Arch image ..." | log
cd "${custom_iso}"/arch/x86_64 || exit
sudo unsquashfs airootfs.sfs
echo -e "Done unsquashing airootfs.sfs"
echo -e ""
echo -e "Adding console and locale config files to iso ..." | log
# Copy over vconsole.conf (sets font at boot), locale.gen (enables locale(s) for font) & uvesafb.conf
sudo cp "${working_dir}"/etc/vconsole.conf "${working_dir}"/etc/locale.gen "${squashfs}"/etc/
sudo arch-chroot "${squashfs}" /bin/bash locale-gen
# Copy over main Anarchy config and installer script, make them executable
echo -e "Adding anarchy config and installer scripts to iso ..." | log
sudo cp "${working_dir}"/etc/anarchy.conf "${working_dir}"/etc/pacman.conf "${squashfs}"/etc/
sudo cp "${working_dir}"/anarchy-installer.sh "${squashfs}"/usr/bin/anarchy
sudo cp "${working_dir}"/extra/sysinfo "${working_dir}"/extra/iptest "${squashfs}"/usr/bin/
sudo chmod +x "${squashfs}"/usr/bin/anarchy "${squashfs}"/usr/bin/sysinfo "${squashfs}"/usr/bin/iptest
# Create Anarchy and lang directories, copy over all lang files
echo -e "Adding language files to iso ..." | log
sudo mkdir -p "${squashfs}"/usr/share/anarchy/lang "${squashfs}"/usr/share/anarchy/extra "${squashfs}"/usr/share/anarchy/boot "${squashfs}"/usr/share/anarchy/etc
sudo cp "${working_dir}"/lang/* "${squashfs}"/usr/share/anarchy/lang/
# Create shell function library, copy /lib to squashfs-root
echo -e "Adding anarchy scripts to iso ..." | log
sudo mkdir "${squashfs}"/usr/lib/anarchy
sudo cp "${working_dir}"/lib/* "${squashfs}"/usr/lib/anarchy/
# Copy over extra files (dot files, desktop configurations, issue file, hostname file)
echo -e "Adding dot files and desktop configurations to iso ..." | log
sudo rm "${squashfs}"/root/install.txt
sudo cp "${working_dir}"/extra/shellrc/.zshrc "${squashfs}"/root/
sudo cp "${working_dir}"/extra/.dialogrc "${squashfs}"/root/
sudo cp "${working_dir}"/extra/shellrc/.zshrc "${squashfs}"/etc/zsh/zshrc
cat "${working_dir}"/extra/.helprc | sudo tee -a "${squashfs}"/root/.zshrc >/dev/null
sudo cp -r "${working_dir}"/extra/shellrc/. "${squashfs}"/usr/share/anarchy/extra/
sudo cp -r "${working_dir}"/extra/desktop "${working_dir}"/extra/fonts "${working_dir}"/extra/anarchy-icon.png "${squashfs}"/usr/share/anarchy/extra/
sudo cp "${working_dir}"/etc/hostname "${working_dir}"/etc/issue_cli "${squashfs}"/etc/
sudo cp -r "${working_dir}"/boot/splash.png "${working_dir}"/boot/loader/ "${squashfs}"/usr/share/anarchy/boot/
sudo cp "${working_dir}"/etc/nvidia340.xx "${squashfs}"/usr/share/anarchy/etc/
sudo cp -r "${working_dir}"/extra/wallpapers "${squashfs}"/usr/share/anarchy/extra/
# Copy over built packages and create repository
echo -e "Adding built AUR packages to iso ..." | log
sudo mkdir "${custom_iso}"/arch/x86_64/squashfs-root/usr/share/anarchy/pkg
for pkg in $(echo "${local_aur_packages[@]}"); do
sudo cp /tmp/"${pkg}"/*.pkg.tar.xz "${squashfs}"/usr/share/anarchy/pkg/
done
cd "${squashfs}"/usr/share/anarchy/pkg || exit
sudo repo-add anarchy-local.db.tar.gz *.pkg.tar.xz
cd "${working_dir}" || exit
echo -e "Done adding files to iso"
echo -e ""
}
build_system() {
echo -e "Installing packages to new system ..." | log
# Install fonts, fbterm, fetchmirrors etc.
sudo pacman --root "${squashfs}" --cachedir "${squashfs}"/var/cache/pacman/pkg --noconfirm -Sy terminus-font acpi zsh-syntax-highlighting pacman-contrib broadcom-wl
sudo pacman --root "${squashfs}" --cachedir "${squashfs}"/var/cache/pacman/pkg -Sl | awk '/\[installed\]$/ {print $1 "/" $2 "-" $3}' > "${custom_iso}"/arch/pkglist.x86_64.txt
sudo pacman --root "${squashfs}" --cachedir "${squashfs}"/var/cache/pacman/pkg --noconfirm -Scc
sudo rm -f "${squashfs}"/var/cache/pacman/pkg/*
echo -e "Done installing packages to new system"
echo -e ""
# cd back into root system directory, remove old system
cd "${custom_iso}"/arch/x86_64 || exit
rm airootfs.sfs
# Recreate the iso using compression, remove unsquashed system, generate checksums
echo -e "Recreating Anarchy image ..." | log
sudo mksquashfs squashfs-root airootfs.sfs -b 1024k -comp xz
sudo rm -r squashfs-root
md5sum airootfs.sfs > airootfs.md5
echo -e "Done recreating Anarchy image"
echo -e ""
}
configure_boot() {
echo -e "Configuring boot ..." | log
arch_iso_label="$(<"${custom_iso}"/loader/entries/archiso-x86_64.conf awk 'NR==6{print $NF}' | sed 's/.*=//')"
arch_iso_hex="$(<<<"${arch_iso_label}" xxd -p)"
anarchy_iso_hex="$(<<<"${anarchy_iso_label}" xxd -p)"
cp "${working_dir}"/boot/splash.png "${custom_iso}"/arch/boot/syslinux/
cp "${working_dir}"/boot/iso/archiso_head.cfg "${custom_iso}"/arch/boot/syslinux/
sed -i "s/${arch_iso_label}/${anarchy_iso_label}/;s/Arch Linux archiso/Anarchy Linux/" "${custom_iso}"/loader/entries/archiso-x86_64.conf
sed -i "s/${arch_iso_label}/${anarchy_iso_label}/;s/Arch Linux/Anarchy Linux/" "${custom_iso}"/arch/boot/syslinux/archiso_sys.cfg
sed -i "s/${arch_iso_label}/${anarchy_iso_label}/;s/Arch Linux/Anarchy Linux/" "${custom_iso}"/arch/boot/syslinux/archiso_pxe.cfg
cd "${custom_iso}"/EFI/archiso/ || exit
echo -e "Replacing label hex in efiboot.img...\n${arch_iso_label} ${arch_iso_hex} > ${anarchy_iso_label} ${anarchy_iso_hex}" | log
xxd -c 256 -p efiboot.img | sed "s/${arch_iso_hex}/${anarchy_iso_hex}/" | xxd -r -p > efiboot1.img
if ! (xxd -c 256 -p efiboot1.img | grep "${anarchy_iso_hex}" &>/dev/null); then
echo -e "${color_red}\nError: failed to replace label hex in efiboot.img${color_blank}" | log
echo -e "Press any key to continue."
read input
fi
mv efiboot1.img efiboot.img
echo -e "Done configuring boot"
echo -e ""
}
create_iso() {
echo -e "Creating new Anarchy image ..." | log
cd "${working_dir}" || exit
xorriso -as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "${anarchy_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 "${out_dir}"/"${anarchy_iso_name}" \
"${custom_iso}"
if [ "$?" -eq 0 ]; then
rm -rf "${custom_iso}"
generate_checksums
else
echo -e "${color_red}Error: Image creation failed, exiting.${color_blank}" | log
exit 4
fi
}
generate_checksums() {
echo -e "Generating image checksum ..." | log
cd "${out_dir}"
echo -e "$(sha256sum "${anarchy_iso_name}")" > "${anarchy_iso_name}".sha256sum
echo -e "Done generating image checksum"
echo -e ""
}
uninstall_dependencies() {
if [ "${#missing_deps[@]}" -ne 0 ]; then
echo -e "Installed dependencies: ${missing_deps[*]}" | log
if [ "${user_input}" = true ]; then
echo -e "Uninstall these dependencies? [y/N]: "
local input
read -r input
case "${input}" in
y|Y|yes|YES|Yes)
echo -e "Chose to remove dependencies" | log
for pkg in "${missing_deps[@]}"; do
echo -e "Removing ${pkg} ..." | log
sudo pacman -Rs ${pkg}
echo -e "${pkg} removed" | log
done
echo -e "Removed all dependencies" | log
;;
*)
echo -e "Chose not to remove dependencies" | log
;;
esac
fi
fi
}
# Logs last command to display it in cleanup
command_log() {
current_command="${BASH_COMMAND}"
last_command="${current_command}"
}
# Starts if the iso-generator is interrupted
cleanup() {
# Check if user exited or if there was an error
if [ "${last_command}" = "init" ]; then
echo -e "User force stopped the script" | log
else
echo -e "${color_red}An error occured: ${last_command} exited with error code $?${color_blank}" | log
fi
# Check if customiso is mounted
if mount | grep "${custom_iso}" > /dev/null; then
echo -e "Unmounting customiso directory ..." | log
sudo umount "${custom_iso}"
fi
# Check and clean the customiso directory
if [ -d "${custom_iso}" ]; then
echo -e "Removing customiso directory ..." | log
# We have to use sudo in case root owns files inside customiso
sudo rm -rf "${custom_iso}"
fi
if [ "${last_command}" != "init" ]; then
echo -e "${color_white}Please report this issue to our Github issue tracker: https://git.io/JeOxK${color_blank}"
echo -e "${color_white}Make sure to include the relevant log: ${log_file}${color_blank}"
echo -e "${color_white}You can also ask about the issue in our Telegram: https://t.me/anarchy_linux${color_blank}"
fi
}
usage() {
clear
echo -e "${color_white}Usage: compile.sh [options]${color_blank}"
echo -e "${color_white} -c | --no-color) Disable color output${color_blank}"
echo -e "${color_white} -d | --docker) Compile inside docker${color_blank}"
echo -e "${color_white} -i | --no-input) Don't ask user for input${color_blank}"
echo -e "${color_white} -o | --output-dir) Specify directory for generated ISOs/checksums${color_blank}"
echo -e "${color_white} -l | --log-dir) Specify directory for logs${color_blank}"
echo -e ""
}
# Enable traps
trap command_log DEBUG
trap cleanup ERR
# Enable color output and user input by default
show_color=true
user_input=true
while (true); do
case "$1" in
-h|--help)
usage
exit 0
;;
-c|--no-color)
show_color=false
shift
;;
-d|--docker)
docker_compile=true
shift
;;
-i|--no-input)
user_input=false
shift
;;
-o|--output-dir)
shift
out_dir="$(readlink -f $1)"
shift
;;
-l|--log-dir)
shift
log_dir="$(readlink -f $1)"
shift
;;
*)
prettify
set_up_logging
set_version
init
extract_arch_iso
copy_config_files
build_system
configure_boot
create_iso
uninstall_dependencies
echo -e "${color_green}${anarchy_iso_name} image generated successfully. Check 'out' directory\n${color_blank}" | log
exit 0
;;
esac
done