-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbuild-iso
More file actions
executable file
·5613 lines (4704 loc) · 196 KB
/
build-iso
File metadata and controls
executable file
·5613 lines (4704 loc) · 196 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
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# shellcheck disable=SC2317
#==============================================================================
# build-iso: Build antiX liveCD/USB isos from scratch using debootstrap.
#
# Copyright 2012 -- 2024
# BitJam and anticapitalista for antiX <[email protected]>
#==============================================================================
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VERSION="1.99.09"
VERSION_DATE="March 24, 2023"
ME=${0##*/}
UPDATE_SKIP_PART="2-10,14-17,19"
ISO_SKIP_STAGE="2-5,7"
unset ARCH
usage() {
cat << Usage
Usage: $ME [options] [N]
Build an antiX liveCD/USB iso from scratch using debootstrap.
Options:
-a --auto Don't prompt before entering each stage
-A --AUTO ... and also clear out most files when done.
-c --chroot Enter the chroot environment if it is available
-C --COLOR= Color mode: high|low|off. Default is high.
-d --delete Delete squashfs dir and stage-?.out files when done
without prompting
-D --DELETE Also delete entire work directory without prompting
-e --error-ask Ask before exiting due to stderr output messages
-f --fast Mount chroot directory as tmpfs for speed
-F --FAST-UMOUNT List and optionally umount all our tmpfs mounts
-h --help Show this help
-i --iso-only Only build an iso. Don't create a squashfs file
-I --INTERACTIVE Let Debian ask config questions inside the chroot
-j --jbb Suppress voluminous output
-m --manual Enter chroot if the automatic chroot stage fails
-n --no-error-check Don't do error checking on stderr output
-N --NO-ERROR-LOG Also, don't log or highlight errors on stderr
-p --pretend Show what would be done next but do nothing
-q --quiet Ask fewer questions (and print less in --pretend mode)
-r --reset Update all default variables in stage 0
-s --stats Display the number of packages that would be installed
-S --SAVE Save the squashfs directory in the cache
-u --update Skip most parts in chroot stage preceding add and remove
-U --UPDATE Merge add.list and remove.list into the other lists
-V --VERBOSE Print even more than we already do
-v --version Print version info and exit
--lz4 Override default compression scheme with lz4
--user-default Specify a defaults file, must be present in Input folder
--zstd Override default compression scheme with zstd
--show-stages Show the stages of processing
--show-parts Show parts of stage-$chroot_stage and how to control them
-0 -- -8 Start over from stage N.
--stop5 Stop process at Stage 5 (cleanup)
--stop8 Stop process at Stage 8 (iso generation)
Short options stack: -up0 == -u -p -0 == --update --pretend -0
Optional argument:
N Start over from stage N (same as -N).
Usage
exit 0
}
# Output from start_main() does not get vlogged
main() {
unset UMOUNT_ERRORS
MAIN_T=$EPOCHSECONDS
local firefox_prefs="/etc/skel/.mozilla/firefox/*/prefs.js"
local all_stages="0 1 2 3 4 5 6 7 8 9"
local chroot_stage=4
local stage output_file
local manual_mode pretend_mode auto_mode chroot_mode delete_mode delete_all
local quiet_mode start_from reset_mode iso_only full_auto update_mode UPDATE_mode
local show_parts show_stages interactive color_mode verbose_mode stats_mode
local no_log_errors no_check_errors disable_errors do_fast check_tmpfs
local save_mode jbb_mode
local script_dir
script_dir=$(dirname "$(readlink -f "$0")")
local template="$script_dir/Template"
local tools="$script_dir/Tools"
local output_dir="$script_dir/Output"
local input_dir="$script_dir/Input"
local remaster_dir
remaster_dir=$(readlink -f "$script_dir"/Remaster)
local iso_file_dir="$remaster_dir/iso-files"
local deb_cache_dir="$remaster_dir/deb-cache/archives"
local pacman_cache_dir="$remaster_dir/pacman-cache/pkg"
local manual_selections=manual-selections
local exit_file="$output_dir/MUST-EXIT"
local sign_off_file="$output_dir/SIGN-OFF"
local first_time_file="$input_dir/first-time"
local did_stage_file="$output_dir/did-stage"
local log_file="$output_dir/$ME.log"
local err_file="$output_dir/$ME.err"
local make_xinitrc=/usr/share/antiX/lib/make-xinitrc
# local live_files_list=$input_dir/live-files.list
local strict_regex_file="$input_dir/strict-exceptions.regex"
local lax_regex_file="$input_dir/lax-errors.regex"
local regex_files="$lax_regex_file $strict_regex_file"
local theme_dir="$script_dir/Themes"
local root_path="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin"
local template
local part_env="ASK_PART EXIT_PART RUN_PART SHELL_PART SKIP_PART TEST_PART"
local stage_env="ASK_STAGE EXIT_STAGE SKIP_STAGE"
local build_dir="/Build"
local partial_name="PARTIAL"
local partial_file="$build_dir/$partial_name"
local seed_fname="random-seed"
local user_defaults apt_yes
# local initrd_encrypt
local short_stack="aAcCdDefFhiIjmnNpqrsuUvV0-8"
local arg val ARGS
ARGS="$*"
while (( $# > 0 )) && [[ $1 =~ ^- ]]; do
arg=${1#-}; shift
# Unstack single-letter options
case $arg in
[$short_stack][$short_stack]*)
if echo "$arg" | grep -q "^[$short_stack]\+$"; then
# shellcheck disable=SC2046
set -- $(echo "$arg" | sed -r 's/([a-zA-Z])/ -\1 /g') "$@"
continue
fi;;
esac
# Deal with all options that take a parameter
case $arg in
-color|C) (( $# < 1 )) && fatal "Expected a parameter after: $(pqw -"$arg")"
val=$1
[[ $val =~ ^- ]] \
&& fatal "Suspicious argument after -$arg: $(pqw "$val")"
shift ;;
-user-default) (( $# < 1 )) && fatal "Expected a parameter after: $(pqw -"$arg")"
val=$1
# Use basename to allow both "filename" and "Input/filename" formats
val=$(basename "$val")
user_defaults="$input_dir/$val"
[[ ! -e "$user_defaults" ]] \
&& fatal "Default file not found -$arg: $(pqw "$val")"
shift ;;
*=*) val=${arg#*=} ;;
*) val="???" ;;
esac
case $arg in
-auto|a) auto_mode=true ; apt_yes="-y" ;;
-AUTO|A) auto_mode=true ; full_auto=true ; apt_yes="-y" ;;
-chroot|c) chroot_mode=true ;;
-color=*|C=*) color_mode=$val ;;
-COLOR|C) color_mode=$val ;;
-delete|d) delete_mode=true ;;
-DELETE|D) delete_mode=true ; delete_all=true ;;
-error-ask|e) ask_errors=true ;;
-fast|f) do_fast=true ;;
-FAST-UMOUNT|F) check_tmpfs=true ;;
-help|h) usage ;;
-iso-only|i) iso_only=true ;;
-INTERACTIVE|I) interactive=true ;;
-jbb|j) jbb_mode=true ;;
-manual|m) manual_mode=true ;;
-no-error-check|n) disable_errors=true ;;
-NO-ERROR-LOG|N) no_log_errors=true ; disable_errors=true ;;
-pretend|p) pretend_mode=true ;;
-quiet|q) quiet_mode=true ;;
-reset|r) reset_mode=true ;;
-stats|s) stats_mode=true ;;
-SAVE|S) save_mode=true ;;
-show-parts) show_parts=true ;;
-show-stages) show_stages=true ;;
-update|u) update_mode=true ;;
-UPDATE|U) UPDATE_mode=true ;;
-user-default) ;;
-VERBOSE|V) verbose_mode=true ;;
-lz4) lz4_override=true ;;
-zstd) zstd_override=true ;;
-stop5) stop_5=true ;;
-stop8) stop_8=true ;;
[0-8]) [[ $start_from ]] && fatal "Can only set starting stage once"
start_from=$arg ;;
-version|v) echo "$ME version $VERSION ($VERSION_DATE)"; exit ;;
*) fatal "Unknown parameter -$arg" ;;
esac
done
is_antiX && apt_yes=
if (( $# == 1 )) && [[ -z $start_from ]]; then
arg=$1; shift
case $arg in
[0-8]) start_from=$arg ;;
*) fatal "Bad stage argument: $arg. Must be [0-8]."
esac
fi
if [[ -n $update_mode ]]; then
: "${start_from:=$((chroot_stage - 1))}"
SKIP_PART="$SKIP_PART${SKIP_PART:+,}$UPDATE_SKIP_PART"
fi
[[ -n $reset_mode ]] && : "${start_from:=0}"
[[ -n $iso_only ]] && SKIP_STAGE="$SKIP_STAGE${SKIP_STAGE:+,}$ISO_SKIP_STAGE"
case $color_mode in
high|hi|"") color_mode="high" ;;
low|lo) color_mode="low" ;;
off) ;;
*) fatal "Bad --color operand: $color_mode" ;;
esac
local black blue green cyan red purple brown lt_gray dk_gray lt_blue
local lt_green lt_cyan lt_red magenta yellow white rev_red nc
local text_co bold_co err_co
local num_co prompt_co time_co
local high_co
# shellcheck disable=SC2034
set_colors() {
black=$'\e[0;30m'; blue=$'\e[0;34m'; green=$'\e[0;32m';
cyan=$'\e[0;36m'; red=$'\e[0;31m'; purple=$'\e[0;35m';
brown=$'\e[0;33m'; lt_gray=$'\e[0;37m'; dk_gray=$'\e[1;30m';
lt_blue=$'\e[1;34m'; lt_green=$'\e[1;32m'; lt_cyan=$'\e[1;36m';
lt_red=$'\e[1;31m'; magenta=$'\e[1;35m'; yellow=$'\e[1;33m';
white=$'\e[1;37m'; rev_red=$'\e[0;7;31m'; nc=$'\e[0m';
}
if [[ $color_mode != "off" ]]; then
set_colors
fi
case $color_mode in
high) text_co=$lt_cyan; bold_co=$yellow; err_co=$lt_red;
num_co=$magenta; prompt_co=$lt_green; time_co=$cyan;
high_co=$white; ;;
low) text_co=$nc; bold_co=$lt_blue; err_co=$red;
num_co=$purple; prompt_co=$green; time_co=$cyan;
high_co=$cyan; ;;
esac
[[ -n $pretend_mode ]] || SIGN_OFF="${bold_co}Quit$text_co $ME$nc"
local pretty_fmt="%15s: $text_co%s$nc\n"
(( $# > 0 )) && fatal "Extra command line parameters: $(pqw "$@")"
[[ -z $script_dir ]] && fatal "No script_dir!"
[[ $script_dir = "/" ]] && fatal "script_dir can't be root dir!"
[[ -n $show_stages ]] && show_stages
[[ -n $show_parts ]] && show_parts
SUDO=sudo
(( UID == 0 )) && SUDO=
[[ -n $show_parts || -n $show_stages ]] && exit
local normal_defaults="$input_dir/defaults $input_dir/defaults-local"
local all_defaults="$input_dir/defaults-system $normal_defaults"
if [[ -n $user_defaults ]]; then
local normal_defaults="$user_defaults $input_dir/defaults-local"
local all_defaults="$input_dir/defaults-system $normal_defaults"
fi
load_defaults
set_output_paths() {
# shellcheck disable=SC2153
local work_name="$DISTRO_NAME-${DISTRO_VERSION}-$ISO_ARCH"
[[ ${DISTRO_FAMILY:-debian} = debian ]] && work_name="$work_name-$DEBIAN_RELEASE"
[[ "$DISTRO_NAME" = antiX ]] && work_name="$work_name-$ISO_FLAV"
output_dir="$script_dir/Output/$work_name"
log_file="$output_dir/$ME.log"
err_file="$output_dir/$ME.err"
did_stage_file="$output_dir/did-stage"
}
# Set ISO_ARCH based on ARCH
case $ARCH in
i386) ISO_ARCH=386 ;;
amd64) ISO_ARCH=x64 ;;
x86_64) ISO_ARCH=x64 ;;
*) error "Invalid ARCH $(pqw "$ARCH")." ;;
esac
# Set kernel variables (copied from do_stage_0)
if [[ ${DISTRO_FAMILY:-debian} = debian ]]; then
: "${K_PKG:=linux}"
: "${K_HEADERS_PKG:=linux-headers}"
: "${K_BOOT_IMAGE:=vmlinuz-linux}"
: "${K_INITRAMFS_IMAGE:=initramfs-linux.img}"
: "${K_FALLBACK_INITRAMFS_IMAGE:=initramfs-linux-fallback.img}"
else
: "${K_PKG:=linux}"
: "${K_HEADERS_PKG:=linux-headers}"
: "${K_BOOT_IMAGE:=vmlinuz-linux}"
: "${K_INITRAMFS_IMAGE:=initramfs-linux.img}"
: "${K_FALLBACK_INITRAMFS_IMAGE:=initramfs-linux-fallback.img}"
fi
K_GNU=
case $ISO_FLAV in
*-libre) K_GNU=-gnu
FLAV=${ISO_FLAV%-libre} ;;
*) FLAV=$ISO_FLAV ;;
esac
local distro_k_arch=686
is_antiX && distro_k_arch=486
case $ARCH in
i386) K_ARCH=$distro_k_arch ;;
amd64) K_ARCH=amd64 ;;
x86_64) K_ARCH=amd64 ;;
*) error "Invalid ARCH $(pqw "$ARCH")." ;;
esac
if [[ ${DISTRO_FAMILY:-debian} = debian ]]; then
K_NAME=$(echo "$K_TEMPLATE" | sed \
-e "s/%V/$K_VERSION/" \
-e "s/%G/$K_GNU/" \
-e "s/%R/$K_REVISION/" \
-e "s/%A/$K_ARCH/" \
-e "s/%V/$K_VERSION/")
else
: "${K_NAME:=$K_PKG}"
fi
# Set build-specific output directory
set_output_paths
# In auto mode we need to cache sudo credentials to avoid mid-build prompts
# (or run as root) to avoid confusing mid-build failures.
if (( UID != 0 )) && [[ -n $auto_mode ]]; then
sudo true >/dev/null 2>&1 \
|| fatal "$(pq --auto) requires sudo access (or run as root)"
fi
trap on_exit EXIT
trap "echo; exit" INT
if [[ -n $pretend_mode || -n $chroot_mode || -n $stats_mode ]]; then
log_file=/dev/null
else
mkdir -p "$(dirname "$log_file")"
fi
if [[ -n $check_tmpfs ]]; then
check_all_tmpfs && exit
vexit "No tmpfs mounts were found"
fi
[[ "$script_dir" == "$build_dir" ]] && no_log_errors=true
{
printf "\n$bold_co%63s$nc\n" "" | sed 's/ /-/g'
echo -e "$ME $ARGS"
echo -e " version: $VERSION ($VERSION_DATE)"
echo -e " started: $(date)"
echo -e "directory: $script_dir\n"
} >> "$log_file"
# Always start out with a clean slate
rm -f "$exit_file" "$sign_off_file"
update_template_file basic-applications.list basic-package.list
update_template_file pesky-packages.list pesky-package.list
[[ -n $update_mode ]] && say "update mode: skipping parts $(pq "$SKIP_PART")"
# shellcheck disable=SC2086
expand_parts $part_env $stage_env
# Clear out the did-stage file
: > "$did_stage_file"
# We only advance to the next stage if the previous stages all completed and wrote
# stage-N.out output files. These files are also used for passing information on
# from one stage to the next.
while true; do
# Read previous output files and set the stage
if [[ -n $start_from ]]; then
stage=$start_from
# Source all previous stage files to get full state
for ((s=0; s<=stage; s++)); do
output_file="$output_dir/stage-$s.out"
# shellcheck disable=SC1090
[[ -r "$output_file" ]] && source "$output_file"
done
else
for stage in $all_stages; do
output_file="$output_dir/stage-$stage.out"
[[ -r "$output_file" ]] || break
# shellcheck disable=SC1090
source "$output_file"
done
fi
# Variables derived from output files
local full_distro_name="$DISTRO_NAME-${DISTRO_VERSION}_$ISO_ARCH"
[[ "$DISTRO_NAME" = antiX ]] && full_distro_name="$full_distro_name-$ISO_FLAV"
local fancy_name="$full_distro_name $CODE_NAME $RELEASE_DATE"
local work_name="$DISTRO_NAME-${DISTRO_VERSION}-$ISO_ARCH"
[[ ${DISTRO_FAMILY:-debian} = debian ]] && work_name="$work_name-$DEBIAN_RELEASE"
[[ "$DISTRO_NAME" = antiX ]] && work_name="$work_name-$ISO_FLAV"
local work_dir="$remaster_dir/work/$work_name"
local iso_dir="$work_dir/iso"
local sqfs_dir="$work_dir/squashfs"
local sqfs_output_dir="$sqfs_dir$build_dir/Output/$work_name"
local sqfs_input_dir="$sqfs_dir$build_dir/Input"
local boot_menu_dir="$sqfs_dir/usr/share/boot-menus"
local initrd_dir="$work_dir/initrd"
# Ensure convenience links are correct for current build
convenience_link "$work_dir" work
convenience_link "$sqfs_dir" sqfs
convenience_link "$iso_dir" iso
convenience_link "$initrd_dir" initrd
local chroot_cache_opts="chroot $work_name $sqfs_dir"
local deboot_cache_opts
if [[ ${DISTRO_FAMILY:-debian} = arch ]]; then
deboot_cache_opts="pacstrap $ARCH $sqfs_dir"
else
deboot_cache_opts="debootstrap $ARCH-$DEBIAN_RELEASE $sqfs_dir"
fi
# Select template root for all stages (not just Stage 0).
case ${DISTRO_FAMILY:-debian} in
debian) template="$script_dir/Template" ;;
arch) template="$script_dir/Template/Arch"
[[ -d "$template" ]] || fatal "Missing Arch templates at $(pq "$template")" ;;
*) fatal "Unknown DISTRO_FAMILY: $(pqw "$DISTRO_FAMILY")" ;;
esac
local manual_selections_template=$template/COMMON/$manual_selections
# Do weird modes here after variables are set
[[ -n $chroot_mode ]] && do_chroot && exit
if [[ -n $start_from ]]; then
(( stage < start_from )) \
&& fatal "Only at stage $(pqnw "$stage"). Can't start from stage $(pqnw "$start_from")."
clear_outputs "$start_from" "$pretend_mode" "$delete_mode" || exit
start_from=
fi
[[ -n $save_mode ]] && do_save && exit
[[ -n $pretend_mode ]] && do_pretend && exit
[[ -n $stats_mode ]] && do_stats && exit
[[ -n $UPDATE_mode ]] && update_add_remove_lists && exit
[[ "$script_dir" == "$build_dir" && "$stage" != "$chroot_stage" ]] \
&& fatal "In chroot environment but stage is $(pqw "$stage")"
# Set window title (but only in normal modes)
echo -ne "\e]0;$ME stage:$stage $full_distro_name\a"
DID_WINDOW_TITLE=true
if has_word SKIP_STAGE "$stage"; then
say "Skipping stage $(pqn "$stage")"
leave_stage notime
continue
fi
# We read in these files every time because they might have been
# edited inside the stages and the changes don't propagate up to here
if [[ -z $disable_errors ]]; then
read_error_regexes
check_errors_reset
#say "ERROR_OFFSET=$ERROR_OFFSET"
fi
if (( stage != chroot_stage )) && [[ -z $no_log_errors ]]; then
[[ -e "$exit_file" ]] && exit "$(cat "$exit_file")"
# The tee and sed only apply to stdrr. Stdout goes right through.
# This highlights stderr output and stores it in a file which we
# periodically scan with the check_errors_* routines
main_case 7>&1 1>&2 2>&7 \
| tee -a "$err_file" | sed -e "s/^/$red/" -e "s/$/$nc/"
# The redirects above cause main_case() to launch in a subshell which
# breaks the "exit" command. This fixes it by using my_exit() which
# writes $exit_file before exiting
[[ -e "$exit_file" ]] && exit "$(cat "$exit_file" 2>/dev/null)"
else
main_case
fi
done
}
main_case() {
case $stage in
0) do_stage_0 ;;
1) do_stage_1 ;;
2) do_stage_2 ;;
3) do_stage_3 ;;
4) do_stage_4 ;;
5) do_stage_5 ;;
6) do_stage_6 ;;
7) do_stage_7 ;;
8) do_stage_8 ;;
9) do_stage_9 ;;
*) fatal "Unknown stage: $stage"
esac
}
#==============================================================================
# The Ten Stages of Processing
#==============================================================================
#------------------------------------------------------------------------------
# Stage 0 gathers all user input and prepares defaults and directories
#------------------------------------------------------------------------------
do_stage_0() {
enter_stage 0 "!Gather inputs and set defaults"
[[ -s "$err_file" && -z "$no_log_errors" ]] \
&& YES_no "Clear error file $(pq "$ME.err")" && : > "$err_file"
if [[ -e "$first_time_file" ]]; then
say "The input file structure and layout have changed."
say "Your are encouraged to run in $(pq --reset) mode to verify input parameters."
if YES_no "Enter $(pq --reset) mode"; then
say "Entering $(pq --reset) mode."
reset_mode=true
else
rm -f "$first_time_file"
fi
fi
# shellcheck disable=SC2086
pick_prog MAKE_ISO $MAKE_ISO_PROGS
# shellcheck disable=SC2086
pick_prog GZIP $GZIP_PROGS
require_programs chroot isohybrid mksquashfs md5sum sudo tee zsync \
pkill expand strings iconv unbuffer
mkdir -p "$output_dir" || my_exit
# Give user a chance to set up directories the way they want
if ! [[ -d $remaster_dir ]]; then
cat << Remaster_Blurb
The "Remaster" directory does not exist. This is where *.iso files,
cache files, and intermediate storage will reside. Think gigabytes.
If you want it to be on a different device then exit now and create
a symlink called "Remaster".
Remaster_Blurb
YES_no_loud "Shall I create a local \"Remaster\" directory for you" \
|| vexit "Need Remaster symlink or directory to continue"
mkdir -p "$script_dir/Remaster" || my_exit
fi
local name
for name in DISTRO_NAME DISTRO_VERSION CODE_NAME K_VERSION K_REVISION \
NEW_HOSTNAME; do
update_default $name
done
load_defaults
: "${DISTRO_FAMILY:=debian}"
# Note: template selection is handled in the main stage loop as well, so
# stage-0 is not required for subsequent stages to be correct.
case $DISTRO_FAMILY in
debian) template="$script_dir/Template" ;;
arch) template="$script_dir/Template/Arch"
[[ -d "$template" ]] || error "Missing Arch templates at $(pq "$template")" ;;
*) error "Unknown DISTRO_FAMILY: $(pqw "$DISTRO_FAMILY")" ;;
esac
# Distro-specific tool requirements (outer build environment)
case $DISTRO_FAMILY in
debian) require_programs debootstrap apt-get dpkg ;;
arch) require_arch_host_tools ;;
esac
# Fill in default value
: "${RELEASE_DATE:=$(printf '%(%e %B %Y)T' -1)}"
: "${ISO_LABEL:=${DISTRO_NAME}-Live}"
if [[ $DISTRO_FAMILY = debian ]]; then
choose "local mirror" LOCAL_MIRROR \
us gr au be bg br ch cz de dk ee es "fi" fr \
gr hk hr hu ie is it jp kr nl no nz pl pt ro \
ru se si sk tr tw ua uk us
choose "Debian release" DEBIAN_RELEASE \
stable testing unstable bullseye bookworm
fi
if [[ -z ${ENABLE_LOCALES:-} ]]; then
choose "which locales to enable" ENABLE_LOCALES \
"Default (about 60)" \
"All (about 400)" \
"Single (the one default locale)"
fi
if [[ $DISTRO_FAMILY = arch ]]; then
[[ ${ARCH:-} = x86_64 ]] || choose "arch" ARCH x86_64
else
[[ ${ARCH:-} = i386 || ${ARCH:-} = amd64 ]] || choose "arch" ARCH i386 amd64
fi
if [[ -n ${ISO_FLAV:-} ]]; then
local flav_dir=${ISO_FLAV%-libre}
[[ -d "$template/$flav_dir" ]] || ISO_FLAV=
fi
if [[ -z ${ISO_FLAV:-} ]]; then
local flavs=()
mapfile -t flavs < <(flavour_list)
choose "flavour" ISO_FLAV "${flavs[@]}" core-libre
fi
K_GNU=
case $ISO_FLAV in
*-libre) K_GNU=-gnu
FLAV=${ISO_FLAV%-libre} ;;
*) FLAV=$ISO_FLAV ;;
esac
RESPIN_INHERIT=
if is_distro_flav "$FLAV"; then
ISO_RESPIN_OF=$FLAV
else
choose "flavour to base respin on" ISO_RESPIN_OF full base core
if [[ -z $(ls "$template/$FLAV") ]] \
&& YES_no "Fill \"$FLAV\" directory from \"$ISO_RESPIN_OF\" ?"; then
cp "$template/$ISO_RESPIN_OF"/*.list "$template/$FLAV/"
YES_no "Do you want to stop now to edit your new respin?" \
&& vexit "at user's request"
fi
RESPIN_INHERIT=$ISO_RESPIN_OF
fi
is_distro_flav "$ISO_RESPIN_OF" || fatal "Invalid flavour to base respin on: $ISO_RESPIN_OF"
local distro_k_arch=686
is_antiX && distro_k_arch=486
case $ARCH in
i386) K_ARCH=$distro_k_arch ; ISO_ARCH=386 ;;
amd64) K_ARCH=amd64 ; ISO_ARCH=x64 ;;
x86_64) K_ARCH=amd64 ; ISO_ARCH=x64 ;;
*) error "Invalid ARCH $(pqw "$ARCH")." ;;
esac
if [[ ${DISTRO_FAMILY:-debian} = debian ]]; then
K_NAME=$(echo "$K_TEMPLATE" | sed \
-e "s/%V/$K_VERSION/" \
-e "s/%G/$K_GNU/" \
-e "s/%R/$K_REVISION/" \
-e "s/%A/$K_ARCH/" \
-e "s/%V/$K_VERSION/")
else
: "${K_PKG:=linux}"
: "${K_HEADERS_PKG:=linux-headers}"
: "${K_BOOT_IMAGE:=vmlinuz-linux}"
: "${K_INITRAMFS_IMAGE:=initramfs-linux.img}"
: "${K_FALLBACK_INITRAMFS_IMAGE:=initramfs-linux-fallback.img}"
: "${K_NAME:=$K_PKG}"
fi
# shellcheck disable=SC2086
local $HOST_ARCH
case $(uname -m) in
i386|i486|i686) HOST_ARCH=386 ;;
x86_64) HOST_ARCH=x64 ;;
*) error "Cannot detect Host ARCH" ;;
esac
# Kernel wildcard resolution deferred to Stage 4 (after chroot setup)
if [[ $K_NAME =~ \* ]]; then
say "Kernel wildcard $(pq "$K_NAME") will be resolved in Stage 4"
fi
#$K_VERSION$K_GNU-antix.$K_REVISION-$K_ARCH-smp
[[ -n $THEME ]] || select_theme
check_theme_dir "$THEME"
# repeated code
remaster_dir=$(readlink -f "$script_dir/Remaster")
set_output_paths
if [[ -n $pretend_mode || -n $chroot_mode || -n $stats_mode ]]; then
log_file=/dev/null
else
mkdir -p "$output_dir"
fi
output_file="$output_dir/stage-$stage.out"
: > "$did_stage_file"
local full_distro_name=$DISTRO_NAME-${DISTRO_VERSION}_$ISO_ARCH
[[ $DISTRO_NAME = antiX ]] && full_distro_name=$full_distro_name-$ISO_FLAV
local iso_file=$full_distro_name.iso
if [[ ${DISTRO_FAMILY:-debian} = debian ]]; then
local dir
for dir in $(flavour_list) COMMON base-AND-full; do
mkdir -p "$script_dir/Deb/$dir"
done
elif [[ ${DISTRO_FAMILY:-debian} = arch ]]; then
# Create directories for Arch packages
mkdir -p "$script_dir/Deb/Arch"
mkdir -p "$script_dir/Deb/ArchXfce"
mkdir -p "$script_dir/Deb/ArchKDE"
fi
local full_iso_file=$iso_file_dir/$iso_file
if [[ -e "$full_iso_file" ]]; then
say "The output file $(pq "Remaster/iso-files/$iso_file") already exists!"
say "If we continue then it will get over-written."
YES_no "Continue anyway" || my_exit 0
fi
cat << Output > "$output_file"
ARCH="$ARCH"
DISTRO_FAMILY="$DISTRO_FAMILY"
DEBIAN_RELEASE="$DEBIAN_RELEASE"
FLAV="$FLAV"
GZIP="$GZIP"
ISO_ARCH="$ISO_ARCH"
ISO_FLAV="$ISO_FLAV"
ISO_LABEL="$ISO_LABEL"
K_NAME="$K_NAME"
K_PKG="$K_PKG"
K_HEADERS_PKG="$K_HEADERS_PKG"
K_BOOT_IMAGE="$K_BOOT_IMAGE"
K_INITRAMFS_IMAGE="$K_INITRAMFS_IMAGE"
K_FALLBACK_INITRAMFS_IMAGE="$K_FALLBACK_INITRAMFS_IMAGE"
MAKE_ISO="$MAKE_ISO"
RELEASE_DATE="$RELEASE_DATE"
RESPIN_INHERIT="$RESPIN_INHERIT"
THEME="$THEME"
ISO_RESPIN_OF="$ISO_RESPIN_OF"
Output
say "Ready to begin creation of $(pq "$iso_file")"
pretty_output $((stage + 1)) >> "$log_file"
[[ -e "$first_time_file" ]] && rm -f "$first_time_file"
if [[ -z $quiet_mode ]]; then
echo "With:"
pretty_output $((stage + 1))
echo
fi
do_one_stat
# shellcheck disable=SC2059
printf "$pretty_fmt" REMASTER_DIR "$remaster_dir"
# shellcheck disable=SC2059
printf "$pretty_fmt" "on device" "$(df "$remaster_dir" | tail -n1 | cut -f1 -d" ")"
}
#------------------------------------------------------------------------------
# Stage 1 creates working directories and symlinks
#------------------------------------------------------------------------------
do_stage_1() {
enter_stage 1 "Make directories and symlinks"
convenience_link "$work_dir" work
convenience_link "$sqfs_dir" sqfs
convenience_link "$iso_dir" iso
convenience_link "$initrd_dir" initrd
$SUDO chown root:root "$sqfs_dir"
leave_stage notime
}
#------------------------------------------------------------------------------
# Stage 2 runs debootstrap, makes some small adjustmesnt to the fs and also
# handles caching what debootstrap created.
#------------------------------------------------------------------------------
do_stage_2() {
enter_stage 2 "Bootstrap root filesystem"
if [[ ${DISTRO_FAMILY:-debian} = arch ]]; then
say "Using pacstrap (Arch; experimental)"
[[ $do_fast ]] && mount_tmpfs
if [[ -d "$sqfs_dir" ]]; then
say "Clear out existing files ..."
check_sqfs_dir
$SUDO rm -rf "$(dirname "${sqfs_dir:?}")"/squashfs/*
fi
# shellcheck disable=SC2086
if restore_cache $chroot_cache_opts; then
leave_stage
return
fi
# shellcheck disable=SC2086
if ! restore_cache $deboot_cache_opts; then
umount_chroot
check_errors_strict
start_timer
$SUDO mkdir -p "$sqfs_dir/etc"
# Create vconsole.conf before pacstrap to avoid mkinitcpio errors
$SUDO sh -c "printf '%s\n' 'KEYMAP=us' > '$sqfs_dir/etc/vconsole.conf'"
: "${PACSTRAP_PACKAGES:=base linux linux-firmware}"
# shellcheck disable=SC2086
say "pacstrap to $(pq "$sqfs_dir") with: $(pq $PACSTRAP_PACKAGES)"
if is_arch_host; then
# On Arch host, use native pacman configuration
say "Using host pacman configuration (Arch Linux)"
# shellcheck disable=SC2086
$SUDO pacstrap -c -G -M "$sqfs_dir" $PACSTRAP_PACKAGES 2>&1 | tr '\r' '\n'
else
# On Debian/MX host, provide dedicated config + mirrors
: "${PACMAN_CONF:=Input/arch/pacman.conf}"
: "${PACMAN_MIRRORLIST:=Input/arch/mirrorlist}"
local pacman_conf_src=$script_dir/${PACMAN_CONF#./}
local mirror_src=$script_dir/${PACMAN_MIRRORLIST#./}
[[ -r "$pacman_conf_src" ]] || fatal "Missing PACMAN_CONF: $(pqw "$PACMAN_CONF")"
[[ -r "$mirror_src" ]] || fatal "Missing PACMAN_MIRRORLIST: $(pqw "$PACMAN_MIRRORLIST")"
local pacman_work=$work_dir/pacman
$SUDO mkdir -p "$pacman_work"
local pacman_conf=$pacman_work/pacman.conf
local mirrorlist=$pacman_work/mirrorlist
$SUDO cp "$mirror_src" "$mirrorlist"
$SUDO cp "$pacman_conf_src" "$pacman_conf"
$SUDO sed -i "s|^Include = /etc/pacman.d/mirrorlist$|Include = $mirrorlist|" "$pacman_conf"
# Ensure the host keyring exists for signature verification.
if [[ ! -d /etc/pacman.d/gnupg ]] || [[ -z $(ls -A /etc/pacman.d/gnupg 2>/dev/null) ]]; then
require_programs_fatal pacman-key makepkg
if ! ensure_archlinux_keyring_layout; then
fatal "Missing Arch keyring file. On Debian/MX try: sudo apt install archlinux-keyring"
fi
say "Initialize host pacman keyring"
$SUDO sh -c "pacman-key --init 2>&1 | tr '\r' '\n'"
$SUDO sh -c "pacman-key --populate archlinux 2>&1 | tr '\r' '\n'"
fi
# shellcheck disable=SC2086
$SUDO pacstrap -C "$pacman_conf" -c -G -M "$sqfs_dir" $PACSTRAP_PACKAGES 2>&1 | tr '\r' '\n'
fi
end_timer "run pacstrap"
check_errors_lax
umount_chroot
[[ -e "$sqfs_dir/bin/bash" ]] || fatal "pacstrap failed"
fi
# Ensure the target has a working pacman configuration and mirrorlist.
if is_arch_host; then
# On Arch host, pacstrap should have set up the target correctly
# But let's verify and fix if needed
if [[ ! -f "$sqfs_dir/etc/pacman.conf" ]]; then
say "Copying host pacman.conf to target"
$SUDO cp "/etc/pacman.conf" "$sqfs_dir/etc/pacman.conf"
fi
if [[ ! -f "$sqfs_dir/etc/pacman.d/mirrorlist" ]]; then
say "Copying host mirrorlist to target"
$SUDO cp "/etc/pacman.d/mirrorlist" "$sqfs_dir/etc/pacman.d/mirrorlist"
fi
else
# On Debian/MX hosts, pacstrap does not reliably set this up for the target.
$SUDO mkdir -p "$sqfs_dir/etc/pacman.d"
$SUDO cp "$mirror_src" "$sqfs_dir/etc/pacman.d/mirrorlist"
$SUDO cp "$pacman_conf_src" "$sqfs_dir/etc/pacman.conf"
if ! $SUDO grep -q '^\[extra\]' "$sqfs_dir/etc/pacman.conf"; then
fatal "Target pacman.conf is missing repository sections (e.g. [extra]). Check $(pqw "$PACMAN_CONF")"
fi
fi
# Avoid mkinitcpio warnings about missing vconsole config in minimal installs.
if [[ ! -e "$sqfs_dir/etc/vconsole.conf" ]]; then
$SUDO mkdir -p "$sqfs_dir/etc"
$SUDO sh -c "printf '%s\n' 'KEYMAP=us' > '$sqfs_dir/etc/vconsole.conf'"
fi
report_size "$sqfs_dir"
# shellcheck disable=SC2086
create_cache $deboot_cache_opts
say "Customize live system (Arch)"
copy_template_dir squashfs "$sqfs_dir"
# pacstrap may emit warnings that are not actionable for our build; reset
# error offset so Stage-level strict checking doesn't block progress.
check_errors_reset
leave_stage notime
return
fi
[[ $do_fast ]] && mount_tmpfs
if [[ -d "$sqfs_dir" ]]; then
say "Clear out existing files ..."
check_sqfs_dir
# Convoluted to be safer against deleting entire filesystem
$SUDO rm -rf "$(dirname "${sqfs_dir:?}")"/squashfs/*
fi
# shellcheck disable=SC2086
if restore_cache $chroot_cache_opts; then
leave_stage
return
fi
# shellcheck disable=SC2086
if ! restore_cache $deboot_cache_opts; then
say "debootstrap for $(pq "$ARCH" "$DEBIAN_RELEASE") from local mirror $(pq "$LOCAL_MIRROR") ..."
umount_chroot
mount_deb_cache
local args cnt exclude_list include_list keyring url
args="--arch=$ARCH"
exclude_list=$(gather_join exclude-debootstrap)
include_list=$(gather_join include-debootstrap)
cnt=$(echo "$exclude_list" | tr ',' '\n' | wc -l)
psay "$cnt" "Exclude $(pqn %n) package%s"
keyring="$template/$ISO_RESPIN_OF/keyring.gpg"
[[ -n "$exclude_list" ]] && args="$args --exclude=$exclude_list"
[[ -n "$include_list" ]] && args="$args --include=$include_list"
[[ -r "$keyring" ]] && args="$args --keyring=$keyring"
url="$(eval echo "$MIRROR_URL_TEMPLATE")"
check_errors_strict
start_timer
$SUDO mkdir -p "$sqfs_dir/usr" "$sqfs_dir/etc"
local debian_frontend_env=""
if [[ -n $auto_mode ]]; then
debian_frontend_env="DEBIAN_FRONTEND=noninteractive"
say "Running debootstrap in noninteractive mode (auto mode enabled)..."
else
say "Running debootstrap in interactive mode..."
fi
vsay "DEBUG: debootstrap args: $args"
vsay "DEBUG: DEBIAN_RELEASE: $DEBIAN_RELEASE"
vsay "DEBUG: sqfs_dir: $sqfs_dir"
vsay "DEBUG: url: $url"
# WSL workaround: patch debootstrap to replace 'sync' with 'true' to avoid hangs
if grep -qi microsoft /proc/version 2>/dev/null; then
say "WSL detected: creating patched debootstrap without sync..."
local patched_debootstrap="$work_dir/debootstrap-no-sync"
$SUDO sed 's/^\tsync$/\ttrue # sync disabled for WSL/' /usr/sbin/debootstrap > "$patched_debootstrap"
$SUDO chmod +x "$patched_debootstrap"
# shellcheck disable=SC2086
$SUDO $debian_frontend_env "$patched_debootstrap" $args "$DEBIAN_RELEASE" "$sqfs_dir" "$url"
else