forked from Difrex/boobstrap
-
Notifications
You must be signed in to change notification settings - Fork 3
/
booty.in
executable file
·628 lines (598 loc) · 17.1 KB
/
booty.in
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
#! /usr/bin/env sh
mkbootstrap() {
SYSTEM="$1"
if test "$2"; then
shift
else
return 1
fi
case "$SYSTEM" in
"archlinux_gnulinux"|"arch_gnulinux") pacstrap "$@" ;;
"manjaro_gnulinux") basestrap "$@" ;;
"debian_gnulinux") debootstrap "$@" ;;
"crux_gnulinux") cruxstrap "$@" ;;
"fedora_gnulinux"|"redhat_gnulinux"|"centos_gnulinux") dnf "$@" ;;
esac
}
overlay() {
DESTINATION=""
OVERLAY=""
FORMAT=""
NUM=0
while test "$1"; do
case "$1" in
"--destination") DESTINATION="$(realpath $2)" ; shift ;;
"--overlay") OVERLAY="$OVERLAY $(realpath $2)" ; shift ;;
"--format") FORMAT="$2" ; shift ;;
esac
shift
done
if test "$DESTINATION" = ""; then
echo "No destination directory specified" | msg -2 --foreground "Brown"
return 1
fi
echo "Prepare overlays" | msg -2
hi
if test "$FORMAT" = ""; then
FORMAT="cpio"
echo "No overlay format specified, fallback to using CPIO" | msg -2 --foreground "Brown"
fi
for overlay in $OVERLAY; do
NUM="$(($NUM + 10))"
case "$FORMAT" in
"cpio")
SOURCE="$overlay"
TARGET="$DESTINATION/$NUM-$(basename $overlay).cpio"
echo "CPIO [$SOURCE] => [$TARGET]" | msg -2 --foreground "Light Blue"
cd "$SOURCE"
find . -print0 | cpio --create --format "newc" --null --quiet 1>$TARGET 2>/dev/null
CODE="$?"
cd "$OLDPWD"
;;
"squashfs"|"squashfs-"*)
SOURCE="$overlay"
TARGET="$DESTINATION/$NUM-$(basename $overlay).squashfs"
echo "SquashFS [$SOURCE] => [$TARGET]" | msg -2 --foreground "Light Blue"
mksquashfs "$SOURCE" "$TARGET" -b 1048576 -comp xz -Xdict-size 100% 1>/dev/null 2>/dev/null
CODE="$?"
;;
*)
CODE="1"
echo "Unknown filesystem format" | msg -2 --foreground "Brown"
;;
esac
hi
case "$CODE" in
"0") echo "Success" | msg -2 --foreground "Light Green" ;;
*) echo "Failure [$CODE]" | msg -2 --foreground "Brown" ;;
esac
lo
done
lo
echo "Overlays done" | msg -2
return "$CODE"
}
mkinitramfs() {
DIR=""
OUTPUT=""
IS_STANDALONE=""
STR_OVERLAY=""
STR_FORMAT=""
while test "$1"; do
case "$1" in
"--output") OUTPUT="$(realpath $2)" ; shift ;;
"--standalone") IS_STANDALONE="yes" ;;
"--overlay") STR_OVERLAY="$STR_OVERLAY --overlay $2" ; shift ;;
"--cpio") STR_FORMAT="--format cpio" ;;
"--squashfs") STR_FORMAT="--format squashfs" ;;
"--squashfs-xz") STR_FORMAT="--format squashfs-xz" ;;
"--help"|"-h")
cat <<EOF
$BOOTY_NAME $BOOTY_VERSION
Usage: mkinitramfs <directory> [options]...
Creates bootable ram disk image from the directory.
--output <file> specify output file,
by default outputs to STDOUT
--standalone uses directory "as is"
--overlay add overlay
--squashfs, pre-defined command mksquashfs
--squashfs-xz pre-defined command mksquashfs
Report about bugs & features to $(echo c3Bvb2ZpbmdAdm9nbGVhLm5ldAo= | base64 -d)
EOF
exit 0
;;
*)
if test "$DIR" = ""; then
DIR="$1"
fi
;;
esac
shift
done
if test "$OUTPUT" = ""; then
OUTPUT="-"
fi
if test "$DIR" = ""; then
echo "Directory not selected" | msg -2 --foreground "Brown"
return 1
fi
echo "Generating initramfs [$DIR]" | msg -2
hi
if test "$IS_STANDALONE" = ""; then
echo "Creating system directories" | msg -2
hi
for dir in "/proc" "/sys" "/dev" "/run" "/sbin" "/bin" "/etc" "/usr/sbin" "/usr/bin" "/mnt" "/tmp"; do
mkdir -p $DIR$dir 2>/dev/null
case "$?" in
"0") echo "$dir" | msg -2 --foreground "Light Blue" ;;
*) echo "$dir" | msg -2 --foreground "Light Red" --highlight ;;
esac
done
lo
#
# TODO replace it with mknod
#
echo "Copying devices" | msg -2
hi
for dev in "console" "tty" "tty1" "null"; do
cp -a "/dev/$dev" "$DIR/dev/$dev" 2>/dev/null
case "$?" in
"0") echo "/dev/$dev" | msg -2 --foreground "Light Blue" ;;
*) echo "/dev/$dev" | msg -2 --foreground "Light Red" --highlight ;;
esac
done
lo
echo "Copying system files" | msg -2
hi
for bin in $SYSTEMWIDE_BINARIES; do
which "$bin" 1>/dev/null 2>/dev/null
CODE="$?"
case "$CODE" in
"0") echo "$bin" | msg -2 --foreground "Light Blue" ;;
*) echo "$bin" | msg -2 --foreground "Light Red" --highlight ;;
esac
deps=""
for dep in $(lddtree $(which $bin 2>/dev/null)); do
deps="$deps $dep"
if test -f "$DIR$dep"; then
continue
fi
install -D "$dep" "$DIR$dep" 2>/dev/null
CODE="$?"
done
hi
for dep in $(echo $deps | tr ' ' '\n' | sort | uniq | tr '\n' ' '); do
case "$CODE" in
"0") echo "$dep" | msg -2 --foreground "Purple" ;;
*) echo "$dep" | msg -2 --foreground "Light Red" --highlight ;;
esac
done
lo
done
lo
echo "Creating init" | msg -2
hi
echo "/init" | msg -2 --foreground "Light Blue"
initramfs_init "$DIR/init"
case "$?" in
"0") ;;
*) echo "Failure [$CODE]" | msg -2 --foreground "Brown" ;;
esac
lo
fi
if test "$STR_OVERLAY"; then
mkdir -p "$DIR/media/system"
overlay --destination "$DIR/media/system" $STR_OVERLAY $STR_FORMAT
fi
echo "Creating initramfs [$OUTPUT]" | msg -2
cd "$DIR" 2>/dev/null
case "$OUTPUT" in
""|"-")
find . -print0 | cpio --create --format "newc" --null --quiet 2>/dev/null
CODE="$?"
;;
*)
find . -print0 | cpio --create --format "newc" --null --quiet > "$OUTPUT" 2>/dev/null
CODE="$?"
;;
esac
hi
case "$CODE" in
"0") echo "Success" | msg -2 --foreground "Light Green" ;;
*) echo "Error while generating initramfs" | msg -2 --foreground "Brown" --highlight ;;
esac
lo
cd "$OLDPWD" 2>/dev/null
echo "Done [$OUTPUT]" | msg -2
lo
echo "Done [$DIR]" | msg -2
}
mkbootisofs() {
DIR=""
ISO=""
LOADER_LEGACY_BOOT=""
LOADER_EFI=""
KERNEL=""
INITRD=""
BIOS=""
UEFI=""
PORTABLE=""
BOOTABLE=""
ISO_9660=""
ISO_9660_LABEL=""
ISO_9660_RUN=""
STR_OVERLAY=""
STR_FORMAT=""
while test "$1"; do
case "$1" in
"--output") ISO="$(realpath $2)" ; ISO_9660="yes" ; shift ;;
"--loader") LOADER_LEGACY_BOOT="$2" ; LOADER_EFI="$2" ; shift ;;
"--legacy-boot") LOADER_LEGACY_BOOT="$2" ; shift ;;
"--efi") LOADER_EFI="$2" ; shift ;;
"--kernel") KERNEL="$2" ; shift ;;
"--initrd") INITRD="$2" ; shift ;;
"--portable") PORTABLE="yes" ;;
"--bootable") BOOTABLE="yes" ;;
"--iso-9660") ISO_9660="yes" ;;
"--iso-9660-label") ISO_9660_LABEL="$2" ; shift ;;
"--overlay") STR_OVERLAY="$STR_OVERLAY --overlay $2" ; shift ;;
"--cpio") STR_FORMAT="--format cpio" ;;
"--squashfs") STR_FORMAT="--format squashfs" ;;
"--squashfs-xz") STR_FORMAT="--format squashfs-xz" ;;
"--help")
cat <<EOF
$BOOTY_NAME $BOOTY_VERSION
Usage: mkbootisofs <directory> [BOOT.ISO] [options]...
Creates BIOS and/or UEFI compatible bootable images.
--output < file | device | - >
--portable, creates structure of the disk (default)
--bootable, makes bootable device where directory created
--iso-9660 additional outputs ISO
--overlay < directory >
--cpio,
--squashfs
--help
Report about bugs & features to $(echo c3Bvb2ZpbmdAdm9nbGVhLm5ldAo= | base64 -d)
EOF
exit 0
;;
"-"*) echo "Unknown option: $1" | msg -2 ;;
*)
if test "$DIR" = ""; then
DIR="$(realpath $1)"
elif test "$ISO" = ""; then
ISO="$(realpath $1)"
ISO_9660="yes"
fi
;;
esac
shift
done
if test "$DIR" = ""; then
echo "No working directory selected" | msg -2 --foreground "Brown"
return 1
fi
if test "$ISO_9660" = "yes"; then
if xorrisofs --version 1>/dev/null 2>/dev/null; then
ISO_9660_RUN="xorrisofs"
fi
if genisoimage --version 1>/dev/null 2>/dev/null; then
ISO_9660_RUN="genisoimage"
fi
if test "$ISO_9660_RUN" = ""; then
echo "None of cdrkit, xorriso/xorrisofs or mkisofs found" | msg -2 --foreground "Brown"
return 1
fi
fi
for dir in "/usr/share/syslinux" "/usr/lib/syslinux/bios" "$SYSLINUX_PATH"; do
if test -f "$dir/mbr.bin"; then
SYSLINUX_BIOS_MBR="$dir/mbr.bin"
fi
if test -f "$dir/gptmbr.bin"; then
SYSLINUX_BIOS_GPTMBR="$dir/gptmbr.bin"
fi
if test -f "$dir/isolinux.bin"; then
SYSLINUX_BIOS_ISOLINUX="$dir/isolinux.bin"
fi
if test -f "$dir/ldlinux.c32"; then
SYSLINUX_BIOS_LDLINUX="$dir/ldlinux.c32"
fi
done
for dir in "/usr/share/syslinux/efi64" "/usr/lib/syslinux/efi64" "$SYSLINUX_PATH"; do
if test -f "$dir/syslinux.efi"; then
SYSLINUX_UEFI_EFIBOOT="$dir/syslinux.efi"
fi
if test -f "$dir/ldlinux.e64"; then
SYSLINUX_UEFI_LDLINUX="$dir/ldlinux.e64"
fi
done
for dir in "/usr/lib/grub" "/lib/grub" "$GRUB_PATH"; do
if test -d "$dir/i386-pc"; then
GRUB_PATH="$dir"
fi
done
case "$LOADER_LEGACY_BOOT" in
"grub2"|"GRUB2") LOADER_LEGACY_BOOT="GRUB2" ;;
"syslinux"|"SYSLINUX") LOADER_LEGACY_BOOT="SYSLINUX" ;;
?*) echo "Unknown legacy boot loader: $LOADER_LEGACY_BOOT" | msg -2 --foreground "Brown" ; return 1 ;;
esac
case "$LOADER_EFI" in
"grub2"|"GRUB2") LOADER_EFI="GRUB2" ;;
"syslinux"|"SYSLINUX") LOADER_EFI="SYSLINUX" ;;
?*) echo "Unknown efi loader: $LOADER_LEGACY_BOOT" | msg -2 --foreground "Brown" ; return 1 ;;
esac
echo "Creating bootable filesystem [$DIR]" | msg -2
hi
if test "$BOOTABLE" = "yes"; then
DEV="$(df $DIR | tail -n 1 | tr -s " " | cut -d " " -f 1 | sed -r "s:[0-9]+\$::" | sed -r "s:([0-9])[a-z]+\$:\\1:i")"
TYP="$(fdisk -l $DEV | grep Disklabel\ type: | cut -d " " -f 3)"
echo "Creating bootable device [$DEV]" | msg -2
hi
#
# FIXME: syslinux legacy boot on gpt is broken
# NOTABUG: grub2 requires "BIOS boot" partition
#
if test "$LOADER_LEGACY_BOOT" = "SYSLINUX"; then
case "$TYP" in
"dos") SYSLINUX_MBR="$SYSLINUX_BIOS_MBR" ;;
"gpt") SYSLINUX_MBR="$SYSLINUX_BIOS_GPTMBR" ;;
*) SYSLINUX_MBR="$SYSLINUX_BIOS_MBR" ;;
esac
echo "Installing syslinux as legacy boot loader" | msg -2 --foreground "Light Blue"
hi
mkdir -p "$DIR/efi/boot"
cp "/usr/share/booty/syslinux/syslinux.cfg" "$DIR/efi/boot/syslinux.cfg"
extlinux --install "$DIR/efi/boot" 2>&1 | msg -2 --foreground "Light Cyan" --background "Light Blue"
cat "$SYSLINUX_MBR" > "$DEV"
lo
fi
if test "$LOADER_EFI" = "SYSLINUX"; then
echo "Installing syslinux as efi loader" | msg -2 --foreground "Light Blue"
mkdir -p "$DIR/efi/boot"
cp "/usr/share/booty/syslinux/syslinux.cfg" "$DIR/efi/boot/syslinux.cfg"
cp "$SYSLINUX_UEFI_EFIBOOT" "$DIR/efi/boot/bootx64.efi"
cp "$SYSLINUX_UEFI_LDLINUX" "$DIR/efi/boot/"
fi
if test "$LOADER_LEGACY_BOOT" = "GRUB2"; then
echo "Installing grub2 as legacy boot loader" | msg -2 --foreground "Light Blue"
hi
mkdir -p "$DIR/boot/grub"
cp "/usr/share/booty/grub/grub.cfg" "$DIR/boot/grub/grub.cfg"
grub-install "$DEV" \
--boot-directory="$DIR/boot" \
--target="i386-pc" \
--recheck 2>&1 | msg -2 --foreground "Light Cyan" --background "Light Blue"
lo
fi
if test "$LOADER_EFI" = "GRUB2"; then
echo "Installing grub2 as efi loader" | msg -2 --foreground "Light Blue"
hi
mkdir -p "$DIR/boot/grub"
cp "/usr/share/booty/grub/grub.cfg" "$DIR/boot/grub/grub.cfg"
grub-install \
--boot-directory="$DIR/boot" \
--target="x86_64-efi" \
--removable \
--efi-directory="$DIR" \
--recheck 2>&1 | msg -2 --foreground "Light Cyan" --background "Light Blue"
lo
fi
lo
echo "Done [$DEV]" | msg -2
fi
if test "$STR_OVERLAY"; then
mkdir -p "$DIR/system"
overlay --destination "$DIR/system" $STR_OVERLAY $STR_FORMAT
fi
if test "$ISO_9660" = "yes"; then
if test "$ISO" = ""; then
ISO="-"
fi
echo "Burning [$ISO]" | msg -2
hi
if test "$LOADER_LEGACY_BOOT" = "SYSLINUX"; then
ISO_9660_LEGACY_BOOT="-b boot/syslinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table"
mkdir -p "$DIR/boot/syslinux"
cp "/usr/share/booty/syslinux/syslinux.cfg" "$DIR/boot/syslinux/syslinux.cfg"
for bin in $SYSLINUX_BIOS_ISOLINUX $SYSLINUX_BIOS_LDLINUX; do
cp "$bin" "$DIR/boot/syslinux"
done
fi
if test "$LOADER_EFI" = "SYSLINUX"; then
ISO_9660_EFI=""
echo "syslinux can't boot iso in efi-mode" | msg -2 --foreground "Light Blue"
fi
if test "$LOADER_LEGACY_BOOT" = "GRUB2"; then
ISO_9660_LEGACY_BOOT="-b boot/grub/bios.img -no-emul-boot -boot-load-size 4 -boot-info-table"
mkdir -p "$DIR/boot/grub"
mkdir -p "$DIR/boot/grub/i386-pc"
cp -a "$GRUB_PATH/i386-pc/"*".mod" "$DIR/boot/grub/i386-pc"
cp -a "$GRUB_PATH/i386-pc/"*".lst" "$DIR/boot/grub/i386-pc"
echo 'search --file --no-floppy --set root /boot/vmlinuz' > "$DIR/boot/grub/grub.cfg"
grub-mkimage \
--config="$DIR/boot/grub/grub.cfg" \
--output="$DIR/boot/grub/core.img" \
--format="i386-pc" \
--prefix="/boot/grub" \
biosdisk iso9660 normal search search_fs_file part_msdos part_gpt fat
cat "$GRUB_PATH/i386-pc/cdboot.img" "$DIR/boot/grub/core.img" > $DIR/boot/grub/bios.img
cp -r "/usr/share/booty/grub" "$DIR/boot"
fi
if test "$LOADER_EFI" = "GRUB2"; then
ISO_9660_EFI="-eltorito-alt-boot -e efi/boot/floppy.img -no-emul-boot"
mkdir -p "$DIR/efi/boot"
mkdir -p "$DIR/boot/grub"
mkdir -p "$DIR/boot/grub/x86_64-efi"
mkdir -p "$DIR/boot/grub/i386-efi"
cp -a "$GRUB_PATH/x86_64-efi/"*".mod" "$DIR/boot/grub/x86_64-efi"
cp -a "$GRUB_PATH/x86_64-efi/"*".lst" "$DIR/boot/grub/x86_64-efi"
cp -a "$GRUB_PATH/i386-efi/"*".mod" "$DIR/boot/grub/i386-efi"
cp -a "$GRUB_PATH/i386-efi/"*".lst" "$DIR/boot/grub/i386-efi"
echo 'search --file --no-floppy --set root /boot/vmlinuz' > "$DIR/boot/grub/grub.cfg"
grub-mkimage \
--config="$DIR/boot/grub/grub.cfg" \
--output="$DIR/efi/boot/bootx64.efi" \
--format="x86_64-efi" \
--prefix="/boot/grub" \
iso9660 normal search search_fs_file part_msdos part_gpt fat
grub-mkimage \
--config="$DIR/boot/grub/grub.cfg" \
--output="$DIR/efi/boot/bootia32.efi" \
--format="i386-efi" \
--prefix="/boot/grub" \
iso9660 normal search search_fs_file part_msdos part_gpt fat
mkdosfs -C -n "MS-DOS" "$DIR/efi/boot/floppy.img" 1440 1>/dev/null
mount -o loop "$DIR/efi/boot/floppy.img" "$DIR/boot"
mkdir -p "$DIR/boot/efi/boot"
cp "$DIR/efi/boot/bootx64.efi" "$DIR/boot/efi/boot"
cp "$DIR/efi/boot/bootia32.efi" "$DIR/boot/efi/boot"
umount "$DIR/boot"
cp -r "/usr/share/booty/grub" "$DIR/boot"
fi
if test "$ISO_9660_RUN" = "genisoimage"; then
echo "Creating iso image using genisoimage" | msg -2 --foreground "Light Blue"
hi
genisoimage -v -J -r -V "$ISO_9660_LABEL" -A "$ISO_9660_LABEL" \
-input-charset "utf-8" \
$ISO_9660_LEGACY_BOOT \
$ISO_9660_EFI \
-o "$ISO" "$DIR" 2>&1 | msg -2 --foreground "Light Cyan" --background "Light Blue"
CODE="$?"
lo
fi
if test "$ISO_9660_RUN" = "xorrisofs"; then
echo "Creating iso image using xorrisofs" | msg -2 --foreground "Light Blue"
hi
xorrisofs -v -J -r -V "$ISO_9660_LABEL" -A "$ISO_9660_LABEL" \
$ISO_9660_LEGACY_BOOT \
$ISO_9660_EFI \
-o "$ISO" "$DIR" 2>&1 | msg -2 --foreground "Light Cyan" --background "Light Blue"
CODE="$?"
lo
fi
if test "$LOADER_LEGACY_BOOT" = "SYSLINUX"; then
if test "$ISO_9660_EFI"; then
isohybrid --uefi "$ISO"
else
isohybrid "$ISO"
fi
fi
if test "$CODE"; then
case "$CODE" in
"0") echo "Success" | msg -2 --foreground "Light Green" ;;
*) echo "Failure [$CODE]" | msg -2 --foreground "Brown" ;;
esac
fi
lo
echo "Done [$ISO]" | msg -2
fi
lo
echo "Done [$DIR]" | msg -2
}
exportroot() {
CODE=""
DIR=""
while test "$1"; do
case "$1" in
*)
if test "$DIR" = ""; then
DIR="$1"
fi
;;
esac
shift
done
if test -d "$DIR"; then
echo "Export chroot [$DIR]" | msg -2
hi
cd "$DIR"
find . -print0 | cpio --create --format "newc" --null --quiet 2>/dev/null
CODE="$?"
case "$CODE" in
"0")
echo "Export success" | msg -2 --foreground "Light Green"
;;
*)
echo "Export failed" | msg -2 msg -2 --foreground "Brown"
;;
esac
cd "$OLDPWD"
lo
echo "Done [$DIR]" | msg -2
else
echo "No such directory [$DIR] for export" | msg -2 --foreground "Brown"
fi
return "$CODE"
}
importroot() {
CODE=""
DIR=""
while test "$1"; do
case "$1" in
*)
if test "$DIR" = ""; then
DIR="$1"
fi
;;
esac
shift
done
if test -d "$DIR"; then
echo "Import chroot [$DIR]" | msg -2
hi
cd "$DIR"
cpio --extract --make-directories --format "newc" --quiet 1>/dev/null 2>/dev/null
CODE="$?"
case "$CODE" in
"0")
echo "Import success" | msg -2 --foreground "Light Green"
;;
*)
echo "Import failed [$CODE]" | msg -2 --foreground "Brown"
;;
esac
cd "$OLDPWD"
lo
echo "Done [$DIR]" | msg -2
else
echo "No such directory [$DIR] for import" | msg -2 --foreground "Brown"
fi
return "$CODE"
}
lddtree() {
if test "$1" = ""; then
return 0
fi
echo "$1"
for dep in $(ldd "$1" | awk 'BEGIN{ORS="\n"}$1~/^\//{print $1}$3~/^\//{print $3}'); do
lddtree "$dep"
done
}
main() {
case "$(basename $0)" in
"mkbootstrap") mkbootstrap "$@" ;;
"mkinitramfs") mkinitramfs "$@" ;;
"mkbootisofs") mkbootisofs "$@" ;;
"exportroot") exportroot "$@" ;;
"importroot") importroot "$@" ;;
esac
}
hi() {
return 0
}
lo() {
return 0
}
msg() {
while read -r input; do
echo "$input" >&2
done
}
for BOOTY_CONF in "/etc/booty/booty.conf"; do
if test -f "$BOOTY_CONF"; then
. "$BOOTY_CONF" || exit 1
fi
done
readonly BOOTY_NAME="booty"
readonly BOOTY_VERSION="1.4"
main "$@"