-
Notifications
You must be signed in to change notification settings - Fork 29
/
build-iso
executable file
·4150 lines (3419 loc) · 135 KB
/
build-iso
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
#==============================================================================
# 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=$(date +%s)
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 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 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 user_default_file apt_yes
# local initrd_encrypt
local short_stack="aAcCdDefFhiIjmnNpqrsuUvV0-8"
local arg val ARGS
ARGS="$*"
while [[ $# -gt 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
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) [[ $# -lt 1 ]] && fatal "Expected a parameter after: $(pqw -$arg)"
val=$1
[[ $val =~ ^- ]] \
&& fatal "Suspicious argument after -$arg: $(pqw $val)"
shift ;;
-user-default) [ $# -lt 1 ] && fatal "Expected a parameter after: $(pqw -$arg)"
val=$1
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) user_default_file=true ;;
-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 [[ $# -eq 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
if [[ $color_mode != "off" ]]; then
black="\x1B[0;30m"; blue="\x1B[0;34m"; green="\x1B[0;32m";
cyan="\x1B[0;36m"; red="\x1B[0;31m"; purple="\x1B[0;35m";
brown="\x1B[0;33m"; lt_gray="\x1B[0;37m"; dk_gray="\x1B[1;30m";
lt_blue="\x1B[1;34m"; lt_green="\x1B[1;32m"; lt_cyan="\x1B[1;36m";
lt_red="\x1B[1;31m"; magenta="\x1B[1;35m"; yellow="\x1B[1;33m";
white="\x1B[1;37m"; rev_red="\x1B[0;7;31m"; nc="\x1B[0m";
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"
[[ $# -gt 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 -eq 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_default_file ]]; then
local normal_defaults="$user_defaults $input_dir/defaults-local"
local all_defaults="$input_dir/defaults-system $normal_defaults"
fi
load_defaults
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)"
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
for stage in $all_stages; do
output_file=$output_dir/stage-$stage.out
[[ -r $output_file ]] || break
[[ -n $start_from ]] && [[ $stage -eq $start_from ]] && break
source $output_file
done
# 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-$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
local sqfs_input_dir=$sqfs_dir$build_dir/Input
local boot_menu_dir=$sqfs_dir/usr/local/share/boot-menus
local initrd_dir=$work_dir/initrd
local manual_selections_template=$template/COMMON/$manual_selections
local chroot_cache_opts="chroot $work_name $sqfs_dir"
local deboot_cache_opts="debootstrap $ARCH-$DEBIAN_RELEASE $sqfs_dir"
# Do weird modes here after variables are set
[[ -n $chroot_mode ]] && do_chroot && exit
if [[ -n $start_from ]]; then
[[ $stage -lt $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 -ne $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
pick_prog MAKE_ISO $MAKE_ISO_PROGS
pick_prog GZIP $GZIP_PROGS
require_programs chroot debootstrap isohybrid mksquashfs md5sum sudo tee zsync \
pkill column 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
# Fill in default value
: ${RELEASE_DATE:=$(date +"%-e %B %Y")}
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
choose "which locales to enable" ENABLE_LOCALES \
"Default (about 60)" \
"All (about 400)" \
"Single (the one default locale)"
choose "arch" ARCH i386 amd64
choose "flavour" ISO_FLAV $(flavour_list) core-libre
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 ;;
*) error "Invalid ARCH $(pqw $ARCH). Expected $(pqw i386) or $(pqw amd64)". ;;
esac
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/")
local $HOST_ARCH
case $(arch) in
i386|i486|i686) HOST_ARCH=386 ;;
x86_64) HOST_ARCH=x64 ;;
*) error "Cannot detect Host ARCH" ;;
esac
# Detect kernel if using wildcards
# This won't work if host is running a different ARCH
if [[ $K_NAME =~ \* ]]; then
if [[ $ISO_ARCH == "$HOST_ARCH" ]]; then
search_for_k_name || error "Not running on the same ARCH as the build, \
might want to avoid using wildcards for kernels, otherwise you won't be able to start the build at different steps."
fi
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)
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
local dir
for dir in $(flavour_list) COMMON base-AND-full; do
mkdir -p $script_dir/Deb/$dir
done
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"
DEBIAN_RELEASE="$DEBIAN_RELEASE"
FLAV="$FLAV"
GZIP="$GZIP"
ISO_ARCH="$ISO_ARCH"
ISO_FLAV="$ISO_FLAV"
K_NAME="$K_NAME"
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
printf "$pretty_fmt" REMASTER_DIR $remaster_dir
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 "Run debootstrap"
[[ $do_fast ]] && mount_tmpfs
if test -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
if restore_cache $chroot_cache_opts; then
leave_stage
return
fi
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 debootstrap $args $DEBIAN_RELEASE $sqfs_dir $url
end_timer "run debootstrap $ARCH $DEBIAN_RELEASE"
check_errors_lax
##anticapitalista - remove systemd from 4 files in /etc
if is_antiX; then
say "removing systemd from 4 files"
$SUDO sed -i '/^systemd/d' $sqfs_dir/etc/{group,gshadow,passwd,shadow}
say "de-systemd complete"
fi
umount_chroot
[[ -e $sqfs_dir/bin/bash ]] || error "debootstrap failed"
fi
report_size $sqfs_dir
create_cache $deboot_cache_opts
say "Customize live system for antiX"
$SUDO rm -f $sqfs_dir/etc/apt/sources.list
copy_template_dir squashfs $sqfs_dir
leave_stage
}
#------------------------------------------------------------------------------
# Stage 3 prepares for running the chroot command for either a Bash shell or
# for running stage 4 in the chroot. Much of this functionality is repeated
# when the --chroot option is used so we put most of the work in prep_chroot().
#------------------------------------------------------------------------------
do_stage_3() {
enter_stage 3 "Prepare chroot"
check_sqfs_dir
# We want to run stage N+1 inside the chroot so we need to signal
# that the current stage is done
leave_stage notime
# Save the PARTIAL file from destruction but don't be fooled by older copies
rm -f $work_dir/$partial_name
[[ -e $sqfs_dir$partial_file ]] && cp $sqfs_dir$partial_file $work_dir
# Make sure we start over from scratch
$SUDO rm -rf $sqfs_dir$build_dir
prep_chroot
# Put saved PARTIAL file back in the build directory
[[ -e $work_dir/$partial_name ]] \
&& $SUDO mv $work_dir/$partial_name $sqfs_dir$partial_file
# This stage must fail if the next stage fails
rm $output_file
# Get realtime log updates from the chroot
(tail -n 0 -f $sqfs_output_dir/$ME.log >> $log_file) &
export TAIL_PID_1=$!
if [[ -z $no_log_errors ]]; then
touch $err_file
(tail -n 0 -f $err_file > $sqfs_output_dir/$ME.err) &
export TAIL_PID_2=$!
fi
HOST_HOSTNAME=$(hostname)
local args
local next_output_file=$sqfs_output_dir/stage-$((stage + 1)).out
[[ -n $interactive ]] && args="--interactive"
[[ -n $auto_mode ]] && args="$args --auto"
[[ -n $quiet_mode ]] && args="$args --quiet"
[[ -n $ask_errors ]] && args="$args --error-ask"
[[ -n $verbose_mode ]] && args="$args --VERBOSE"
[[ $color_mode != high ]] && args="$args --COLOR=$color_mode"
[[ -n $disable_errors ]] && args="$args --no-error-check"
mountpoint -q $sqfs_dir && args="$args --fast"
check_errors_strict
say "Run $(pq $ME) in chroot"
$SUDO chroot $sqfs_dir $build_dir/$ME $args
$SUDO hostname "$HOST_HOSTNAME"
if [[ ! -e $next_output_file && -n $manual_mode ]]; then
say "The buld inside the chroot failed"
say "======================================================="
say "You are in a chroot environment."
say "Use the command $(pq /Build/$ME $args)"
say "to continue building"
say "Use $(pq exit) or $(pq Ctrl-D) when done"
say "======================================================="
$SUDO chroot $sqfs_dir /bin/bash -rcfile $build_dir/bashrc 2>&1
say "Left chroot"
fi
check_errors_reset
clear_pids
kill_chroot_procs
umount_chroot
[[ -e $next_output_file ]] || fatal "Build inside chroot failed"
local chroot_selections=$sqfs_dir$build_dir/$manual_selections
if [[ -r $chroot_selections ]]; then
say "Update $(pq $manual_selections) in Template"
cp $chroot_selections $manual_selections_template
fi
local missing
for missing in "$sqfs_dir$build_dir"/missing*; do
[[ -r $missing ]] && cp $missing $work_dir
done
cp $sqfs_output_dir/package-list.out $work_dir
cp $sqfs_input_dir/strict-exceptions.regex $input_dir
cp $sqfs_input_dir/lax-errors.regex $input_dir
cp $next_output_file $output_dir
leave_stage
report_size $sqfs_dir
}
#-----------------------------------------------------------------------------
# Stage 4 is the heart of the program. It runs inside the chroot and does most
# of the tasks needed to convert a debootstrap system into antiX. Each part
# inside here can be controled with the ASK_PART, SKIP_PART, etc environment
# variables.
#------------------------------------------------------------------------------
do_stage_4() {
enter_stage 4 "!Inside of chroot"
_say_ "$num_co===============================================================$nc"
#error-logchecking ASAP so we don't waste user's time
[[ "$script_dir" == "$build_dir" ]] || fatal "We do not appear to be in a chroot environment"
[[ -n $K_NAME ]] || error "No K_NAME specified"
if ! [[ -r $manual_selections_template ]]; then
say "No $(pq $manual_selections) file found. Forcing $(pq interactive) mode"
interactive=true
fi
if [[ -n $interactive ]]; then
say "Interactive mode $(pq enabled)"
if [[ -r $manual_selections_template ]] && YES_no_loud "Load current defaults"; then
say "Set defaults from $(pq $manual_selections) file"
debconf-set-selections $manual_selections_template
fi
else
say "interactive mode ${num_co}disabled"
export DEBIAN_FRONTEND=noninteractive
say "Set defaults from $(pq $manual_selections) file"
debconf-set-selections $manual_selections_template
fi
# Doesn't seem to be needed, it just shows an error that /proc/mounts = /etc/mtab
# say "Create $(pq /etc/mtab)"
# grep -v rootfs /proc/mounts > /etc/mtab
echo $$ > $build_dir/MY-PID
say "prepend $(pq $build_dir/fake) to PATH"
PATH=$build_dir/fake:$PATH
# Read in the ASK_PART, SKIP_PART, etc values from outer program
[[ -r $script_dir/ENV_IN ]] && source $script_dir/ENV_IN
require_programs apt-get
if [[ -s $partial_file ]] \
&& do_part 0 "!Read PARTIAL file to skip parts done"; then
local add_skip
add_skip=$(join_lines $partial_file ",")
say "have already processed these parts: $(pq $add_skip)"
if YES_no "Skip these parts this time"; then
SKIP_PART="$SKIP_PART${SKIP_PART:+,}$add_skip"
else
rm -f $partial_file
fi
else
skip_part 0 "Read PARTIAL file to skip parts done"
fi
if ! is_antiX; then
local early_deb
if ls /*${ARCH}.deb >/dev/null 2>&1; then
for early_deb in /*${ARCH}.deb; do
[[ -f $early_deb ]] || continue
say "Install arch deb package $(pq $early_deb)"
apt-get install "$early_deb"; rm "$early_deb"
done
fi
if ls /*all.deb >/dev/null 2>&1; then
for early_deb in /*all.deb; do
say "Install all deb package $(pq $early_deb)"
apt-get install $early_deb; rm $early_deb
done
fi
fi
# for 64 bit set multiarch
if [[ $ARCH = "amd64" ]] ; then
say "Adding multiarch support"
dpkg --add-architecture i386
fi
if do_part 1 "Update repos and do apt-get update"; then
local list_dir=/etc/apt/sources.list.d
# Remove non-free repos from -libre flavours
[[ $ISO_FLAV =~ -libre$ ]] \
&& sed -i -e 's/\<contrib\>//g' -e 's/\<non-free\>//g' $list_dir/debian.list
apt-get $APT_GET_OPTS update
end_part_lax
fi
if [[ $K_NAME =~ \* ]] && do_part 2 "Search for complete kernel name"; then
# Use apt-cache to get full kernel name if it contains a "*"
search_for_k_name
end_part_strict
else
skip_part 2 "Search for complete kernel name"
fi
: ${LOCALE:=en_US.UTF-8}
if do_part 3 "!Define locales"; then
case $ENABLE_LOCALES in
[Aa]ll) say "Will build $(pq all) locales"
sed -i -r "s/^# ([a-z][a-z]([a-z]?_| ISO|\.UTF| UTF))/\1/" /etc/locale.gen;;
[Dd]efault) say "Will build $(pq default) default locales" ;;
[Ss]ingle) say "Will build $(pq "$LOCALE") locale"
local locale_re=${LOCALE//./\.}
sed -i -r -e "s/^([a-z])/# \1/" -e "s/^#\s+($locale_re)/\1/" /etc/locale.gen;;
*) error "Bad ENABLE_LOCALES: $ENABLE_LOCALES"
esac
local cnt
cnt=$(grep -c '^[a-zA-Z]' /etc/locale.gen)
psay $cnt "There %are now $(pqn %n) locale%s to generate"
end_part_lax
fi
if gather_any basic-package \
&& do_part 4 "Install basic packages"; then
install_packages basic-package basic
end_part_lax
else
skip_part 4 "Install basic packages"
fi
if do_part 5 "Install kernel & headers"; then
local kname=linux-image-$K_NAME
! is_antiX && kname=$kname$UNSIGNED
apt-get $APT_GET_OPTS install linux-headers-$K_NAME $kname
end_part_strict
fi
if do_part 6 "Update locales"; then
: ${LOCALE:=en_US.UTF-8}
say "Set default locale to $(pq $LOCALE)"
update-locale LANG=$LOCALE
end_part_lax
fi
if gather_any pesky-package \
&& do_part 7 "Install pesky packages"; then
gather_say pesky-package "Install $(pqn %n) pesky package%s"
for package in $(compile_pkg_list pesky-package exclude-chroot); do
DEBIAN_FRONTEND=dialog apt-get install $apt_yes $package
done
end_part_lax
else
skip_part 7 "Install pesky packages"
fi
if gather_any package \
&& do_part 8 "Install antiX packages"; then
install_packages package $FLAV
end_part_lax
else
skip_part 8 "Install antiX packages"
fi
#say_in $high_co "$(list_newer_procs)"
show_tmpfs_and_mem
if do_part 9 "Run first apt-get -f $apt_yes install"; then
apt-get update && apt-get $APT_GET_OPTS dist-upgrade
apt-get -f install
end_part_lax
fi
local debs cnt
debs=$(ls $build_dir/Deb/*.deb 2>/dev/null)
cnt=$(echo "$debs" | wc -w)
if [[ $cnt -gt 0 ]] \
&& do_part 10 "Install latest antiX debs"; then
psay $cnt "Install $(pqn %n) .deb package%s"
for deb in $debs; do
say "install $(pq ${deb##*/})"
apt-get install $deb
done
end_part_lax
else
skip_part 10 "Install latest antiX debs"
fi
if gather_any remove \
&& do_part 11 "Remove some packages"; then
gather_say remove "Remove $(pqn %n) package%s"