mklive.sh.in: add custom scripts to init

The added option -H <hooksdir> allows the user to specify a directory
that contains hook scripts which should be run directly after the live
system's init sequence.
This can be used to customize the system (such as e.g. setting a
different default shell)
This commit is contained in:
edr 2016-05-10 21:58:33 +02:00 committed by Michael Aldridge
parent 414ebf318f
commit 3c68cc4158

View File

@ -78,7 +78,8 @@ Options:
-o <file> Output file name for the ISO image (auto if unset). -o <file> Output file name for the ISO image (auto if unset).
-p "pkg pkgN ..." Install additional packages into the ISO image. -p "pkg pkgN ..." Install additional packages into the ISO image.
-I <includedir> Include directory structure under given path into rootfs -I <includedir> Include directory structure under given path into rootfs
-H <hooksdir> Add scripts in given directory as startup hooks to the init
procedure.
-C "cmdline args" Add additional kernel command line arguments. -C "cmdline args" Add additional kernel command line arguments.
-T "title" Modify the bootloader title. -T "title" Modify the bootloader title.
-K Do not remove builddir. -K Do not remove builddir.
@ -181,6 +182,13 @@ cleanup_rootfs() {
rm -r $ROOTFS/usr/lib/dracut/modules.d/01autoinstaller rm -r $ROOTFS/usr/lib/dracut/modules.d/01autoinstaller
} }
setup_init_hooks() {
hooks_dir=/usr/local/custom-scripts/
mkdir -p ${ROOTFS}${hooks_dir}
find $HOOKS_DIRECTORY -mindepth 1 -maxdepth 1 -exec cp -rfpPv {} ${ROOTFS}${hooks_dir} \;
echo 'find '${hooks_dir}' -type f -executable -exec {} \;' >> $ROOTFS/etc/rc.local
}
generate_isolinux_boot() { generate_isolinux_boot() {
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/ldlinux.c32 "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/ldlinux.c32 "$ISOLINUX_DIR"
@ -296,7 +304,7 @@ generate_iso_image() {
# #
# main() # main()
# #
while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:h" opt; do while getopts "a:b:r:c:C:T:Kk:l:i:I:H:s:S:o:p:h" opt; do
case $opt in case $opt in
a) BASE_ARCH="$OPTARG";; a) BASE_ARCH="$OPTARG";;
b) BASE_SYSTEM_PKG="$OPTARG";; b) BASE_SYSTEM_PKG="$OPTARG";;
@ -306,7 +314,8 @@ while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:h" opt; do
k) KEYMAP="$OPTARG";; k) KEYMAP="$OPTARG";;
l) LOCALE="$OPTARG";; l) LOCALE="$OPTARG";;
i) INITRAMFS_COMPRESSION="$OPTARG";; i) INITRAMFS_COMPRESSION="$OPTARG";;
I) INCLUDE_DIRECTORY="$OPTARG";; I) INCLUDE_DIRECTORY=$(cd "$OPTARG" && pwd);;
H) HOOKS_DIRECTORY=$(cd "$OPTARG" && pwd);;
s) SQUASHFS_COMPRESSION="$OPTARG";; s) SQUASHFS_COMPRESSION="$OPTARG";;
S) ROOTFS_FREESIZE="$OPTARG";; S) ROOTFS_FREESIZE="$OPTARG";;
o) OUTPUT_FILE="$OPTARG";; o) OUTPUT_FILE="$OPTARG";;
@ -359,7 +368,8 @@ GRUB_DIR="$BOOT_DIR/grub"
ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg" ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg"
CURRENT_STEP=0 CURRENT_STEP=0
STEP_COUNT=9 STEP_COUNT=9
[ -n "${INCLUDE_DIRECTORY}" ] && ((STEP_COUNT=STEP_COUNT+1)) [ -n "${INCLUDE_DIRECTORY}" ] && STEP_COUNT=$((STEP_COUNT+1))
[ -n "${HOOKS_DIRECTORY}" ] && STEP_COUNT=$((STEP_COUNT+1))
: ${SYSLINUX_DATADIR:=$VOIDHOSTDIR/usr/share/syslinux} : ${SYSLINUX_DATADIR:=$VOIDHOSTDIR/usr/share/syslinux}
: ${GRUB_DATADIR:=$VOIDHOSTDIR/usr/share/grub} : ${GRUB_DATADIR:=$VOIDHOSTDIR/usr/share/grub}
@ -412,6 +422,9 @@ generate_grub_efi_boot
print_step "Cleaning up rootfs..." print_step "Cleaning up rootfs..."
cleanup_rootfs cleanup_rootfs
print_step "Creating startup hooks..."
setup_init_hooks
print_step "Generating squashfs image ($SQUASHFS_COMPRESSION) from rootfs..." print_step "Generating squashfs image ($SQUASHFS_COMPRESSION) from rootfs..."
generate_squashfs generate_squashfs