forked from mdrights/LiveSlak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_slackware_live.sh
executable file
·2313 lines (1986 loc) · 85.6 KB
/
make_slackware_live.sh
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
# Copyright 2014, 2015, 2016, 2017 Eric Hameleers, Eindhoven, NL
# All rights reserved.
#
# Permission to use, copy, modify, and distribute this software for
# any purpose with or without fee is hereby granted, provided that
# the above copyright notice and this permission notice appear in all
# copies.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# This script creates a live image for a Slackware OS.
# Features:
# - boots using isolinux/extlinux on BIOS, or grub on UEFI.
# - requires kernel >= 4.0 which supports multiple lower layers in overlay
# - uses squashfs to create compressed modules out of directory trees
# - uses overlayfs to bind multiple squashfs modules together
# - you can add your own modules into ./addons/ or ./optional subdirectories.
# - persistence is enabled when writing the ISO to USB stick using iso2usb.sh.
# - LUKS encrypted homedirectory is optional on USB stick using iso2usb.sh.
#
# -----------------------------------------------------------------------------
# Version of the Live OS generator:
VERSION="1.1.8.2"
# Directory where our live tools are stored:
LIVE_TOOLDIR=${LIVE_TOOLDIR:-"$(cd $(dirname $0); pwd)"}
# Load the optional configuration file:
CONFFILE=${CONFFILE:-"${LIVE_TOOLDIR}/$(basename $0 .sh).conf"}
if [ -f ${CONFFILE} ]; then
echo "-- Loading configuration file."
. ${CONFFILE}
fi
# Set to "YES" to send error output to the console:
DEBUG=${DEBUG:-"NO"}
# Set to "YES" in order to delete everything we have,
# and rebuild any pre-existing .sxz modules from scratch:
FORCE=${FORCE:-"NO"}
# Set to 32 to be more compatible with the specs. Slackware uses 4 by default:
BOOTLOADSIZE=${BOOTLOADSIZE:-4}
# If you want to include an EFI boot image for 32bit Slackware then you
# need a recompiled grub which supports 32bit EFI (Slackware's grub will not).
# A patch for grub.SlackBuild to enable this feature can be found
# in the source directory. Works for both the 32bit and the 64bit grub package.
# Therefore we disable 32bit EFI by default. Enable at your own peril:
EFI32=${EFI32:-"NO"}
# Set to YES if you want to use the SMP kernel on 32bit Slackware:
SMP32=${SMP32:-"NO"}
# Include support for NFS root (PXE boot), will increase size of the initrd:
NFSROOTSUP=${NFSROOTSUP:-"NO"}
# Use xorriso instead of mkisofs/isohybrid to create the ISO:
USEXORR=${USEXORR:-"NO"}
# Timestamp:
THEDATE=$(date +%Y%m%d)
#
# ---------------------------------------------------------------------------
#
# The live username of the image:
LIVEUID=${LIVEUID:-"live"}
# The root and live user passwords of the image:
ROOTPW=${ROOTPW:-"toor"}
LIVEPW=${LIVEPW:-"live"}
# Distribution name:
DISTRO=${DISTRO:-"slackware"}
# Custom name for the host:
LIVE_HOSTNAME=${LIVE_HOSTNAME:-"darkstar"}
# What type of Live image?
# Choices are: SLACKWARE, XFCE, KDE4, PLASMA5, MATE, CINNAMON, DLACK, STUDIOWARE
LIVEDE=${LIVEDE:-"SLACKWARE"}
# What runlevel to use if adding a DE like: XFCE, KDE4, PLASMA5 etc...
RUNLEVEL=${RUNLEVEL:-4}
# Use the graphical syslinux menu (YES or NO)?
SYSMENU=${SYSMENU:-"YES"}
# This variable can be set to a comma-separated list of package series.
# The squashfs module(s) for these package series will then be re-generated.
# Example commandline parameter: "-r l,kde,kdei"
REFRESH=""
# The amount of seconds we want the init script to wait to give the kernel's
# USB subsystem time to settle. The default value of mkinitrd is "1" which
# is too short for use with USB sticks but "1" is fine for CDROM/DVD.
WAIT=${WAIT:-"5"}
#
# ---------------------------------------------------------------------------
#
# Who built the live image:
BUILDER=${BUILDER:-"MDrights"}
# Console font to use with syslinux for better language support:
CONSFONT=${CONSFONT:-"ter-i16v.psf"}
# The ISO main directory:
LIVEMAIN=${LIVEMAIN:-"liveslak"}
# Marker used for finding the Slackware Live files:
MARKER=${MARKER:-"SLACKWARELIVE"}
# The filesystem label we will be giving our ISO:
MEDIALABEL=${MEDIALABEL:-"LIVESLAK"}
# The name of the custom package list containing the generic kernel.
# This package list is special because the script will also take care of
# the ISO boot setup when processing the MINLIST package list:
MINLIST=${MINLIST:-"min"}
# For x86_64 you can add multilib:
MULTILIB=${MULTILIB:-"NO"}
# Use the '-G' parameter to generate the ISO from a pre-populated directory
# containing the live OS files:
ONLY_ISO="NO"
# The name of the directory used for storing persistence data:
PERSISTENCE=${PERSISTENCE:-"persistence"}
# Slackware version to use (note: this won't work for Slackware <= 14.1):
SL_VERSION=${SL_VERSION:-"current"}
# Slackware architecture to install:
SL_ARCH=${SL_ARCH:-"x86_64"}
# Root directory of a Slackware local mirror tree;
# You can define custom repository location (must be in local filesystem)
# for any module in the file ./pkglists/<module>.conf:
SL_REPO=${SL_REPO:-"/var/cache/liveslak/Slackware"}
DEF_SL_REPO=${SL_REPO}
# The rsync URI of our default Slackware mirror server:
SL_REPO_URL=${SL_REPO_URL:-"rsync.osuosl.org::slackware"}
DEF_SL_REPO_URL=${SL_REPO_URL}
# List of Slackware package series - each will become a squashfs module:
SEQ_SLACKWARE="tagfile:a,ap,d,e,f,k,kde,kdei,l,n,t,tcl,x,xap,xfce,y pkglist:slackextra"
# Stripped-down Slackware with XFCE as the Desktop Environment:
# - each series will become a squashfs module:
SEQ_XFCEBASE="${MINLIST},xbase,xapbase,xfcebase"
# Stripped-down Slackware with KDE4 as the Desktop Environment:
# - each series will become a squashfs module:
SEQ_KDE4BASE="pkglist:${MINLIST},xbase,xapbase,kde4base"
# List of Slackware package series with Plasma5 (full install):
# - each will become a squashfs module:
SEQ_PLASMA5="tagfile:a,ap,d,e,f,k,l,n,t,tcl,x,xap,xfce,y pkglist:slackextra,kde4plasma5,plasma5,alien,alienrest,slackpkgplus"
# List of Slackware package series with MATE (not full install, stripped out some serials by MD):
# - each will become a squashfs module:
SEQ_MSB="tagfile:a,ap,d,l,n,x,xap pkglist:slackextra,mate"
# List of Slackware package series with Cinnamon (not full install):
# - each will become a squashfs module:
SEQ_CIN="tagfile:a,ap,d,l,n,x,xap pkglist:slackextra,cinnamon"
# Slackware package series with Gnome3/systemd instead of KDE4 (full install):
# - each will become a squashfs module:
SEQ_DLACK="tagfile:a,ap,d,e,f,k,l,n,t,tcl,x,xap pkglist:slackextra,systemd,dlackware"
# List of Slackware package series with StudioWare (full install):
# - each will become a squashfs module:
SEQ_STUDW="tagfile:a,ap,d,e,f,k,kde,l,n,t,tcl,x,xap,xfce,y pkglist:slackextra,studioware,slackpkgplus"
# -- START: Used verbatim in upslak.sh -- #
# List of kernel modules required for a live medium to boot properly;
# Lots of HID modules added to support keyboard input for LUKS password entry:
KMODS=${KMODS:-"squashfs:overlay:loop:xhci-pci:ohci-pci:ehci-pci:xhci-hcd:uhci-hcd:ehci-hcd:mmc-core:mmc-block:sdhci:sdhci-pci:sdhci-acpi:usb-storage:hid:usbhid:i2c-hid:hid-generic:hid-apple:hid-cherry:hid-logitech:hid-logitech-dj:hid-logitech-hidpp:hid-lenovo:hid-microsoft:hid_multitouch:jbd:mbcache:ext3:ext4:isofs:fat:nls_cp437:nls_iso8859-1:msdos:vfat:ntfs"}
# Network kernel modules to include for NFS root support:
NETMODS="kernel/drivers/net"
# Network kernel modules to exclude from above list:
NETEXCL="appletalk arcnet bonding can dummy.ko hamradio hippi ifb.ko irda macvlan.ko macvtap.ko pcmcia sb1000.ko team tokenring tun.ko usb veth.ko wan wimax wireless xen-netback.ko"
# -- END: Used verbatim in upslak.sh -- #
# Firmware for wired network cards required for NFS root support:
NETFIRMWARE="3com acenic adaptec bnx tigon e100 sun kaweth tr_smctr cxgb3"
# If any Live variant needs additional 'append' parameters, define them here,
# either using a variable name 'KAPPEND_<LIVEDE>', or by defining 'KAPPEND' in the .conf file:
KAPPEND_SLACKWARE=""
KAPPEND_STUDIOWARE="threadirqs"
#
# ---------------------------------------------------------------------------
#
# What compression to use for the initrd?
# Default is xz with CRC32 (the kernel's XZ decoder does not support CRC64),
# the alternative is gzip (which adds ~30% to the initrd size).
COMPR=${COMPR:-"xz --check=crc32"}
# What compression to use for the squashfs modules?
# Default is xz, alternatives are gzip, lzma, lzo:
SXZ_COMP=${SXZ_COMP:-"xz"}
# Mount point where Live filesystem is assembled (no storage requirements):
LIVE_ROOTDIR=${LIVE_ROOTDIR:-"/mnt/slackwarelive"}
# Directory where the live ISO image will be written:
OUTPUT=${OUTPUT:-"/tmp"}
# Directory where we create the staging directory:
TMP=${TMP:-"/tmp"}
# Toplevel directory of our staging area (this needs sufficient storage):
LIVE_STAGING=${LIVE_STAGING:-"${TMP}/slackwarelive_staging"}
# Work directory where we will create all the temporary stuff:
LIVE_WORK=${LIVE_WORK:-"${LIVE_STAGING}/temp"}
# Directory to be used by overlayfs for data manipulation,
# needs to be a directory in the same filesystem as ${LIVE_WORK}:
LIVE_OVLDIR=${LIVE_OVLDIR:-"${LIVE_WORK}/.ovlwork"}
# Directory where we will move the kernel and create the initrd;
# note that a ./boot directory will be created in here by installpkg:
LIVE_BOOT=${LIVE_BOOT:-"${LIVE_STAGING}/${LIVEMAIN}/bootinst"}
# Directories where the squashfs modules will be created:
LIVE_MOD_SYS=${LIVE_MOD_SYS:-"${LIVE_STAGING}/${LIVEMAIN}/system"}
LIVE_MOD_ADD=${LIVE_MOD_ADD:-"${LIVE_STAGING}/${LIVEMAIN}/addons"}
LIVE_MOD_OPT=${LIVE_MOD_OPT:-"${LIVE_STAGING}/${LIVEMAIN}/optional"}
# ---------------------------------------------------------------------------
# Define some functions.
# ---------------------------------------------------------------------------
# Clean up in case of failure:
cleanup() {
# Clean up by unmounting our loopmounts, deleting tempfiles:
echo "--- Cleaning up the staging area..."
sync
umount ${LIVE_ROOTDIR}/sys 2>${DBGOUT} || true
umount ${LIVE_ROOTDIR}/proc 2>${DBGOUT} || true
umount ${LIVE_ROOTDIR}/dev 2>${DBGOUT} || true
umount ${LIVE_ROOTDIR} 2>${DBGOUT} || true
# Need to umount the squashfs modules too:
umount ${LIVE_WORK}/*_$$ 2>${DBGOUT} || true
rmdir ${LIVE_ROOTDIR} 2>${DBGOUT}
rmdir ${LIVE_WORK}/*_$$ 2>${DBGOUT}
rm -r ${LIVE_MOD_OPT}/ 2>${DBGOUT} || true
rm -r ${LIVE_MOD_ADD}/ 2>${DBGOUT} || true
rm -r ${LIVE_STAGING}/* 2>${DBGOUT} || true
}
trap 'echo "*** $0 FAILED at line $LINENO ***"; cleanup; exit 1' ERR INT TERM
# Uncompress the initrd based on the compression algorithm used:
uncompressfs () {
if $(file "${1}" | grep -qi ": gzip"); then
gzip -cd "${1}"
elif $(file "${1}" | grep -qi ": XZ"); then
xz -cd "${1}"
fi
}
#
# Return the full pathname of first package found below $2 matching exactly $1:
#
full_pkgname() {
PACK=$1
TOPDIR=$2
# Perhaps I will use this more readable code in future:
#for FL in $(find ${TOPDIR} -name "${PACK}-*.t?z" 2>/dev/null) ; do
# # Weed out package names starting with "$PACK"; we want exactly "$PACK":
# if [ "$(echo $FL |rev |cut -d- -f4- |cut -d/ -f1 |rev)" != "$PACK" ]; then
# continue
# else
# break
# fi
#done
#echo "$FL"
echo "$(find ${TOPDIR} -name "${PACK}-*.t?z" 2>/dev/null |grep -E "\<${PACK//+/\\+}-[^-]+-[^-]+-[^-]+.t?z" |head -1)"
}
#
# Find packages and install them into the temporary root:
#
function install_pkgs() {
if [ -z "$1" ]; then
echo "-- function install_pkgs: Missing module name."
cleanup
exit 1
fi
if [ ! -d "$2" ]; then
echo "-- function install_pkgs: Target directory '$2' does not exist!"
cleanup
exit 1
elif [ ! -f "$2/${MARKER}" ]; then
echo "-- function install_pkgs: Target '$2' does not contain '${MARKER}' file."
echo "-- Did you choose the right installation directory?"
cleanup
exit 1
fi
# Define the default Slackware repository, can be overridden here:
SL_REPO_URL="${DEF_SL_REPO_URL}"
SL_REPO="${DEF_SL_REPO}"
SL_PKGROOT="${DEF_SL_PKGROOT}"
SL_PATCHROOT="${DEF_SL_PATCHROOT}"
if [ "$3" = "local" -a -d ${LIVE_TOOLDIR}/local${DIRSUFFIX}/$1 ]; then
echo "-- Installing local packages from subdir 'local${DIRSUFFIX}/$1'."
installpkg --terse --root "$2" "local${DIRSUFFIX}/$1/*.t?z"
else
# Load package list and (optional) custom repo info:
if [ "$3" = "tagfile" ]; then
PKGCONF="__tagfile__"
PKGFILE=${SL_PKGROOT}/${1}/tagfile
else
PKGCONF=${LIVE_TOOLDIR}/pkglists/$(echo $1 |tr [A-Z] [a-z]).conf
PKGFILE=${LIVE_TOOLDIR}/pkglists/$(echo $1 |tr [A-Z] [a-z]).lst
if [ -f ${PKGCONF} ]; then
echo "-- Loading repo info for '$1'."
. ${PKGCONF}
fi
fi
if [ "${SL_REPO}" = "${DEF_SL_REPO}" ]; then
# We need only one release from the Slackware package mirror;
# This must *not* end with a '/' :
SELECTION="${DISTRO}${DIRSUFFIX}-${SL_VERSION}"
else
SELECTION=""
fi
if [ ! -d ${SL_REPO} -o -z "$(find ${SL_PKGROOT} -type f 2>/dev/null)" ]; then
# Oops... empty local repository. Let's see if we can rsync from remote:
echo "** Slackware package repository root '${SL_REPO}' does not exist or is empty!"
RRES=1
if [ -n "${SL_REPO_URL}" ]; then
mkdir -p ${SL_REPO}
# Must be a rsync URL!
echo "-- Rsync-ing repository content from '${SL_REPO_URL}' to local directory '${SL_REPO}'..."
echo "-- This can be time-consuming. Please wait."
rsync -rlptD --no-motd --exclude=source ${RSYNCREP} ${SL_REPO_URL}/${SELECTION} ${SL_REPO}/
RRES=$?
echo "-- Done rsync-ing from '${SL_REPO_URL}'."
fi
if [ $RRES -ne 0 ]; then
echo "** Exiting."
cleanup
exit 1
fi
fi
if [ -f ${PKGFILE} ]; then
echo "-- Loading package list '$PKGFILE'."
else
echo "-- Mandatory package list file '$PKGFILE' is missing! Exiting."
cleanup
exit 1
fi
for PKGPAT in $(cat ${PKGFILE} |grep -v -E '^ *#|^$' |cut -d: -f1); do
# Extract the name of the package to install:
PKG=$(echo $PKGPAT |cut -d% -f2)
# Extract the name of the potential package to replace; if there is
# no package to replace then the 'cut' will make REP equal to PKG:
REP=$(echo $PKGPAT |cut -d% -f1)
# Look in ./patches ; then ./${DISTRO}$DIRSUFFIX ; then ./extra
# Need to escape any '+' in package names such a 'gtk+2':
if [ ! -z "${SL_PATCHROOT}" ]; then
FULLPKG=$(full_pkgname ${PKG} ${SL_PATCHROOT})
else
FULLPKG=""
fi
if [ "x${FULLPKG}" = "x" ]; then
FULLPKG=$(full_pkgname ${PKG} ${SL_PKGROOT})
else
echo "-- $PKG found in patches"
fi
if [ "x${FULLPKG}" = "x" ]; then
# One last attempt: look in ./extra
FULLPKG=$(full_pkgname ${PKG} $(dirname ${SL_PKGROOT})/extra)
fi
if [ "x${FULLPKG}" = "x" ]; then
echo "-- Package $PKG was not found in $(dirname ${SL_REPO}) !"
else
# Determine if we need to install or upgrade a package:
for INSTPKG in $(ls -1 "$2"/var/log/packages/${REP}-* 2>/dev/null |rev |cut -d/ -f1 |cut -d- -f4- |rev) ; do
if [ "$INSTPKG" = "$REP" ]; then
break
fi
done
if [ "$INSTPKG" = "$REP" ]; then
if [ "$PKG" = "$REP" ]; then
ROOT="$2" upgradepkg --reinstall "${FULLPKG}"
else
# We need to replace one package (REP) with another (FULLPKG):
ROOT="$2" upgradepkg "${REP}%${FULLPKG}"
fi
else
installpkg --terse --root "$2" "${FULLPKG}"
fi
fi
done
fi
if [ "$TRIM" = "doc" -o "$TRIM" = "mandoc" -o "$LIVEDE" = "XFCE" ]; then
# Remove undesired (too big for a live OS) document subdirectories:
(cd "${2}/usr/doc" && find . -type d -mindepth 2 -maxdepth 2 -exec rm -rf {} \;)
rm -rf "$2"/usr/share/gtk-doc
rm -rf "$2"/usr/share/help
find "$2"/usr/share/ -type d -name doc |xargs rm -rf
# Remove residual bloat:
rm -rf "${2}"/usr/doc/*/html
rm -f "${2}"/usr/doc/*/*.{html,css,xml,pdf,db,gz,bz2,xz,txt,TXT}
# Remove info pages:
rm -rf "$2"/usr/info
fi
if [ "$TRIM" = "mandoc" ]; then
# Also remove man pages:
rm -rf "$2"/usr/man
fi
if [ "$LIVEDE" = "XFCE" ]; then
# By pruning stuff that no one likely needs anyway,
# we make room for packages we would otherwise not be able to add.
# MySQL embedded is only used by Amarok:
rm -f "$2"/usr/bin/mysql*embedded*
# I am against torture:
rm -f "$2"/usr/bin/smbtorture
# Also remove some of the big unused/esoteric static libraries:
rm -rf "$2"/usr/lib${DIRSUFFIX}/{libaudiofile,libgdk,libglib,libgtk}.a
rm -rf "$2"/usr/lib${DIRSUFFIX}/{liblftp*,libnl}.a
rm -rf "$2"/usr/lib${DIRSUFFIX}/libboost*test*.a
# The llvm static libraries are not needed since we also ship the .so:
rm -rf "$2"/usr/lib${DIRSUFFIX}/lib{LLVM,clang,lldb}*.a
# And these are not needed for a simple XFCE ISO:
rm -rf "$2"/usr/lib${DIRSUFFIX}/clang/*/lib/linux/*.a{,.syms}
# Get rid of useless documentation:
rm -rf "$2"/usr/share/ghostscript/*/doc/
# We don't need tests or examples:
find "$2"/usr/ -type d -iname test |xargs rm -rf
find "$2"/usr/ -type d -iname "example*" |xargs rm -rf
# Get rid of most of the screensavers:
KEEPXSCR="julia xflame xjack"
if [ -d "${2}"/usr/libexec/xscreensaver ]; then
cd "${2}"/usr/libexec/xscreensaver
mkdir .keep
for XSCR in ${KEEPXSCR} ; do
mv ${XSCR} .keep/ 2>/dev/null
done
rm -rf [A-Za-z]*
mv .keep/* . 2>/dev/null
rm -rf .keep
cd - 1>/dev/null
fi
# Remove unneeded languages from glibc:
KEEPLANG="$(cat ${LIVE_TOOLDIR}/languages|grep -Ev "(^ *#|^$)"|cut -d: -f5)"
for LOCALEDIR in /usr/lib${DIRSUFFIX}/locale /usr/share/i18n/locales /usr/share/locale ; do
if [ -d "${2}"/${LOCALEDIR} ]; then
cd "${2}"/${LOCALEDIR}
mkdir .keep
for KL in C ${KEEPLANG} ; do
mv ${KL%%.utf8}* .keep/ 2>/dev/null # en_US.utf8 -> en_US*
mv ${KL%%_*} .keep/ 2>/dev/null # en_US.utf8 -> en
done
rm -rf [A-Za-z]*
mv .keep/* . 2>/dev/null
rm -rf .keep
cd - 1>/dev/null
fi
done
fi
# End install_pkgs
}
#
# Create the graphical multi-language syslinux boot menu:
#
function gen_bootmenu() {
MENUROOTDIR="$1/menu"
# Generate vesamenu structure - many files because of the selection tree.
mkdir -p ${MENUROOTDIR}
# Initialize an empty keyboard selection and language menu:
rm -f ${MENUROOTDIR}/kbd.cfg
rm -f ${MENUROOTDIR}/lang*.cfg
# Generate main (us) vesamenu.cfg: # MDrights modified the locale parameter in the default block of menu.tpl.
cat ${LIVE_TOOLDIR}/menu.tpl | sed \
-e "s/@KBD@/us/g" \
-e "s/@LANG@/us/g" \
-e "s/@CONSFONT@/$CONSFONT/g" \
-e "s/@DIRSUFFIX@/$DIRSUFFIX/g" \
-e "s/@DISTRO@/$DISTRO/g" \
-e "s/@CDISTRO@/${DISTRO^}/g" \
-e "s/@UDISTRO@/${DISTRO^^}/g" \
-e "s/@KVER@/$KVER/g" \
-e "s/@LIVEMAIN@/$LIVEMAIN/g" \
-e "s/@MEDIALABEL@/$MEDIALABEL/g" \
-e "s/@LIVEDE@/$(echo $LIVEDE |sed 's/BASE//')/g" \
-e "s/@SL_VERSION@/$SL_VERSION/g" \
-e "s/@VERSION@/$VERSION/g" \
-e "s/@KAPPEND@/$KAPPEND/g" \
> ${MENUROOTDIR}/vesamenu.cfg
for LANCOD in $(cat ${LIVE_TOOLDIR}/languages |grep -Ev "(^ *#|^$)" |cut -d: -f1)
do
LANDSC=$(cat ${LIVE_TOOLDIR}/languages |grep "^$LANCOD:" |cut -d: -f2)
KBD=$(cat ${LIVE_TOOLDIR}/languages |grep "^$LANCOD:" |cut -d: -f3)
# First, create keytab files if they are missing:
if [ ! -f ${MENUROOTDIR}/${KBD}.ktl ]; then
keytab-lilo $(find /usr/share/kbd/keymaps/i386 -name "us.map.gz") $(find /usr/share/kbd/keymaps/i386 -name "${KBD}.map.gz") > ${MENUROOTDIR}/${KBD}.ktl
fi
# Add this keyboard to the keyboard selection menu:
cat <<EOL >> ${MENUROOTDIR}/kbd.cfg
label ${LANCOD}
menu label ${LANDSC}
kbdmap menu/${KBD}.ktl
kernel vesamenu.c32
append menu/menu_${LANCOD}.cfg
EOL
# Generate custom vesamenu.cfg for selected keyboard:
cat ${LIVE_TOOLDIR}/menu.tpl | sed \
-e "s/@KBD@/$KBD/g" \
-e "s/@LANG@/$LANCOD/g" \
-e "s/@CONSFONT@/$CONSFONT/g" \
-e "s/@DIRSUFFIX@/$DIRSUFFIX/g" \
-e "s/@DISTRO@/$DISTRO/g" \
-e "s/@CDISTRO@/${DISTRO^}/g" \
-e "s/@UDISTRO@/${DISTRO^^}/g" \
-e "s/@KVER@/$KVER/g" \
-e "s/@LIVEMAIN@/$LIVEMAIN/g" \
-e "s/@MEDIALABEL@/$MEDIALABEL/g" \
-e "s/@LIVEDE@/$(echo $LIVEDE |sed 's/BASE//')/g" \
-e "s/@SL_VERSION@/$SL_VERSION/g" \
-e "s/@VERSION@/$VERSION/g" \
-e "s/@KAPPEND@/$KAPPEND/g" \
> ${MENUROOTDIR}/menu_${LANCOD}.cfg
# Generate custom language selection submenu for selected keyboard:
for SUBCOD in $(cat ${LIVE_TOOLDIR}/languages |grep -Ev "(^ *#|^$)" |cut -d: -f1) ; do
SUBKBD=$(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f3)
cat <<EOL >> ${MENUROOTDIR}/lang_${LANCOD}.cfg
label $(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f1)
menu label $(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f2)
EOL
if [ "$SUBKBD" = "$KBD" ]; then
echo " menu default" >> ${MENUROOTDIR}/lang_${LANCOD}.cfg
fi
cat <<EOL >> ${MENUROOTDIR}/lang_${LANCOD}.cfg
kernel /boot/generic
append initrd=/boot/initrd.img $KAPPEND load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 kbd=$KBD tz=$(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f4) locale=$(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f5) xkb=$(cat ${LIVE_TOOLDIR}/languages |grep "^$SUBCOD:" |cut -d: -f6)
EOL
done
done
}
#
# Create the grub menu file for UEFI boot:
#
function gen_uefimenu() {
GRUBDIR="$1"
# Generate the grub menu structure - many files because of the selection tree.
# I expect the directory to exist... but you never know.
mkdir -p ${GRUBDIR}
# Initialize an empty keyboard, language and timezone selection menu:
rm -f ${GRUBDIR}/kbd.cfg
rm -f ${GRUBDIR}/lang.cfg
rm -f ${GRUBDIR}/tz.cfg
# Generate main grub.cfg:
cat ${LIVE_TOOLDIR}/grub.tpl | sed \
-e "s/@KBD@/us/g" \
-e "s/@LANG@/us/g" \
-e "s/@CONSFONT@/$CONSFONT/g" \
-e "s/@DIRSUFFIX@/$DIRSUFFIX/g" \
-e "s/@DISTRO@/$DISTRO/g" \
-e "s/@CDISTRO@/${DISTRO^}/g" \
-e "s/@UDISTRO@/${DISTRO^^}/g" \
-e "s/@KVER@/$KVER/g" \
-e "s/@LIVEMAIN@/$LIVEMAIN/g" \
-e "s/@MEDIALABEL@/$MEDIALABEL/g" \
-e "s/@LIVEDE@/$(echo $LIVEDE |sed 's/BASE//')/g" \
-e "s/@SL_VERSION@/$SL_VERSION/g" \
-e "s/@VERSION@/$VERSION/g" \
-e "s/@KAPPEND@/$KAPPEND/g" \
> ${GRUBDIR}/grub.cfg
# Set a default keyboard selection:
cat <<EOL > ${GRUBDIR}/kbd.cfg
# Keyboard selection:
set default = $sl_lang
EOL
# Set a default language selection:
cat <<EOL > ${GRUBDIR}/lang.cfg
# Language selection:
set default = $sl_lang
EOL
# Create the remainder of the selection menus:
for LANCOD in $(cat languages |grep -Ev "(^ *#|^$)" |cut -d: -f1) ; do
LANDSC=$(cat languages |grep "^$LANCOD:" |cut -d: -f2)
KBD=$(cat languages |grep "^$LANCOD:" |cut -d: -f3)
XKB=$(cat languages |grep "^$LANCOD:" |cut -d: -f6)
LANLOC=$(cat languages |grep "^$LANCOD:" |cut -d: -f5)
# Add this entry to the keyboard selection menu:
cat <<EOL >> ${GRUBDIR}/kbd.cfg
menuentry "${LANDSC}" {
set sl_kbd="$KBD"
set sl_xkb="$XKB"
set sl_lang="$LANDSC"
export sl_kbd
export sl_xkb
export sl_lang
configfile \$grubdir/grub.cfg
}
EOL
# Add this entry to the language selection menu:
cat <<EOL >> ${GRUBDIR}/lang.cfg
menuentry "${LANDSC}" {
set sl_locale="$LANLOC"
set sl_lang="$LANDSC"
export sl_locale
export sl_lang
configfile \$grubdir/grub.cfg
}
EOL
done
# Create the timezone selection menu:
TZDIR="/usr/share/zoneinfo"
TZLIST=$(mktemp -t alientz.XXXXXX)
if [ ! -f $TZLIST ]; then
echo "*** Failed to create a temporary file!"
cleanup
exit 1
fi
# First, create a list of timezones:
# This code taken from Slackware script:
# source/a/glibc-zoneinfo/timezone-scripts/output-updated-timeconfig.sh
# Author: Patrick Volkerding <[email protected]>
# US/ first:
( cd $TZDIR
find . -type f | xargs file | grep "timezone data" | cut -f 1 -d : | cut -f 2- -d / | sort | grep "^US/" | while read zone ; do
echo "${zone}" >> $TZLIST
done
)
# Don't list right/ and posix/ zones:
( cd $TZDIR
find . -type f | xargs file | grep "timezone data" | cut -f 1 -d : | cut -f 2- -d / | sort | grep -v "^US/" | grep -v "^posix/" | grep -v "^right/" | while read zone ; do
echo "${zone}" >> $TZLIST
done
)
for TZ in $(cat $TZLIST); do
# Add this entry to the keyboard selection menu:
cat <<EOL >> ${GRUBDIR}/tz.cfg
menuentry "${TZ}" {
set sl_tz="$TZ"
export sl_tz
configfile \$grubdir/grub.cfg
}
EOL
rm -f $TZLIST
done
}
#
# Create an ISO file from a directory's content:
#
create_iso() {
TOPDIR=${1:-"${LIVE_STAGING}"}
cd "$TOPDIR"
# Tag the type of live environment to the ISO filename:
if [ "$LIVEDE" = "SLACKWARE" ]; then
ISOTAG=""
else
ISOTAG="-$(echo $LIVEDE |tr A-Z a-z)"
fi
# Determine whether we add UEFI boot capabilities to the ISO:
if [ -f boot/syslinux/efiboot.img -a "$USEXORR" = "NO" ]; then
UEFI_OPTS="-eltorito-alt-boot -no-emul-boot -eltorito-platform 0xEF -eltorito-boot boot/syslinux/efiboot.img"
elif [ -f boot/syslinux/efiboot.img -a "$USEXORR" = "YES" ]; then
UEFI_OPTS="-eltorito-alt-boot -e boot/syslinux/efiboot.img -no-emul-boot"
else
UEFI_OPTS=""
fi
# Time to determine the output filename, now that we know all the variables
# and ensured that the OUTPUT directory exists:
OUTFILE=${OUTFILE:-"${OUTPUT}/${DISTRO}${DIRSUFFIX}-live${ISOTAG}-${SL_VERSION}.iso"}
if [ "$USEXORR" = "NO" ]; then
mkisofs -o "${OUTFILE}" \
-V "${MEDIALABEL}" \
-R -J \
-hide-rr-moved \
-v -d -N \
-no-emul-boot -boot-load-size ${BOOTLOADSIZE} -boot-info-table \
-sort boot/syslinux/iso.sort \
-b boot/syslinux/isolinux.bin \
-c boot/syslinux/isolinux.boot \
${UEFI_OPTS} \
-preparer "$(echo $LIVEDE |sed 's/BASE//') Live built by ${BUILDER}" \
-publisher "The Slackware Linux Project - http://www.slackware.com/" \
-A "${DISTRO^}-${SL_VERSION} for ${SL_ARCH} ($(echo $LIVEDE |sed 's/BASE//') Live $VERSION)" \
-x ./$(basename ${LIVE_WORK}) \
-x ./${LIVEMAIN}/bootinst \
-x boot/syslinux/testing \
.
if [ "$SL_ARCH" = "x86_64" -o "$EFI32" = "YES" ]; then
# Make this a hybrid ISO with UEFI boot support on x86_64.
# On 32bit, the variable EFI32 must be explicitly enabled.
isohybrid -u "${OUTFILE}"
else
isohybrid "${OUTFILE}"
fi # End UEFI hybrid ISO.
else
echo "-- Using xorriso to generate the ISO and make it hybrid."
xorriso -as mkisofs -o "${OUTFILE}" \
-V "${MEDIALABEL}" \
-J -joliet-long -r \
-hide-rr-moved \
-v -d -N \
-b boot/syslinux/isolinux.bin \
-c boot/syslinux/isolinux.boot \
-boot-load-size ${BOOTLOADSIZE} -boot-info-table -no-emul-boot \
${UEFI_OPTS} \
-isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \
-isohybrid-gpt-basdat \
-preparer "$(echo $LIVEDE |sed 's/BASE//') Live built by ${BUILDER}" \
-publisher "The Slackware Linux Project - http://www.slackware.com/" \
-A "${DISTRO^}-${SL_VERSION} for ${SL_ARCH} ($(echo $LIVEDE |sed 's/BASE//') Live $VERSION)" \
-x ./$(basename ${LIVE_WORK}) \
-x ./${LIVEMAIN}/bootinst \
-x boot/syslinux/testing \
.
fi
# Return to original directory:
cd - 1>/dev/null
cd "${OUTPUT}"
md5sum "$(basename "${OUTFILE}")" \
> "$(basename "${OUTFILE}")".md5
cd - 1>/dev/null
echo "-- Live ISO image created:"
ls -l "${OUTFILE}"*
} # End of create_iso()
# ---------------------------------------------------------------------------
# Action!
# ---------------------------------------------------------------------------
while getopts "a:d:efhm:r:s:t:vz:GH:MO:R:X" Option
do
case $Option in
h )
echo "----------------------------------------------------------------"
echo "make_slackware_live.sh $VERSION"
echo "----------------------------------------------------------------"
echo "Usage:"
echo " $0 [OPTION] ..."
echo "or:"
echo " SL_REPO=/your/repository/dir $0 [OPTION] ..."
echo ""
echo "The SL_REPO is the directory that contains the directory"
echo " ${DISTRO}-<RELEASE> or ${DISTRO}64-<RELEASE>"
echo "Current value of SL_REPO : $SL_REPO"
echo ""
echo "The script's parameters are:"
echo " -h This help."
echo " -a arch Machine architecture (default: ${SL_ARCH})."
echo " Use i586 for a 32bit ISO, x86_64 for 64bit."
echo " -d desktoptype SLACKWARE (full Slack), KDE4 basic,"
echo " XFCE basic, PLASMA5, MATE, CINNAMON, DLACK."
echo " -e Use ISO boot-load-size of 32 for computers."
echo " where the ISO won't boot otherwise."
echo " -f Forced re-generation of all squashfs modules,"
echo " custom configurations and new initrd.img."
echo " -m pkglst[,pkglst] Add modules defined by pkglists/<pkglst>,..."
echo " -r series[,series] Refresh only one or a few package series."
echo " -s slackrepo_dir Directory containing ${DISTRO^} repository."
echo " -t <doc|mandoc> Trim the ISO (remove man and/or doc)."
echo " -v Show debug/error output."
echo " -z version Define your ${DISTRO^} version (default: $SL_VERSION)."
echo " -G Generate ISO file from existing directory tree"
echo " -H hostname Hostname of the Live OS (default: $LIVE_HOSTNAME)."
echo " -M Add multilib (x86_64 only)."
echo " -O outfile Custom filename for the ISO."
echo " -R runlevel Runlevel to boot into (default: $RUNLEVEL)."
echo " -X Use xorriso instead of mkisofs/isohybrid."
exit
;;
a ) SL_ARCH="${OPTARG}"
;;
d ) LIVEDE="$(echo ${OPTARG} |tr a-z A-Z)"
;;
e ) BOOTLOADSIZE=32
;;
f ) FORCE="YES"
;;
m ) SEQ_ADDMOD="${OPTARG}"
;;
r ) REFRESH="${OPTARG}"
;;
s ) SL_REPO="${OPTARG}"
;;
t ) TRIM="${OPTARG}"
;;
v ) DEBUG="YES"
;;
z ) SL_VERSION="${OPTARG}"
;;
G ) ONLY_ISO="YES"
;;
H ) LIVE_HOSTNAME="${OPTARG}"
;;
M ) MULTILIB="YES"
;;
O ) OUTFILE="${OPTARG}"
OUTPUT="$(cd $(dirname "${OUTFILE}"); pwd)"
;;
R ) RUNLEVEL=${OPTARG}
;;
X ) USEXORR="YES"
;;
* ) echo "You passed an illegal switch to the program!"
echo "Run '$0 -h' for more help."
exit
;; # DEFAULT
esac
done
# End of option parsing.
shift $(($OPTIND - 1))
# $1 now references the first non option item supplied on the command line
# if one exists.
# ---------------------------------------------------------------------------
[ "$DEBUG" = "NO" ] && DBGOUT="/dev/null" || DBGOUT="/dev/stderr"
# -----------------------------------------------------------------------------
# Some sanity checks first.
# -----------------------------------------------------------------------------
if [ -n "$REFRESH" -a "$FORCE" = "YES" ]; then
echo ">> Please use only _one_ of the switches '-f' or '-r'!"
echo ">> Run '$0 -h' for more help."
exit 1
fi
if [ "$ONLY_ISO" = "YES" -a "$FORCE" = "YES" ]; then
echo ">> Please use only _one_ of the switches '-f' or '-G'!"
echo ">> Run '$0 -h' for more help."
exit 1
fi
if [ $RUNLEVEL -ne 3 -a $RUNLEVEL -ne 4 ]; then
echo ">> Default runlevel other than 3 or 4 is not supported."
exit 1
fi
if [ "$SL_ARCH" != "x86_64" -a "$MULTILIB" = "YES" ]; then
echo ">> Multilib is only supported on x86_64 architecture."
exit 1
fi
# Directory suffix, arch dependent:
if [ "$SL_ARCH" = "x86_64" ]; then
DIRSUFFIX="64"
EFIFORM="x86_64"
EFISUFF="x64"
else
DIRSUFFIX=""
EFIFORM="i386"
EFISUFF="ia32"
fi
# Package root directory, arch dependent:
SL_PKGROOT=${SL_REPO}/${DISTRO}${DIRSUFFIX}-${SL_VERSION}/${DISTRO}${DIRSUFFIX}
DEF_SL_PKGROOT=${SL_PKGROOT}
# Patches root directory, arch dependent:
SL_PATCHROOT=${SL_REPO}/${DISTRO}${DIRSUFFIX}-${SL_VERSION}/patches/packages
DEF_SL_PATCHROOT=${SL_PATCHROOT}
# Are all the required add-on tools present?
[ "$USEXORR" = "NO" ] && ISOGEN="mkisofs isohybrid" || ISOGEN="xorriso"
PROG_MISSING=""
for PROGN in mksquashfs unsquashfs grub-mkfont syslinux $ISOGEN installpkg upgradepkg keytab-lilo rsync ; do
if ! which $PROGN 1>/dev/null 2>/dev/null ; then
PROG_MISSING="${PROG_MISSING}-- $PROGN\n"
fi
done
if [ ! -z "$PROG_MISSING" ] ; then
echo "-- Required program(s) not found in PATH!"
echo -e ${PROG_MISSING}
echo "-- Exiting."
exit 1
fi
# Check rsync progress report capability:
if [ -z "$(rsync --info=progress2 2>&1 |grep "unknown option")" ]; then
# Use recent rsync to display some progress:
RSYNCREP="--no-inc-recursive --info=progress2"
else
# Remain silent if we have an older rsync:
RSYNCREP=" "
fi
# Create output directory for image file:
mkdir -p "${OUTPUT}"
if [ $? -ne 0 ]; then
echo "-- Creation of output directory '${OUTPUT}' failed! Exiting."
exit 1
fi
# If so requested, we generate the ISO image and immediately exit.
if [ "$ONLY_ISO" = "YES" -a -n "${LIVE_STAGING}" ]; then
create_iso ${LIVE_STAGING}
cleanup
exit 0
else
# Remove ./boot - it will be created from scratch later:
rm -rf ${LIVE_STAGING}/boot
fi
# Cleanup if we are FORCEd to rebuild from scratch:
if [ "$FORCE" = "YES" ]; then
echo "-- Removing old files and directories!"
umount ${LIVE_ROOTDIR}/{proc,sys,dev} 2>${DBGOUT} || true
umount ${LIVE_ROOTDIR} 2>${DBGOUT} || true
rm -rf ${LIVE_STAGING}/${LIVEMAIN} ${LIVE_WORK} ${LIVE_ROOTDIR}
fi
# Create temporary directories for building the live filesystem:
for LTEMP in $LIVE_OVLDIR $LIVE_BOOT $LIVE_MOD_SYS $LIVE_MOD_ADD $LIVE_MOD_OPT ; do
umount ${LTEMP} 2>${DBGOUT} || true
mkdir -p ${LTEMP}
if [ $? -ne 0 ]; then
echo "-- Creation of temporary directory '${LTEMP}' failed! Exiting."
exit 1
fi
done
# Create the mount point for our Slackware filesystem:
if [ ! -d ${LIVE_ROOTDIR} ]; then