forked from brightflash64/Linux-Respinner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultifunction.sh
More file actions
executable file
·787 lines (719 loc) · 28.4 KB
/
multifunction.sh
File metadata and controls
executable file
·787 lines (719 loc) · 28.4 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
#!/bin/bash
Encoding=UTF-8
[[ $EUID -ne 0 ]] && echo "You must be root to run this script." && exit
# Multifunction Linux Distro Respinner Script v0.80.
# Copyright (c) 2022 by Philip Collier, github.com/AB9IL
# Multifunction Linux Distro Respinner setup 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. There is NO warranty;
# not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Run this script as root to extract the iso contents,
# set up the chroot environment, or build a respun iso file.
# Boot into the iso you will respin. Create the working directory
# (sysdir) and copy the original iso into it. Set the variables
# before running this script. Change SYSUSER and PART to match the
# current username and partition to match your currently running
# system, or the paths will be incorrect.
#
#>>> THIS VERSION FOR <<<
#>>> Debian 12 or any Ubuntu before or after 20.10 <<<
#>>> For Ubuntu, be sure to set UBURELEASE variable!! <<<
#apt update
#apt install -y squashfs-tools genisoimage syslinux-utils xorriso fzf fd-find
# define variables:
export WKDIR="$(readlink -f "$(dirname "$0")")"
export BUILDDATE="$(date -u "+%Y%m%e")"
export RELEASEDATE="$(date -u "+%Y/%m/%d")"
export SYSUSER="$(logname)" # your username as builder of the respin
export CHROOTDNS='1.1.1.1' # DNS to use during chroot operation
export SYSDIR='respun-rhino' # the working directory of the respin project
export ISONAME="Rhino-Linux-2023.4-amd64.iso" # the filename for the iso to be extracted
export ISOCONTENTS='extract-cd' # directory containing the extracted iso contents
export VERSION='0.1.0' # version number of the respun distro
export UBURELEASE='2023.4' # Release Year.Month for Ubuntu distros (e.g. 23.10)
export UBUCODE='rhino' # Ubuntu or Debian codename
export MINTRELEASE=''
export MINTCODE='' # Mint codename
export DISTRIBID='Ubuntu' # LinuxMint or Ubuntu or Debian
export DISTRIBRELEASE=$UBURELEASE # variable for Mint or Ubuntu release
export DISTRIBCODE=$UBUCODE # variable for Mint or Ubuntu codename
export NEWISO="$SYSDIR-latest" # filename for the new iso derived from directory name
export DISTRONAME='Respun Rhino' # plain language name for the respun distro
export DISTROURL='https://example.com' # url for the respin's web page
export FLAVOUR='Rhino' # /etc/casper.conf flavour
export HOST='rhino' # /etc/casper.conf host in the respun distro
export USERNAME='user' # /etc/casper.conf user in the respun distro
export ARCH='amd64'
export RFSCONTENTS='edit' # directory containing the distro root filesystem
export ISOINFO="$DISTRONAME $VERSION - Release $ARCH ($BUILDDATE)" # data for the .disk/info file in the respun iso
export PROCNUM=4 # processor cores to use for filesystem extraction / compression
export xdgdirs="alacritty nvim Thunar wezterm" # XDG directories copied to root configs
export homedirs="dconf rofi gtk-3.0 gtk-4.0 qt5ct" # user configs copied to root configs
export dotfiles=".bashrc .bash_misc .bash_aliases .profile .xinitrc .Xresources .nanorc .wgetrc .inputrc .fzf.bash .tmux.conf"
export homefiles="mimeapps.list" # single files to copy from user config folder
#---DO NOT EDIT BELOW THIS LINE------------------------------------------------
[[ -n "$UBURELEASE" ]] && [[ $(echo "$UBURELEASE > 20.04" | bc -l) -eq 1 ]] && UBUAGE="new" || UBUAGE="old"
[[ "$UBUCODE" == "rhino" ]] && UBUAGE="zero"
[[ "$DISTRIBID" == "Debian" ]] && export MBR_FILE='isohdpfx.bin' # Proper mbr data for Debian isos
[[ "$DISTRIBID" == "Debian" ]] || export MBR_FILE='mbr.img' # Proper mbr data for Mint or Ubuntu isos
[[ "$DISTRIBID" == "Debian" ]] || export EFI_FILE='efi.img' # efi from original Ubuntu 20.10+ iso
extract_ubuntu() {
mkdir mnt
[[ -d "utils" ]] || mkdir utils
[[ -d "$ISOCONTENTS" ]] || mkdir $ISOCONTENTS
[[ -d "$RFSCONTENTS" ]] || mkdir $RFSCONTENTS
case "$UBUAGE" in
new)
# Extract the hybrid MBR template
dd if="$ISONAME" bs=1 count=432 of="${WKDIR}"/utils/"$MBR_FILE"
# Extract EFI partition image
skip=$(/sbin/fdisk -l "$ISONAME" | grep -F '.iso2 ' | awk '{print $2}')
size=$(/sbin/fdisk -l "$ISONAME" | grep -F '.iso2 ' | awk '{print $4}')
dd if="$ISONAME" bs=512 skip="$skip" count="$size" of="${WKDIR}"/utils/"$EFI_FILE"
;;
old)
# Extract the hybrid MBR template
dd if="$ISONAME" bs=1 count=512 of="${WKDIR}"/utils/"$MBR_FILE"
;;
esac
#
mount -o loop $ISONAME mnt
rsync -avhc --inplace \
mnt/ ${ISOCONTENTS}/
find ${ISOCONTENTS}/casper -type f -iname "*.squashfs" \
-exec unsquashfs -p $PROCNUM -f -d $RFSCONTENTS {} \;
umount mnt
rm -rf mnt
# copy certain files to utils
(cat $RFSCONTENTS/sbin/initctl > utils/initctl) &
for onefile in $dotfiles; do
cat $RFSCONTENTS/etc/skel/"$onefile" > utils/"$onefile" &
done
wait
([[ -d "$RFSCONTENTS/etc/skel/.local/" ]] && rsync -avhc --inplace --delete \
--mkpath $RFSCONTENTS/etc/skel/.local/ utils/.local/) &
([[ -d "$RFSCONTENTS/etc/skel/.tmux/" ]] && rsync -avhc --inplace --delete \
--mkpath $RFSCONTENTS/etc/skel/.tmux/ utils/.tmux/) &
write_scripts
}
extract_debian() {
mkdir mnt
[[ -d "utils" ]] || mkdir utils
[[ -d "$ISOCONTENTS" ]] || mkdir $ISOCONTENTS
[[ -d "$RFSCONTENTS" ]] || mkdir $RFSCONTENTS
dd if="$ISONAME" bs=1 count=432 of=utils/"$MBR_FILE"
mount -o loop $ISONAME mnt
rsync -avhc --inplace \
mnt/ ${ISOCONTENTS}/
find ${ISOCONTENTS}/live -type f -iname "*.squashfs" \
-exec unsquashfs -p $PROCNUM -f -d $RFSCONTENTS {} \;
umount mnt
rm -rf mnt
# copy certain files to utils
(cat $RFSCONTENTS/sbin/initctl > utils/initctl) &
for onefile in $dotfiles; do
cat $RFSCONTENTS/etc/skel/"$onefile" > utils/"$onefile" &
done
wait
([[ -d "$RFSCONTENTS/etc/skel/.local/" ]] && rsync -avhc --inplace --delete \
--mkpath $RFSCONTENTS/etc/skel/.local/ utils/.local/) &
([[ -d "$RFSCONTENTS/etc/skel/.tmux/" ]] && rsync -avhc --inplace --delete \
--mkpath $RFSCONTENTS/etc/skel/.tmux/ utils/.tmux/) &
write_scripts
}
enterchroot() {
#get prerequisites if needed
printf '\nGetting prerequisites...'
#apt install -y squashfs-tools genisoimage syslinux-utils xorriso
printf '\nBinding directories...'
mount --bind /run ${WKDIR}/${RFSCONTENTS}/run
mount --bind /dev ${WKDIR}/${RFSCONTENTS}/dev
mount --bind /dev/pts ${WKDIR}/${RFSCONTENTS}/dev/pts
mount --bind /proc ${WKDIR}/${RFSCONTENTS}/proc
mount --bind /sys ${WKDIR}/${RFSCONTENTS}/sys
(cp /etc/hosts $RFSCONTENTS/etc/hosts) &
(mkdir $RFSCONTENTS/run/systemd/resolve) &
[[ "$DISTRIBID" == "Debian" ]] || \
(echo 'nameserver '${CHROOTDNS}'' > $RFSCONTENTS/run/systemd/resolve/resolv.conf) &
[[ "$DISTRIBID" == "Debian" ]] || \
(echo 'nameserver '${CHROOTDNS}'' > $RFSCONTENTS/run/systemd/resolve/stub-resolv.conf) &
[[ "$DISTRIBID" == "Debian" ]] && \
(echo 'nameserver '${CHROOTDNS}'' > $RFSCONTENTS/etc/resolv.conf) &
printf '\nChrooting...'
chroot edit chroot-manager enter
cd $WKDIR || exit
umount ${WKDIR}/${RFSCONTENTS}/run
umount ${WKDIR}/${RFSCONTENTS}/dev/pts
umount ${WKDIR}/${RFSCONTENTS}/dev
umount ${WKDIR}/${RFSCONTENTS}/proc
umount ${WKDIR}/${RFSCONTENTS}/sys
(rm -f $RFSCONTENTS/etc/hosts) &
(rm -rf $RFSCONTENTS/root/.[^.]*) &
(rm -rf $RFSCONTENTS/run/systemd/resolve/.[^.]*) &
(rm -rf $RFSCONTENTS/tmp/.[^.]*) &
(rm -rf $RFSCONTENTS/var/cache/apt/.[^.]*) &
(rm -rf $RFSCONTENTS/var/cache/fontconfig/.[^.]*) &
(rm -rf $RFSCONTENTS/var/cache/man/.[^.]*) &
(rm -rf $RFSCONTENTS/var/lib/apt/lists/.[^.]*) &
(rm -rf $RFSCONTENTS/etc/apt/*.save) &
(rm -rf $RFSCONTENTS/etc/apt/sources.list.d/*.save) &
}
make_ubuntu_disk() {
printf '\nCreate %s.iso!' $NEWISO
printf '\nJumping above root directory, moving files...\n'
cleanup
cd $WKDIR || exit
mkdir -p $RFSCONTENTS/root/.config/dconf
mkdir -p $RFSCONTENTS/var/cache/apt/{archives,partial}
touch $RFSCONTENTS/var/cache/apt/archives/lock
cp -f utils/initctl $RFSCONTENTS/sbin/initctl
# copy dotfiles
for onefile in $dotfiles; do
tee $RFSCONTENTS/etc/skel/"$onefile" $RFSCONTENTS/root/"$onefile" < utils/"$onefile" > /dev/null &
done
# copy config files
for newconf in $homefiles; do
cp -f $RFSCONTENTS/etc/skel/.config/"$newconf" $RFSCONTENTS/root/.config/"$newconf" &
done
# copy config directories
for newdir in $xdgdirs; do
rsync -avhc --inplace --delete --mkpath \
$RFSCONTENTS/etc/xdg/"$newdir"/ $RFSCONTENTS/root/.config/"$newdir"/ &
done
# copy more config directories
for newdir in $homedirs; do
rsync -avhc --inplace --delete --mkpath \
$RFSCONTENTS/etc/skel/.config/"$newdir"/ $RFSCONTENTS/root/.config/"$newdir"/ &
done
# update the html readme file
fd . $RFSCONTENTS/usr/local/share/html/ \
-tf -e html -x sed -i "s|<p>Version: .*; Release Date: .*</p>|<p>Version: ${VERSION}; Release Date: ${RELEASEDATE}</p>|" &
wait
cd $WKDIR || exit
#set distro identity
printf '\nSetting distro identity...'
(echo -e '# This file should go in /etc/casper.conf
# Supported variables are:
# USERNAME, USERFULLNAME, HOST, BUILD_SYSTEM, FLAVOUR
export USERNAME="'${USERNAME}'"
export USERFULLNAME="Live session user"
export HOST="'${HOST}'"
export BUILD_SYSTEM="Ubuntu"
# USERNAME and HOSTNAME as specified above will not be honoured and will be set to
# flavour string acquired at boot time, unless you set FLAVOUR to any
# non-empty string.
export FLAVOUR="'${FLAVOUR}'"' > $RFSCONTENTS/etc/casper.conf) &
(echo -e ${DISTRONAME}' '${VERSION}' \\n \\l\n' > $RFSCONTENTS/etc/issue) &
(echo -e ${DISTRONAME}' '${VERSION}'' > $RFSCONTENTS/etc/issue.net) &
(echo -e 'DISTRIB_ID='${DISTRIBID}'
DISTRIB_RELEASE='${DISTRIBRELEASE}'
DISTRIB_CODENAME='${DISTRIBCODE}'
DISTRIB_DESCRIPTION="'${DISTRONAME}' '${VERSION}'"' > $RFSCONTENTS/etc/lsb-release) &
(echo -e '
The programs included with the '${DISTRONAME}' system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
'${DISTRONAME}' comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
' > $RFSCONTENTS/etc/legal) &
# VERSION_CODENAME must be either MINTCODE or UBUCODE
(echo -e 'NAME="'${DISTRONAME}'"
VERSION="'${VERSION}'"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="'${DISTRONAME}'"
VERSION_ID="'${VERSION}'"
HOME_URL="'${DISTROURL}'"
SUPPORT_URL="'${DISTROURL}'"
BUG_REPORT_URL="'${DISTROURL}'"
PRIVACY_POLICY_URL="'${DISTROURL}'"
VERSION_CODENAME="'${UBUCODE}'"
UBUNTU_CODENAME="'${UBUCODE}'"' > $RFSCONTENTS/usr/lib/os-release) &
(echo -e '#!/bin/sh
#
# 10-help-text - print the help text associated with the distro
# Copyright (C) 2009-2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>,
# Brian Murray <brian@canonical.com>
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
echo "* Support: '${DISTROURL}'"' > $RFSCONTENTS/etc/update-motd.d/10-help-text;
chmod +x $RFSCONTENTS/etc/update-motd.d/10-help-text) &
case "$UBUAGE" in
old)
(echo -e '#define DISKNAME '${DISTRONAME}' '${VERSION}'
#define TYPE binary
#define TYPEbinary 1
#define ARCH amd64
#define ARCHamd64 1
#define DISKNUM 1
#define DISKNUM1 1
#define TOTALNUM 0
#define TOTALNUM0 1' > $ISOCONTENTS/README.diskdefines) &
;;
esac
(echo -e ${ISOINFO} > $ISOCONTENTS/.disk/info) &
(echo -e ${DISTROURL} > $ISOCONTENTS/.disk/release_notes_url) &
#regenerate manifest
printf '\nRegenerating manifest...'
chmod +w $ISOCONTENTS/casper/filesystem.manifest;
chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' | \
tee $ISOCONTENTS/casper/filesystem.manifest $NEWISO-build.log
case "$UBUAGE" in
old)
cp $ISOCONTENTS/casper/filesystem.manifest $ISOCONTENTS/casper/filesystem.manifest-desktop;
sed -i '/ubiquity/d;
/casper/d;
/discover/d;
/laptop-detect/d;
/os-prober/d' $ISOCONTENTS/casper/filesystem.manifest-desktop
;;
esac
#compress filesystem
printf '\nCompressing filesystem for %s.iso version %s...\n' $NEWISO $VERSION
rm $ISOCONTENTS/casper/filesystem.squashfs
mksquashfs $RFSCONTENTS $ISOCONTENTS/casper/filesystem.squashfs \
-comp xz \
-b 1048576 \
-processors $PROCNUM
echo -e $(du -sx --block-size=1 edit | cut -f1) | \
tee $ISOCONTENTS/casper/filesystem.size
#update checksums
(cd $ISOCONTENTS
printf '\nUpdating sha512 sums...'
echo "The file sha512sum.txt contains the sha512 checksums of all files on this medium.
You can verify them automatically with the 'verify-checksums' boot parameter,
or, manually with: 'sha512sum -c sha512sum.txt'." > sha512sum.README
rm md5sum.txt MD5SUMS sha256sum.txt sha512sum.txt
grep -v isolinux/boot.cat <(fd -tf -x sha512sum) | \
tee sha512sum.txt ../$NEWISO-build.log 2>&1)
cd $WKDIR || exit
#remove the old iso file
printf '\nIf exists, delete the old %s.iso...\n' $NEWISO
[[ -f "$NEWISO.iso" ]] && rm -f $NEWISO.iso
#create iso image
printf '\nCreating %s.iso...\n' $NEWISO
# do not change the order of the xorriso options
# do not remove repeated xorriso options
case "$UBUAGE" in
zero)
xorrisofs -v \
-r -joliet-long -l \
-volset "$FLAVOUR$VERSION-$ARCH" \
-volid "$FLAVOUR$VERSION-$ARCH" \
-o $NEWISO.iso \
-iso-level 3 \
-partition_offset 16 \
--grub2-mbr utils/"$MBR_FILE" \
--mbr-force-bootable \
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b utils/"$EFI_FILE" \
-appended_part_as_gpt \
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
-c '/isolinux/boot.cat' \
-b '/isolinux/isolinux.bin' \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--grub2-boot-info \
-eltorito-alt-boot \
-e '--interval:appended_partition_2:::' \
-no-emul-boot \
$ISOCONTENTS | tee -a $NEWISO-build.log 2>&1
;;
new)
xorrisofs -v \
-r -joliet-long -l \
-volset "$FLAVOUR$VERSION-$ARCH" \
-volid "$FLAVOUR$VERSION-$ARCH" \
-o $NEWISO.iso \
-iso-level 3 \
-partition_offset 16 \
--grub2-mbr utils/"$MBR_FILE" \
--mbr-force-bootable \
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b utils/"$EFI_FILE" \
-appended_part_as_gpt \
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
-c '/boot.catalog' \
-b '/boot/grub/i386-pc/eltorito.img' \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--grub2-boot-info \
-eltorito-alt-boot \
-e '--interval:appended_partition_2:::' \
-no-emul-boot \
$ISOCONTENTS | tee -a $NEWISO-build.log 2>&1
;;
old)
xorrisofs -v \
-J -J -joliet-long \
-full-iso9660-filenames \
-input-charset utf-8 \
-rational-rock \
-volset "$FLAVOUR$VERSION-$ARCH" \
-volid "$FLAVOUR$VERSION-$ARCH" \
-o $NEWISO.iso \
-isohybrid-mbr utils/$MBR_FILE \
-eltorito-boot /isolinux/isolinux.bin \
-eltorito-catalog /isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e /boot/grub/efi.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
$ISOCONTENTS | tee -a $NEWISO-build.log 2>&1
;;
esac
# log iso information
echo -e '\nComputing the SHA256 sum:' | tee -a $NEWISO-build.log 2>&1
sha256sum $NEWISO.iso | tee -a $NEWISO-build.log 2>&1
echo -e '\nBoot record information:'
fdisk -lu $NEWISO.iso | tee -a $NEWISO-build.log 2>&1
echo -e 'Boot catalog and image paths:'
xorriso -indev $NEWISO.iso -toc -pvd_info | tee -a $NEWISO-build.log 2>&1
echo -e '\n'${NEWISO}' creation finished'
}
make_debian_disk() {
printf '\nCreate %s.iso!' $NEWISO
printf '\nJumping above root directory, moving files...\n'
cleanup
cd $WKDIR || exit
mkdir -p $RFSCONTENTS/root/.config/dconf
mkdir -p $RFSCONTENTS/var/cache/apt/{archives,partial}
touch $RFSCONTENTS/var/cache/apt/archives/lock
cp -f utils/initctl $RFSCONTENTS/sbin/initctl
# copy dotfiles
for onefile in $dotfiles; do
tee $RFSCONTENTS/etc/skel/"$onefile" $RFSCONTENTS/root/"$onefile" < utils/"$onefile" > /dev/null &
done
# copy config files
for newconf in $homefiles; do
cp -f $RFSCONTENTS/etc/skel/.config/"$newconf" $RFSCONTENTS/root/.config/"$newconf" &
done
# copy config directories
for newdir in $xdgdirs; do
rsync -avhc --inplace --delete --mkpath \
$RFSCONTENTS/etc/xdg/"$newdir"/ $RFSCONTENTS/root/.config/"$newdir"/ &
done
# copy more config directories
for newdir in $homedirs; do
rsync -avhc --inplace --delete --mkpath \
$RFSCONTENTS/etc/skel/.config/"$newdir"/ $RFSCONTENTS/root/.config/"$newdir"/ &
done
# update the html readme file
fd . $RFSCONTENTS/usr/local/share/html/ \
-tf -e html -x sed -i "s|<p>Version: .*; Release Date: .*</p>|<p>Version: ${VERSION}; Release Date: ${RELEASEDATE}</p>|" &
wait
cd $WKDIR || exit
#set distro identity
printf '\nSetting distro identity...'
(echo -e '
## live-config has got the impression it should reset xfce4-panel's settings, after we've set them.
LIVE_CONFIG_NOCOMPONENTS=xfce4-panel
## Set our user and host names.
LIVE_HOSTNAME='${HOST}'
LIVE_USERNAME='${USERNAME}'
LIVE_USER_FULLNAME="Debian live user"' > $RFSCONTENTS/etc/live/config.conf) &
(echo -e ${DISTRONAME}' '${VERSION}' \\n \\l\n' > $RFSCONTENTS/etc/issue) &
(echo -e ${DISTRONAME}' '${VERSION}'' > $RFSCONTENTS/etc/issue.net) &
(echo -e '
The programs included with the '${DISTRONAME}' system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
'${DISTRONAME}' comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.' > $RFSCONTENTS/etc/legal) &
# VERSION_CODENAME must be either MINTCODE or UBUCODE
(echo -e 'PRETTY_NAME="'${DISTRONAME}' '${VERSION}' ('${UBUCODE}')"
NAME="'${DISTRONAME}'"
VERSION_ID="'${VERSION}'"
VERSION="'${VERSION}'"
VERSION_CODENAME="'${UBUCODE}'"
ID=debian
ID_LIKE=debian
HOME_URL="'${DISTROURL}'"
SUPPORT_URL="'${DISTROURL}'"
BUG_REPORT_URL="'${DISTROURL}'"
PRIVACY_POLICY_URL="'${DISTROURL}'"' > $RFSCONTENTS/usr/lib/os-release) &
(echo -e '#!/bin/sh
#
# 10-help-text - print the help text associated with the distro
# Copyright (C) 2009-2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>,
# Brian Murray <brian@canonical.com>
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
echo "* Support: '${DISTROURL}'"' > $RFSCONTENTS/etc/update-motd.d/10-help-text;
chmod +x $RFSCONTENTS/etc/update-motd.d/10-help-text) &
(echo -e ${ISOINFO} > $ISOCONTENTS/.disk/info) &
(echo -e ${DISTROURL} > $ISOCONTENTS/.disk/release_notes_url) &
wait
#compress filesystem
printf '\nCompressing filesystem for %s.iso version %s...\n' $NEWISO $VERSION
rm $ISOCONTENTS/live/filesystem.squashfs
mksquashfs $RFSCONTENTS $ISOCONTENTS/live/filesystem.squashfs \
-comp xz \
-b 1048576 \
-processors $PROCNUM
# echo -e $(du -sx --block-size=1 edit | cut -f1) | \
# tee $ISOCONTENTS/live/filesystem.size
#update checksums
(cd $ISOCONTENTS
printf '\nUpdating sha512 sums...'
echo "The file sha512sum.txt contains the sha512 checksums of all files on this medium.
You can verify them automatically with the 'verify-checksums' boot parameter,
or, manually with: 'sha512sum -c sha512sum.txt'." > sha512sum.README
rm md5sum.txt MD5SUMS sha256sum.txt sha512sum.txt
grep -v isolinux/boot.cat <(fd -tf -x sha512sum) | \
tee sha512sum.txt ../$NEWISO-build.log 2>&1)
cd $WKDIR || exit
#remove the old iso file
printf '\nIf exists, delete the old %s.iso...\n' $NEWISO
[[ -f "$NEWISO.iso" ]] && rm -f $NEWISO.iso
#create iso image
printf '\nCreating %s.iso...\n' $NEWISO
# do not change the order of the xorriso options
# do not remove repeated xorriso options
xorrisofs -v \
-R -r -J -joliet-long \
-full-iso9660-filenames \
-cache-inodes \
-iso-level 3 \
-isohybrid-mbr utils/$MBR_FILE \
-partition_offset 16 \
-A "$ISOCONTENTS" \
-p "$DISTROURL" \
-publisher "$DISTROURL" \
-V "$DISTRONAME-$BUILDDATE" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e boot/grub/efi.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-isohybrid-apm-hfsplus \
-o $NEWISO.iso \
$ISOCONTENTS | tee -a $NEWISO-build.log 2>&1
# log iso information
echo -e '\nComputing the SHA256 sum:' | tee -a $NEWISO-build.log 2>&1
sha256sum $NEWISO.iso | tee -a $NEWISO-build.log 2>&1
echo -e '\nBoot record information:'
fdisk -lu $NEWISO.iso | tee -a $NEWISO-build.log 2>&1
echo -e 'Boot catalog and image paths:'
xorriso -indev $NEWISO.iso -toc -pvd_info | tee -a $NEWISO-build.log 2>&1
echo -e '\n'${NEWISO}' creation finished'
}
write_scripts() {
printf '#!/bin/bash
Encoding=UTF-8
enter(){
printf "\nMounting directories...\n"
export TERM="linux"
export HOME="/root"
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
dbus-uuidgen > /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
printf "\nMoving to system root directory...\n"
cd
/bin/bash
leave
}
leave(){
printf "\nCleaning up before chroot exit...\n"
rm /var/lib/dbus/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
rm -rf /var/cache/apt/.[^.]*
rm -rf /var/lib/apt/lists/.[^.]*
rm -rf /var/cache/fontconfig/.[^.]*
rm -rf /etc/apt/sources.list.d/*.save
rm -rf /root/.[^.]*
rm -rf /tmp/.[^.]*
rm -rf /var/tmp/.[^.]*
rm -f /etc/hosts
rm /etc/machine-id
apt autoremove --purge
apt clean
nala clean
vers=(8 9 10 11 12 13)
for ver in "${vers[@]}";do
python3."$ver" -m pip cache purge
done
printf "\nExiting chroot...\n"
umount /run
umount /proc || umount -lf /proc
umount /sys
umount /dev
umount /dev/pts
exit
}
case $1 in
enter)
enter
;;
leave)
leave
;;
**)
printf "Manage entry and exit of the chroot environment.\n\n
Usage: %s (enter|leave)" "$0"
;;
esac
' > $RFSCONTENTS/usr/sbin/chroot-manager
chmod +x $RFSCONTENTS/usr/sbin/chroot-manager
printf '#!/bin/bash
kernel="$1"
create(){
# Create vmlinuz and initrd files for bootable hybrid livecds.
echo "Creating files for kernel "$kernel"...
This will take a few minutes."
depmod -a -v -w $kernel
update-initramfs -c -k $kernel ; sync
#gzip -dc /boot/initrd.img-$kernel | lzma -7 > ~/initrd.lz
cp /boot/initrd.img-$kernel ~/initrd
cp /boot/vmlinuz-$kernel ~/vmlinuz
rm -f /vmlinuz
rm -f /initrd.img
ln -s /boot/vmlinuz-$kernel /vmlinuz
ln -s /boot/initrd.img-$kernel /initrd.img
update-grub
printf "Task finished; look in $HOME for the files."
}
case "$1" in
-h*|-H*)
[[ "$2" -ne "0" || -z "$2" ]] && \
printf "usage: build-bootfiles <kernel>";
exit
;;
*)
create
;;
esac
' > $RFSCONTENTS/usr/sbin/build-bootfiles
chmod +x $RFSCONTENTS/usr/sbin/build-bootfiles
# make script copy "initrd.img" for Debian isos
[[ "$DISTRIBID" == "Debian" ]] && sed -i 's|~/initrd|initrd.img|' $RFSCONTENTS/usr/sbin/build-bootfiles
}
extractinitrd() {
cd initrd-rebuild
#For initrd.gz from an apt-get upgrade in chroot
#gzip -dc ../initrd.gz | cpio -id
#For initrd.gz in the iso file
#gzip -dc ../$ISOCONTENTS/casper/initrd.gz | cpio -id
#For initrd.lz in the iso file
lzma -dc -S .lz ../$ISOCONTENTS/casper/initrd.lz | cpio -id
cd ../
}
repackinitrd() {
cd initrd-rebuild
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../$ISOCONTENTS/casper/initrd-new.lz
cd ../
}
cleanup() {
cd $WKDIR || exit
printf '\nCleaning up...\n'
umount $RFSCONTENTS/dev
(chown -R man:root $RFSCONTENTS/var/cache/man) &
(fd -H -e TBL . "$ISOCONTENTS" -x rm) &
(fd -H -e txt -e conf -e db -e md -e html . "$RFSCONTENTS/usr/local" -x chmod 666) &
(fd -H -e py -e sh . "$RFSCONTENTS/usr/local/sbin" -x chmod 755) &
(fd -H -tf . "$RFSCONTENTS/usr/local/etc" -x chmod 666) &
(fd -H -e db -e TAG . "$RFSCONTENTS/var/cache" -x chmod 664) &
(fd -H -td . "$RFSCONTENTS/var/log" -x chmod 755) &
(fd -H -tf . "$ISOCONTENTS/isolinux" -x chmod 644) &
(fd -H -e save . "$RFSCONTENTS/etc/apt/sources.list.d" -x rm) &
[[ "$DISTRIBID" == "Debian" ]] || (fd -H -tf . "$RFSCONTENTS/var/crash" -x rm) &
(fd -H -tf . "$RFSCONTENTS/var/lib/apt" -x rm) &
(fd -H -tf . "$RFSCONTENTS/var/cache/apt" -x rm) &
(fd -H -tf . "$RFSCONTENTS/var/log" -x rm) &
(fd -H -tf . "$RFSCONTENTS/var/tmp" -x rm) &
(fd -H -e dpkg-old -e dpkg-dist . "$RFSCONTENTS" -x rm) &
(fd -H -tf . "$RFSCONTENTS/tmp" -x rm) &
(fd -H . "$RFSCONTENTS/home" -x rm -rf) &
(fd -H . "$RFSCONTENTS/root" -x rm -rf) &
(fd -H . "$RFSCONTENTS/tmp" -x rm -rf) &
printf '\nSetting some permissions...\n'
(chmod 4755 $RFSCONTENTS/usr/bin/pkexec) &
(chmod 4755 $RFSCONTENTS/usr/bin/sudo) &
(chown root:messagebus $RFSCONTENTS/usr/lib/dbus-1.0/dbus-daemon-launch-helper) &
(chmod u+s $RFSCONTENTS/usr/lib/dbus-1.0/dbus-daemon-launch-helper) &
printf 'Waiting to finish cleanup and permissions...\n'
wait
}
makebackup(){
echo -e '\nCopying '${NEWISO}'.iso to '${NEWISO}'.bak.iso...\n'
cp -fp $NEWISO.iso $NEWISO.bak.iso
echo -e '\nBackup job complete...'
}
case "$1" in
chroot)
enterchroot
;;
makedisk)
[[ "$DISTRIBID" == "Debian" ]] && make_debian_disk
[[ "$DISTRIBID" == "Ubuntu" ]] && make_ubuntu_disk
[[ "$DISTRIBID" == "LinuxMint" ]] && make_ubuntu_disk
;;
backup)
makebackup
;;
extractiso)
[[ "$DISTRIBID" == "Debian" ]] && extract_debian
[[ "$DISTRIBID" == "Ubuntu" ]] && extract_ubuntu
[[ "$DISTRIBID" == "LinuxMint" ]] && extract_ubuntu
;;
extractinit)
extractinitrd
;;
repackinit)
repackinitrd
;;
cleanup)
cleanup
;;
*)
echo "$0 <command>
chroot Enter a chroot environment
makedisk Create a new iso file based on edited filesystem
backup Create a backup of the iso file
extractiso Extract filesystem from iso file
extractinit Extract contents of initrd file
repackinit Rebuild initrd from extracted contents
cleanup clean cruft and set permissions in the iso filesystem
" >&2
exit 3
;;
esac