forked from BitJam/live-usb-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-first-lum
More file actions
executable file
·2861 lines (2321 loc) · 104 KB
/
data-first-lum
File metadata and controls
executable file
·2861 lines (2321 loc) · 104 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
#==============================================================================
# live-usb-maker
# A fast and robust program to make full featured antiX/MX live-usbs
#
# (C) 2016 -- 2019 Paul Banham <antiX@operamail.com>
# License: GPLv3 or later
#==============================================================================
VERSION="2.40.10"
VERSION_DATE="Fri Apr 5 20:08:35 MDT 2019"
ME=${0##*/}
MY_DIR=$(dirname "$(readlink -f $0)")
MY_LIB_DIR=$(readlink -f "$MY_DIR/../cli-shell-utils")
LIB_DIR="/usr/local/lib/cli-shell-utils"
export TEXTDOMAIN="cli-shell-utils"
domain_dir="$MY_DIR/../cli-shell-utils/locale"
test -d "$domain_dir" && export TEXTDOMAINDIR=$domain_dir
#== BEGIN_CONFIG
ISO_FILE_DIR="%USER_HOME%"
ISO_FILE_SPEC="*.iso"
SEARCH_DIRS="%USER_HOME% /media /root"
SEARCH_DEPTH="4"
MAX_FILES="20"
MIN_ISO_SIZE="180M"
MSDOS_GPT="msdos"
DEFAULT_SIZE="100%"
CMD_SIZE=""
BIOS_SIZE="150"
UEFI_SIZE="50"
BIOS_MARGIN="20"
MAIN_MARGIN="20"
UEFI_MARGIN="5"
EXT4_OPTIONS="-m0 -i100000 -J size=32"
BIOS_LABEL="Live-usb"
ESP_LABEL="LIVE-UEFI"
LIVE_MP="/live/boot-dev"
LINUXFS_NAME="linuxfs"
MIN_LINUXFS_SIZE="120M"
DEF_BOOT_DIR="antiX"
CLONE_DIRS="boot EFI efi"
CLONE_FILES="cdrom.ico version"
CLONE_BDIR_FILES="{vmlinuz,vmlinuz1,initrd.gz,linuxfs}{,.md5}"
UEFI_FILES="[Ee][Ff][Ii] boot/{grub,uefi-mt} version"
UEFI_2_FILES="[Ee][Ff][Ii] version"
BIOS_FILES="[Ee][Ff][Ii] boot/{syslinux,grub,memtest} antiX/{vmlinuz,initrd}* version"
GRUB_CONF="boot/grub/grub.cfg"
EFI_GRUB_CONF="boot/grub/config/efi-grub.cfg"
DID_EFI_FILE="boot/grub/config/did-efi-grub"
CHEATS=""
COLOR_SCHEME="high"
QUESTION_MODE="default"
ENCRYPT=""
PASS_PHRASE_TYPE=""
LUKS_NAME="live-usb-maker"
EXT_OVERHEAD_FORM="* 26 / 10000 - 2"
EXT_OVERHEAD_MAX="44"
PP_MAX_WORD_LEN="8"
PP_NUM_WORDS="6"
PP_WORDS_FILE="/usr/share/dict/american-english"
PP_RAND_SOURCE="/dev/urandom"
GRAPHICAL_MENUS="true"
AUTOMOUNT_DELAY="2"
#== END_CONFIG
MAIN_FS_TYPE="ext4"
UEFI_FS_TYPE="vfat"
CP_ARGS="--no-dereference --preserve=mode,links --recursive"
BACKUP_WORDS_FILE="/usr/share/dict/words"
CRYPT_PROGS="cryptsetup dmsetup"
PHRASE_FNAME="passphrase"
SEED_FNAME="random-seed"
ENCRYPT_FNAME="encrypted"
ENCRYPT_ENABLE="enable"
WORK_DIR="/run/$ME"
SHELL_LIB="cli-shell-utils.bash"
CONFIG_FILE="/root/.config/$ME/$ME.conf"
THE_LOG_FILE="/var/log/$ME.log"
THE_ERR_FILE="/var/log/$ME.error"
THE_PROG_FILE="/var/log/$ME.progress"
LOG_FILE="/dev/null"
ERR_FILE="/dev/null"
PROG_FILE="/dev/null"
EXT4_NO_64BIT="-O ^64bit"
ORDERED_CMDS="partition-clear partition-make makefs-data makefs-main makefs-bios makefs-uefi"
ORDERED_CMDS="$ORDERED_CMDS copy-main check-usb-md5 copy-bios copy-uefi uuids"
ORDERED_CMDS="$ORDERED_CMDS cheats cheats-syslinux cheats-grub install encrypt-main encryption-initrd"
ALL_CMDS="sizes all partition makefs copy cheats $ORDERED_CMDS"
ALL_FORCE="automount,flock,makefs,ultra-fit,usb,nofuse,fuse,uuids,nomd5,debug-copy"
ALL_PAUSE="exit,initrd,copy,uuids"
LIB_PATH="$MY_LIB_DIR:$LIB_DIR"
PATH="$MY_LIB_DIR/bin:$LIB_DIR/bin:$PATH"
MADE_BY_FILE="made-by-live-usb-maker"
USB_FORMAT_LIST="vfat exfat ntfs ext4"
SYSLINUX_FILES="chain.c32 gfxboot.c32 vesamenu.c32 ldlinux.c32 libcom32.c32"
SYSLINUX_FILES="$SYSLINUX_FILES libmenu.c32 libutil.c32 linux.c32 menu.c32"
SYSLINUX_RM="*.c32 ldlinux.sys syslinux.bin isolinux.bin version"
SWEARS="asshole|bastard|bitch|cock|crap|cunt|damn|dick|douche|fag|fuck|piss|pussy|shit|slut"
#------------------------------------------------------------------------------
# Show usage and exit
#------------------------------------------------------------------------------
usage() {
local ret=${1:-0}
cat<<Usage
Usage: $ME [<options>] [default|expert|simple|gui]
Create a live-usb from an iso-file, another live-usb, a live-cd/dvd
or a running live system. You will be prompted for information that
is not supplied in the command line options.
default: default "no" to some questions.
expert: default "yes" to some questions.
simple: skip some questions
gui: non-interactive, disable progress bar, enable progress file
Uses ext4 as the filesystem for the main live-usb partition and adds
a small fat32 file system for booting via UEFI.
This will destroy any existing information on <usb-device>. The default
partitioning scheme is msdos (due to a bug in some Dell BIOSes). Use
the --gpt flag to use gpt partitioning instead.
--from="iso-file" Enter an iso file to use as the source
--from="clone" clone a running live system.
--from=clone=<dir> clone from a mounted live-usb or iso-file.
--from=<dev> copy from a livecd/dvd or live-usb
Options:
-b --bios-size=<xx> Size of BIOS boot partition when using encryption
-c --cheat=xxx Add these cheatcodes to the live-usb
Use "off" or "no" to disable cheats menu.
Use "on" or "yes" to show cheat menus without asking
Otherwise you will be asked.
--clone-persist Clone persistence files
--clone-persist=<p> or pass a parameter: h,home: clone home
r,root: clone root
-C --color=<xxx> Set color scheme to off|low|low2|bw|dark|high
-E --encrypt Set up to boot from an encrypted partition
--encrypt=<flag> Phasephrase option:
ask Enter the passphrase via the keyboard
first-boot Force user to set phrase on first boot
file=xxx Read phrase from file <xxx>
random Generate a random passphrase
random=N Generate a random passhphrase containing
N words (1 -- 20 allowed)
-e --esp-size=<xx> Size of ESP (uefi) partition in MiB (default 50)
--ext-options=<xx> Use these options when creating the ext4 filesystem
--data-first Place a data partition first on the live-usb
--data-first=<str> Specify the file system and or the size (in percent)
--format Make a data usb formatted to fat32 by default
--format=<fs> Make a data usb formated to the give filesystem
-f --from=<xxx> The device, cdrom, or file to make the live-usb from
Use "clone" to clone the current live system or use
clone=<xxx> to clone another live-usb
-F --force=<xxx> Force the options specfied:
usb: Ignore usb/removable check
nomd5: Don't check md5 of files copied to live-usb
ultra-fit: don't warn about SanDisk utra-fit devices
makefs: Make the ext4 filesystem even if one exists
automount: don't temporarily disable antiX automounting
nofuse: don't use fuseiso to mount iso files
fuse: only use fuseiso to mount iso files
-- --gui-progress All remaining args are used as a gui progress bar program
Example: --gui-progress yad --progress --auto-close
-g --gpt Use gpt partitioning instead of msdos
-G --graphic-ui Use the new graphics user interface (default)
--gpt-pmbr Set pmbr_boot disk flag (prevents booting via UEFI)
-h --help Show this usage
-i --initrd=<file> Update the initrd from using a template-initrd.gz
-I --ignore-config Ignore the configuration file
-k --keep-syslinux Don't replace the syslinux files
-L --label=Name Label ext partition with Name
-m --msdos Use msdos partitioning (default) instead of gpt
-n --no-prog-bar Don't show progress *bar* when copying
--no-clone-persist Don't clone persistence files even if they exist
--no-clone-persist=<p> Or pass a parameter: h,home: don't clone home
r,root: don't clone root
-N --numeric-ui Use the legacy numerical user interface
--pause Wait for user input before exit
--pause=initrd Pause after unpacking the initrd.gz file
--percent-prog Show progress percentage but no bar
-p --pretend Don't run commands that affect the usb device
-P --progress Create $THE_PROG_FILE progress *file*
-q --quiet Print less
-R --reset-config Write a fresh config file with default options
-s --size=XX Percent of usb-device to use (default 100)
-S --save-boot Save original boot directory when updating a live-usb
-t --target=<xxx> The device to make into a new live-usb
-u --update Only update an existing live-usb
-v --version Show version information
-V --verbose Print more, show command outputs
-VV --very-verbose Also show commands
-W --write-config Write a config file preserving current options
Notes:
- short options stack. Example: -pv is the same as --pretend --verbose
- options can be intermingled with commands and parameters
- config file: $CONFIG_FILE
- the config file will be sourced if it exists
- it will be created if it doesn't exist
Usage
exit $ret
}
#------------------------------------------------------------------------------
# Callback routine to evalute some command line args before the root user test.
#------------------------------------------------------------------------------
eval_early_argument() {
local val=${1#*=}
case $1 in
-ignore-config|I) IGNORE_CONFIG=true ;;
-write-config|W) WRITE_CONFIG=true ;;
-reset-config|R) RESET_CONFIG=true ;;
-gpt|-gpt-pmbr) CMD_GPT=true ;;
-force|F) FORCE="$FORCE,$val" ;;
-force=*) FORCE="$FORCE,$val" ;;
-progress|P) PROGRESS=true ;;
-pause) PAUSE="$PAUSE${PAUSE:+,}exit" ;;
-help|h) usage ;;
-version|v) show_version ;;
esac
}
#------------------------------------------------------------------------------
# Callback routine to evaluate arguments after the root user check. We also
# need to include the early args to avoid unknown argument errors.
#------------------------------------------------------------------------------
eval_argument() {
local arg=$1 val=$2
case $arg in
-bios-size|b) BIOS_SIZE=$val ;;
-bios-size=*) BIOS_SIZE=$val ;;
-cheat|c) CHEATS="$CHEATS${CHEATS:+ }$val" ;;
-cheat=*) CHEATS="$CHEATS${CHEATS:+ }$val" ;;
-clone-persist) CLONE_PERSIST=home,root ;;
-clone-persist=*) CLONE_PERSIST=$val ;;
-color|C) COLOR_SCHEME=$val ;;
-color=*) COLOR_SCHEME=$val ;;
-encrypt|E) ENCRYPT=true ;;
-encrypt=*) ENCRYPT=true
PASS_PHRASE_TYPE=$val ;;
-esp-size|e) UEFI_SIZE=$val ;;
-ext-options) EXT4_OPTIONS=$val ;;
-ext-options=*) EXT4_OPTIONS=$val ;;
-esp-size=*) UEFI_SIZE=$val ;;
-data-first) DATA_FIRST=fat32 ;;
-data-first=*) DATA_FIRST=$val ;;
-format) FORMAT_USB=true ;;
-format=*) FORMAT_USB=true; USB_FORMAT=$val ;;
-from|f) FROM=$val ;;
-from=*) FROM=$val ;;
--graphic-ui|G) GRAPHICAL_MENUS=true ;;
-gpt|g) MSDOS_GPT="gpt" ;;
-gpt-pmbr) MSDOS_GPT="gpt" ; DO_PMBR=true ;;
-gui-progress|-) END_CMDLINE=true ;;
-initrd|i) INITRD_FILE=$val ;;
-initrd=*) INITRD_FILE=$val ;;
-keep-syslinux|k) KEEP_SYSLINUX=true ;;
-label|L) BIOS_LABEL=$val ;;
-label=*) BIOS_LABEL=$val ;;
-msdos|m) MSDOS_GPT="msdos" ;;
-no-prog-bar|n) NO_PROGRESS_BAR=true ;;
-no-clone-persist) NO_CLONE_PERSIST=home,root ;;
-no-clone-persist=*) NO_CLONE_PERSIST=$val ;;
-pause) PAUSE="$PAUSE${PAUSE:+,}exit" ;;
-numeric-ui|N) GRAPHICAL_MENUS= ;;
-pause=*) PAUSE="$PAUSE${PAUSE:+,}$val" ;;
-percent-prog) PERCENT_PROG=true ;;
-pretend|p) PRETEND_MODE=true ;;
-progress|P) PROGRESS=true ;;
-quiet|q) QUIET=true ;;
-size|s) CMD_SIZE=${val%\%} ;;
-save-boot|S) SAVE_BOOT=true
KEEP_SYSLINUX=true ;;
-size=*) CMD_SIZE=${val%\%} ;;
-target|t) TARGET=$val ;;
-target=*) TARGET=$val ;;
-update|u) CMD_CMDS="$CMD_CMDS${CMD_CMDS:+ }copy-main check-usb-md5"
SAVE_BOOT=true
KEEP_SYSLINUX=true ;;
-verbose|V) VERBOSITY=$((VERBOSITY + 1)) ;;
-very-verbose) VERBOSITY=$((VERBOSITY + 2)) ;;
# These are read early. They are not unknown
-force|F) ;;
-force=*) ;;
-ignore-config|I) ;;
-reset-config|R) ;;
-write-config|W) ;;
*) fatal "Unknown parameter %s" "-$arg" ;;
esac
}
#------------------------------------------------------------------------------
# Callback routine for command line arguments that don't start with "-"
#------------------------------------------------------------------------------
assign_parameter() {
local cnt=$1 param=$2
case $param in
default) QUESTION_MODE=default ;;
expert) QUESTION_MODE=expert ;;
simple) QUESTION_MODE=simple ;;
gui) QUESTION_MODE=gui ;;
*) CMD_CMDS="$CMD_CMDS${CMD_CMDS:+ }$param" ;;
esac
}
#------------------------------------------------------------------------------
# Callback routine to see if an argument requires a value to follow it.
#------------------------------------------------------------------------------
takes_param() {
case $1 in
-bios-size|b) return 0 ;;
-cheat|c) return 0 ;;
-color|C) return 0 ;;
-esp-size|e) return 0 ;;
-from|f) return 0 ;;
-force|F) return 0 ;;
-initrd|i) return 0 ;;
-label|L) return 0 ;;
-size|s) return 0 ;;
-target|t) return 0 ;;
esac
return 1
}
#------------------------------------------------------------------------------
# The main routine. Called from the very bottom of this script.
#------------------------------------------------------------------------------
main() {
local SHIFT SHIFT_2 SHORT_STACK="bcCDeEfFgGhIkLmnNpPqRsStuvVW"
local BE_VERBOSE FROM TARGET FATAL_QUESTION CMD PARAM_CNT ENCRYPT
local CLONE_PERSIST NO_CLONE_PERSIST CLONE_HOME NO_CLONE_HOME
local CLONE_ROOT NO_CLONE_ROOT NO_PROGRESS_BAR TOTAL_SIZE
local FORMAT_USB USB_FORMAT USING_GRUB_CONFIG_2
local VERY_VERBOSE VERBOSITY=0
local ISO_BOOT_DIR START_T=0
set_colors
local orig_args="$*"
# Let non-root users get usage. Need to get --ignore-config early.
read_early_params "$@"
force fuse && force nofuse && fatal "Cannot force both %s and %s" "$(pqw fuse)" "$(pqw nofuse)"
need_root
EXIT_NUM=100
read_reset_config_file "$CONFIG_FILE"
# Strip off leading / once and for all
DEF_BOOT_DIR="${DEF_BOOT_DIR#/}"
# Force stored 'gpt' value back to msdos. Can still be overridden by the
# --gpt command line parameter
if [ -z "$CMD_GPT" -a "$MSDOS_GPT" != 'msdos' ]; then
warn "Forcing partitioning to be %s" "$(pqh msdos)"
MSDOS_GPT=msdos
write_config "$CONFIG_FILE"
fi
ERR_FILE=$THE_ERR_FILE
trap clean_up EXIT
do_flock
test -f $ERR_FILE && rm -f $ERR_FILE
read_all_cmdline_mingled "$@"
set_colors $COLOR_SCHEME
validate_data_first CMD_SIZE "$DATA_FIRST"
validate_clone_persist "$CLONE_PERSIST" "$NO_CLONE_PERSIST"
# Simple sanity check
[ -n "$FORMAT_USB" -a -n "$CMD_CMDS" ] && fatal "Cannot combine %s with any commands" "--format"
[ -n "$INITRD_FILE" -a -n "$CMD_CMDS" ] && fatal "Cannot combine %s with any commands" "--initrd"
[ -n "$FORMAT_USB" -a -n "$INITRD_FILE" ] && fatal "Cannot combine %s with %s" "--format" "--initrd"
validate_fs_type "$USB_FORMAT"
case $VERBOSITY in
0) ;;
1) BE_VERBOSE=true ;;
*) BE_VERBOSE=true ; VERY_VERBOSE=true ;;
esac
[ -n "$BE_VERBOSE" -a -n "$PRETEND_MODE" ] && VERY_VERBOSE=true
CMDS=${CMD_CMDS:-all}
# Let the gui take care of filtering out ultra-fit devices
q_mode gui && FORCE="$FORCE,ultra-fit"
check_cmds CMDS "$ALL_CMDS" "$ORDERED_CMDS"
check_force FORCE "$ALL_FORCE"
check_pause PAUSE "$ALL_PAUSE"
if [ "$FORMAT_USB" ]; then
CMDS='format-usb'
CMD_CMDS="$CMDS"
elif [ "$INITRD_FILE" ]; then
CMDS='update-initrd'
CMD_CMDS="$CMDS"
test -e "$INITRD_FILE" || fatal "Could not find initrd file %s" "$(pqw $INITRD_FILE)"
test -r "$INITRD_FILE" || fatal "Could not read initrd file %s" "$(pqw $INITRD_FILE)"
fi
local percent_size=${CMD_SIZE%%%}
case $percent_size in
"") ;;
[1-9]|[0-9][0-9]|100) ;;
*) fatal "Wrong percentage value '%s'. Should be between %s and %s inclusive." "$(pqh $percent_size)" "1%" "100%"
esac
[ -z "${UEFI_SIZE##[0-9]}" ] && fatal "esp-size must be larger than %s" 9
echo $UEFI_SIZE | egrep -q "^[1-9][0-9]+$" || fatal "esp-size must be an integer larger than %s" 9
# Always write a new config file and then exit if requested
[ "$WRITE_CONFIG" ] && write_config "$CONFIG_FILE" && exit 0
need_prog extlinux
q_mode gui && PROGRESS=true
[ "$PROGRESS" ] && PROG_FILE=$THE_PROG_FILE
# Make sure we have a --from (if needed) and a --target
if q_mode gui; then
case $CMDS in
partition-clear) ;;
format-usb) ;;
update-initrd) ;;
*) fatal_z "$FROM" "No --from was given while in %s mode" gui ;;
esac
fatal_z "$TARGET" "No --target was given while in %s mode" gui
fi
shout_title $"Starting %s" "$ME"
set_window_title "$ME"
start_log "$THE_LOG_FILE" "$orig_args"
# NOTE: this placement is not ideal because it allows the user to
# write an invalid pass_phrase_type to the config file
#======== Encryption =====================================================
if encrypt; then
q_mode gui && : ${PASS_PHRASE_TYPE:=first-boot}
validate_passphrase_type "$PASS_PHRASE_TYPE"
fi
#=========================================================================
type -t find_man_page &>/dev/null && find_man_page
shift $SHIFT_2
if [ $# -gt 0 ]; then
type "$1" &>/dev/null || fatal "Could not find progress program %s" "$(pqh $1)"
printf "Will use progress %s: $*\n" "$(my_type $1)" >> $LOG_FILE
fi
shout_pretend
mkdir -p $WORK_DIR || fatal "Could not make a work directory under %s" "$(dirname "$WORK_DIR")"
mount -t tmpfs tmpfs $WORK_DIR || fatal "Could not mount tmpfs at %s" $WORK_DIR
# Set up our directories. These a GLOBALS so they can be used in clean_up() on exit
ISO_DIR=$WORK_DIR/iso
BIOS_DIR=$WORK_DIR/bios
MAIN_DIR=$WORK_DIR/main
UEFI_DIR=$WORK_DIR/uefi
DATA_DIR=$WORK_DIR/data
INITRD_DIR=$WORK_DIR/initrd
LINUX_DIR=$WORK_DIR/linux
MNT_DIR=$WORK_DIR/live-dev
WORDS_FILE=$WORK_DIR/words
mkdir $ISO_DIR $BIOS_DIR $MAIN_DIR $UEFI_DIR || fatal "Could not make %s subdirectories" "$WORK_DIR"
echo $$ > $WORK_DIR/pid
#--- Find live boot device if we are running live
local we_are_live live_dev
if its_alive; then
we_are_live=true
# FIXME: should use initrd.out to get the uuid, etc
live_dev=$(get_live_dev)
if [ -n "$live_dev" ]; then
shout $"Found live media device %s" "$(pqb /dev/$(get_drive $live_dev))"
else
# Don't error out on systems running toram, just inform
msg $"The live media is not mounted"
fi
fi
# Check cmdline target *before* the first menu
if [ ${#TARGET} -eq 0 ]; then
select_target_device TARGET "$live_dev" "$FROM"
else
check_target "$TARGET" "$live_dev"
fi
if ! force ultra-fit && is_ultra_fit_dev $TARGET; then
warn $"The selected usb drive was %s" "$(pqw $SANDISK_ULTRA_FIT)"
warn $"This device is known to cause errors during creation and boot"
yes_NO $"Do you want to use it anyway?" || exit
fi
msg $"Will use target device %s" "$(pq "$TARGET ($(device_info $TARGET))")"
local target_dev=$(expand_device $TARGET)
# Make sure our target is a real device
[ ${#target_dev} -gt 0 ] || fatal $"Could not find device %s" "$TARGET"
TOTAL_SIZE=$(get_total_size "$target_dev")
[ ${#CMD_CMDS} -eq 0 ] && ! q_mode simple gui && select_overall_mode CMDS QUESTION_MODE
if need_q copy && ! encrypt; then
expert_yes_NO $"Create an encrypted live-usb?" && ENCRYPT=true
fi
# FIXME: better error messsage!!
encrypt && need_prog copy-initrd-programs unpack-initrd cryptsetup dmsetup
local from
if [ ${#FROM} -gt 0 ]; then
check_from from "$FROM" "$TARGET"
elif ! need_q 'copy-main|copy-bios|copy-uefi'; then
from='null=null'
else
#--- Select source of live-usb if one was not given
select_usb_src from "$TARGET"
fi
local from_file from_act=$"copying"
case $from in
iso-file|iso|file)
cli_get_filename from_file $"Please enter the filename" "$ISO_FILE_DIR"
from=file=$from_file ;;
clone)
#
from=clone=$LIVE_MP ;;
dev=*|clone=*|file=*) ;;
null=*) ;;
*) test -f "$from" && from=file=$from ;;
esac
[ -n "$from" -a -n "${from%%*=*}" ] && internal_error "bad from value 1 " "$from"
local from_type=${from%%=*}
local from_value=${from#*=}
# The $from variable must be type=value as seen below. This is more
# Complicated but it makes it easier to report to user what is going on
local from_dev from_thing
case $from_type in
file)
mount_iso_file "$from_value" "$ISO_DIR"
check_md5 "$from_value"
# What thing we are copying or cloning from: file, device or directory
from_thing=$"file"
;;
dev)
mount_device "$from_value" "$ISO_DIR" 'from'
# What thing we are copying or cloning from: file, device or directory
from_thing=$"device"
;;
clone)
# First see if we were given a block device to clone
local from_dev=$(expand_device "$from_value")
# Cloning only copies certain files to make a brand-new live-usb
from_act=$"cloning"
# Just clone the directory instead if the device is already mounted
if is_mounted "$from_dev"; then
from_value=$(grep "^$from_dev " /proc/mounts | cut -d" " -f2 | head -n1)
msg "Will try cloning directory %s" "$(pq "$from_value")"
from_dev=
fi
if [ ${#from_dev} -gt 0 ]; then
mount_device "$from_dev" "$MNT_DIR" 'from'
clone_directory "$MNT_DIR" "$ISO_DIR" "$live_dev"
# What thing we are copying or cloning from: file, device or directory
from_thing=$"device"
elif test -d "$from_value"; then
clone_directory "$from_value" "$ISO_DIR" "$live_dev"
# What thing we are copying or cloning from: file, device or directory
from_thing=$"directory"
else
fatal "Can only clone devices and directories, not '%s" "$from_value"
fi
;;
null) ;;
*)
internal_error "Bad from variable 2" "$from"
;;
esac
# Will use source <file XYZ>
msg $"Will use source %s" "$from_thing $(pq $from_value)"
show_distro_version "$ISO_DIR" # "$from_value"
if test -e $ISO_DIR/$EFI_GRUB_CONF; then
msg "Found grub config %s" "$(pq 2.0)"
USING_GRUB_CONFIG_2=true
elif test -e $ISO_DIR/$GRUB_CONF; then
msg "Found grub config %s" "$(pq 1.0)"
fi
local distro_name=$(get_distro_name "$ISO_DIR/version")
if [ -n "$distro_name" ]; then
BIOS_LABEL=$(make_label 16 - "$distro_name" Live usb)
ESP_LABEL=$(make_label 11 - "$distro_name" uefi)
fi
local cheats
if need_q cheats; then
case $CHEATS in
"") expert_YES_no $"Customize language and timezone?" && cheats_menus cheats ;;
off|no) ;;
yes|on) cheats_menus cheats ;;
*) cheats=$CHEATS ;;
esac
fi
# These are mostly for a manually entered target
test -e $target_dev || fatal "Target device %s does not exist" $target_dev
test -b $target_dev || fatal "Target device %s is not a block device" $target_dev
# Require that an entire disk device be specified (could relax?)
local dev_type=$(lsblk -no type --nodeps $target_dev)
[ "$dev_type" = 'disk' ] || fatal "Device %s is not a disk device" $target_dev
setup_devices $target_dev
# fatal "The device %s does not seem to be usb or removable."
# FIXME: move this to the lib?
force usb || is_usb_or_removable $target_dev \
|| yes_NO_fatal "usb" \
"Do you want to use it anyway (dangerous)?" \
"Use %s to always ignore this warning" \
"The device %s does not seem to be usb or removeable." "$target_dev"
local bios_size main_size uefi_size
encrypt && shout "\n%s" $"Encryption enabled"
need_q partition-make && verify_sizes bios_size main_size uefi_size "$target_dev" \
"$ISO_DIR" "$percent_size" "$BIOS_SIZE" "$UEFI_SIZE" "${DEFAULT_SIZE%%%}"
[ ${#cheats} -gt 0 ] && msg "Cheats: %s" "$(pq $cheats)"
# Bail early if only size info is requested
given_cmd sizes && my_exit 0
# Make sure the target is not in use
umount_all $target_dev
local encrypted_lab=""
#======== Encryption =====================================================
encrypt && echo
if encrypt && need encryption-initrd; then
encrypted_lab="$(bqq $"encrypted") "
msg "Checking to see if the live media will support encryption ..."
# Need to get programs, libs, and modules, out of the linuxfs file (sigh)
local linuxfs_full=$ISO_DIR/$DEF_BOOT_DIR/$LINUXFS_NAME
my_mount "$linuxfs_full" "$LINUX_DIR" -t squashfs -o loop,ro
local initrd_file=$ISO_DIR/$DEF_BOOT_DIR/initrd.gz
start_initrd_encryption "$initrd_file" "$INITRD_DIR" "$LINUX_DIR"
pause initrd
umount $LINUX_DIR ; rmdir $LINUX_DIR
# FIXME: mount initrd, check init, mount linuxfs and check for cryptsetup
test -r "$PP_WORDS_FILE" || PP_WORDS_FILE=$BACKUP_WORDS_FILE
select_passphrase_type PASS_PHRASE_TYPE
fi
# FIXME: add sanity checks for "uuids" and for update-initrd
if [ -n "$FORMAT_USB" ]; then
q_mode gui && : ${USB_FORMAT:=vfat}
makefs_select USB_FORMAT
msg "Will create a %s filesystem" "$(pq $USB_FORMAT)"
elif [ -n "$INITRD_FILE" ]; then
msg "Will update the initrd from file %s" "$(pq $INITRD_FILE)"
fi
#=========================================================================
local new_line=$(printf "$nc_co\n$bold_co...")
# Ready to make live-usb on device X by <cloning|copying directory Y>
local final_q=$(printf $"Ready to make %s on device %s by %s" "${encrypted_lab}$(pqb live-usb)" \
"$(pqb ${target_dev##*/})$new_line" "$from_act $from_thing $(pqb $from_value)")
local ready_str=$"Ready to perform %s action on %s"
[ -z "${CMDS##* *}" ] && ready_str=$"Ready to perform %s actions on %s"
[ "$CMDS" != 'all' ] \
&& final_q=$(printf "$ready_str" "$(pq $CMDS)" "$(pqq ${target_dev##*/})")
if q_mode gui; then
msg "$final_q"
else
echo
shout_subtitle "$final_q"
#final_q=$(printf "%s\n%s" "$final_q" "$(quest $"Shall we begin?")")
YES_no_pretend $"Shall we begin?" || my_exit
fi
[ -n "$BE_VERBOSE" -a -n "$PRETEND_MODE" ] && VERY_VERBOSE=true
# Add last lines of dmesg output to log file on fatal errors
ADD_DMESG_TO_FATAL=true
force automount || suspend_automount
START_T=$(date +%s)
if [ "$FORMAT_USB" ]; then
format_usb "$target_dev" "$MSDOS_GPT" "$USB_FORMAT"
say_done
my_exit 0
fi
need partition-clear && clear_partition "$target_dev"
need partition-make && do_partition "$target_dev" "$MSDOS_GPT" "$bios_size" "$main_size" "$uefi_size"
# msg "Unmount new partitions if needed ..."
#msg $"Wait for automounting ..."
sync; sync
#sleep ${AUTOMOUNT_DELAY:-1}
# Make sure the new target partitions get unmounted if they were auto-mounted
umount_all $target_dev
# Nothing else makes sense if there is no partition table
need_q partition-clear && ! need_q partition-make && exit_done
if [ "$DATA_FIRST_FS" ] && need makefs-data; then
cmd wait_for_file "$DATA_DEV"
make_fs_dev "$DATA_DEV" "$DATA_FIRST_FS" "USB-DATA"
fi
cmd wait_for_file "$BIOS_DEV"
need makefs-bios && do_makefs_ext "$BIOS_DEV" "$EXT4_OPTIONS" "$BIOS_LABEL"
cmd wait_for_file "$UEFI_DEV"
need makefs-uefi && do_makefs_uefi "$UEFI_DEV" "$ESP_LABEL"
#======== Encryption =====================================================
if encrypt && need encrypt-main; then
wait_for_file "$MAIN_DEV"
# Write phrase and signal file *before* encrypting
my_mount $BIOS_DEV $BIOS_DIR -t $MAIN_FS_TYPE
local phrase_file=$BIOS_DIR/$DEF_BOOT_DIR/$PHRASE_FNAME
local encrypt_file=$BIOS_DIR/$DEF_BOOT_DIR/$ENCRYPT_FNAME
# Simplify to types: ask, file, phrase
# Convert file to phrase to avoid problems with \n
local phrase=$PASS_PHRASE_TYPE
case $phrase in
ask) ;;
phrase=*) ;;
file=*) phrase=phrase=$(cat "$val") ;;
random) set_rand_phrase phrase ;;
random=*) set_rand_phrase phrase ${phrase#*=} ;;
first-boot) first_boot_phrase phrase "$phrase_file" ;;
*) internal_error "passphrase type" "$phrase" ;;
esac
encrypt_partition $MAIN_DEV "$LUKS_NAME" "$phrase"
if [ "$DATA_FIRST" ]; then
need makefs-data && do_makefs_ext
fi
need makefs-main && do_makefs_ext "$LUKS_DEV" "$EXT4_OPTIONS" "$BIOS_LABEL"
local main_uuid=$(lsblk --nodeps -no uuid $MAIN_DEV)
cmd write_file $encrypt_file "$main_uuid"
sync
DID_ENCRYPT=true
always_cmd umount $BIOS_DEV
my_mount "$LUKS_DEV" "$MAIN_DIR" -t $MAIN_FS_TYPE
fi
#=========================================================================
[ -z "$DID_PARTITION" ] && guess_partitioning $target_dev
sync; sync
# Tell OS partitioning has changed (after we've created the new file systems)
cmd partprobe $target_dev
my_mount $BIOS_DEV $BIOS_DIR -t $MAIN_FS_TYPE
my_mount $UEFI_DEV $UEFI_DIR -t $UEFI_FS_TYPE
data_first && my_mount $DATA_DEV $DATA_DIR -t $DATA_FIRST_FS
local mp_list="$BIOS_DIR $UEFI_DIR"
encrypt && mp_list="$BIOS_DIR $MAIN_DIR $UEFI_DIR"
data_first && mp_list="$DATA_DIR $mp_list"
display_df_output $mp_list
if [ "$INITRD_FILE" ]; then
update_initrd "$MAIN_DIR" "$INITRD_FILE"
say_done
my_exit 0
fi
#======== Encryption =====================================================
if encrypt && need copy-bios; then
copy_files_spec $ISO_DIR "$BIOS_FILES" "$BIOS_DIR" bios
#need encryption-initrd &&
finish_initrd_encryption "$INITRD_DIR" "$BIOS_DIR/$DEF_BOOT_DIR/initrd.gz"
fi
#=========================================================================
if need copy-uefi; then
if using_grub_config_2; then
copy_files_spec $ISO_DIR "$UEFI_2_FILES" "$UEFI_DIR" uefi
else
copy_files_spec $ISO_DIR "$UEFI_FILES" "$UEFI_DIR" uefi
fi
fix_uefi_memtest $UEFI_DIR
fi
if need copy-main; then
do_copy_main $ISO_DIR $MAIN_DIR "$@"
do_made_by $BIOS_DIR "$MADE_BY_FILE"
write_random_seed $MAIN_DIR/$DEF_BOOT_DIR/$SEED_FNAME
test -e "$MAIN_DIR/.disk" && cmd rm -rf "$MAIN_DIR/.disk"
fi
! force nomd5 && have_usb_md5 "$MAIN_DIR" && need check-usb-md5 && check_usb_md5 "$MAIN_DIR"
#need defrag && do_defrag "$MAIN_DIR" "$DEFRAG_ALL"
# if need_q copy-bios || need_q copy-main; then
# : ${ISO_BOOT_DIR:=$DEF_BOOT_DIR}
# local initrd_file=${INITRD_FILE:-$ISO_DIR/$ISO_BOOT_DIR/initrd.gz}
# enable_disable_initrd_encryption "$initrd_file" "$BIOS_DIR/$DEF_BOOT_DIR/initrd.gz" "$INITRD_DIR"
# fi
local bios_uuid=$(lsblk -no uuid $BIOS_DEV)
local uefi_uuid=$(lsblk -no uuid $UEFI_DEV)
local main_dir
encrypt && main_dir=$MAIN_DIR
if need uuids; then
do_uuids "$BIOS_DIR" "$bios_uuid" "$UEFI_DIR/$GRUB_CONF" "$uefi_uuid" "$UEFI_PART" "$main_dir"
data_first_uuid "$BIOS_DIR" "$DATA_DEV"
fi
[ ${#cheats} -gt 0 ] && need cheats-syslinux && do_cheats_syslinux $BIOS_DIR "$cheats"
[ ${#cheats} -gt 0 ] && need cheats-grub && do_cheats_grub $UEFI_DIR "$cheats"
need install $"install" && do_install_bootloader $target_dev $BIOS_DIR $MSDOS_GPT
sync; sync
need_q copy && display_df_output $mp_list
say_done
[ -n "$FIRST_BOOT_PHRASE" ] && shout $"You will be asked to create a passphrase during the first boot"
my_exit 0
}
#===== End of Main ============================================================
#------------------------------------------------------------------------------
# Validate --from parameter give on command line
#------------------------------------------------------------------------------
check_from() {
local var=$1 cmd_from=$2 exclude=$3
case $cmd_from in
iso|file|iso-file) eval $var=\$cmd_from ; return 0 ;;
clone|clone=*) eval $var=\$cmd_from ; return 0 ;;
esac
local from_dev=$(expand_device "$cmd_from")
if [ ${#from_dev} -gt 0 ]; then
eval "$var=dev=\$from_dev"
return 0
elif test -f "$cmd_from"; then
eval "$var=file=\$cmd_from"
return 0
elif test -d "$cmd_from"; then
eval "$var=clone=\$cmd_from"
return 0
else
fatal "The --from parameter '%s' was not recognized" "$cmd_from"
fi
}
#------------------------------------------------------------------------------
# Offer several passphrases. Let user pick one of them or enter their own
# or force the passphrase to be created on first boot of live-usb
#------------------------------------------------------------------------------
select_passphrase_type() {
local var=$1 val
eval val=\$$var
# Only select a pp type if one was not already given
[ -n "$val" ] && return
shout
local have_words dict_size=0 dict_bits=0
test -r $PP_WORDS_FILE && dict_size=$(dict_size)
if [ $dict_size -eq 0 ]; then
warn "no words were found in the dictionary"
warn "Will not generate passphrases"
elif [ $dict_size -lt 5000 ]; then
warn "only %s words were found in the dictionary" "$(nqh $dict_size)"
warn "Will not generate passphrases"
else
dict_bits=$(x1 "log($dict_size)/log(2)")
have_words=true
fi
# Don't let these menu entries get into the log file
local VERBOSE_SELECT=
local phrase phrase_2 phrase_3 phrase_4 phrase_5 phrase_6
local bits bits_2 bits_3 bits_4 bits_5 bits_6
# Repeat if user wants to see more passphrases
while true; do
local i len=4 max_len=8 seq=
if [ "$have_words" ]; then
shout "Please wait while some random passphrases are generated"
msg "Dictionary size is %s words (%s bits/word)" \
"$(nq $(add_commas $dict_size))" "$(nq $dict_bits)" | color_commas
seq=$(seq 2 6)
fi
for i in $seq; do
phrase=$(gen_passphrase $len)
eval phrase_$i=\$phrase
bits=$(x1 "log($dict_size)/log(2) * $len")