2014-08-27 21:14:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
## live-build(7) - System Build Scripts
|
2020-03-11 09:07:21 -01:00
|
|
|
## Copyright (C) 2016-2020 The Debian Live team
|
2015-01-04 18:05:39 -01:00
|
|
|
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
|
2014-08-27 21:14:12 +00:00
|
|
|
##
|
|
|
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
|
|
|
## This is free software, and you are welcome to redistribute it
|
|
|
|
## under certain conditions; see COPYING for details.
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Including common functions
|
|
|
|
[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
|
|
|
|
|
|
|
|
# Setting static variables
|
2015-02-05 02:30:47 -01:00
|
|
|
DESCRIPTION="Execute hooks in chroot"
|
2014-08-27 21:14:12 +00:00
|
|
|
USAGE="${PROGRAM} [--force]"
|
|
|
|
|
2015-02-05 02:30:47 -01:00
|
|
|
# Processing arguments and configuration files
|
|
|
|
Init_config_data "${@}"
|
2014-08-27 21:14:12 +00:00
|
|
|
|
|
|
|
Echo_message "Begin executing hooks..."
|
|
|
|
|
|
|
|
# Requiring stage file
|
2020-03-15 12:05:44 -01:00
|
|
|
Require_stagefiles config bootstrap
|
2014-08-27 21:14:12 +00:00
|
|
|
|
|
|
|
# Checking stage file
|
2020-03-13 16:11:53 -01:00
|
|
|
Check_stagefile
|
2014-08-27 21:14:12 +00:00
|
|
|
|
2020-03-13 15:19:59 -01:00
|
|
|
# Acquire lock file
|
2015-02-05 02:30:47 -01:00
|
|
|
Acquire_lockfile
|
2014-08-27 21:14:12 +00:00
|
|
|
|
|
|
|
# Make build config available to chroot hooks. First, make the bind
|
|
|
|
# mount and then make it read-only. This can't happen in one mount
|
|
|
|
# command, then the resulting mount will be rw (see mount(8)). Making it
|
|
|
|
# ro prevents modifications and prevents accidentally removing the
|
|
|
|
# contents of the config directory when removing the chroot.
|
|
|
|
mkdir -p chroot/live-build/config
|
|
|
|
mount -o bind config chroot/live-build/config
|
|
|
|
mount -o remount,ro,bind config chroot/live-build/config
|
|
|
|
|
2023-03-04 08:26:02 -01:00
|
|
|
## Processing hooks
|
2020-10-12 18:26:16 +00:00
|
|
|
if ls config/hooks/normal/*.chroot > /dev/null 2>&1 && (
|
|
|
|
ls config/hooks/live/*.chroot > /dev/null 2>&1 ||
|
|
|
|
ls config/hooks/live/*.container > /dev/null 2>&1 )
|
2014-08-27 21:14:12 +00:00
|
|
|
then
|
2020-10-12 18:26:16 +00:00
|
|
|
# If a systemd-nspawn hook exists check if package is installed
|
|
|
|
if ls config/hooks/live/*.container > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
Check_package host /usr/bin/systemd-nspawn systemd-container
|
|
|
|
fi
|
|
|
|
|
2014-08-27 21:14:12 +00:00
|
|
|
# Restoring cache
|
2015-01-06 02:46:37 -01:00
|
|
|
Restore_package_cache chroot
|
2014-08-27 21:14:12 +00:00
|
|
|
|
2020-10-12 18:26:16 +00:00
|
|
|
for HOOK in config/hooks/normal/*.chroot config/hooks/live/*.chroot config/hooks/live/*.container
|
2014-08-27 21:14:12 +00:00
|
|
|
do
|
2015-05-20 06:19:39 +00:00
|
|
|
if [ ! -e "${HOOK}" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2014-08-27 21:14:12 +00:00
|
|
|
# Copying hook
|
2015-05-20 06:19:39 +00:00
|
|
|
cp "${HOOK}" chroot/root
|
2014-08-27 21:14:12 +00:00
|
|
|
|
|
|
|
# Making hook executable
|
2015-05-20 06:19:39 +00:00
|
|
|
if [ ! -x chroot/root/"$(basename ${HOOK})" ]
|
2014-08-27 21:14:12 +00:00
|
|
|
then
|
2015-05-20 06:19:39 +00:00
|
|
|
chmod +x chroot/root/"$(basename ${HOOK})"
|
2014-08-27 21:14:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Executing hook
|
2020-10-12 18:26:16 +00:00
|
|
|
Echo_message "Executing hook ${HOOK}..."
|
|
|
|
case "${HOOK}" in
|
|
|
|
*.container)
|
|
|
|
umount chroot/proc
|
2024-02-23 20:10:24 -01:00
|
|
|
systemd-nspawn --capability=all --register=no --keep-unit -D chroot "/root/$(basename ${HOOK})" || { Echo_error "${HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
|
2020-10-12 18:26:16 +00:00
|
|
|
mount proc-live -t proc chroot/proc
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
Chroot chroot "/root/$(basename ${HOOK})" || { Echo_error "${HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
|
|
|
|
;;
|
|
|
|
esac
|
2014-08-27 21:14:12 +00:00
|
|
|
|
|
|
|
# Removing hook
|
2015-05-20 06:19:39 +00:00
|
|
|
rm -f chroot/root/"$(basename ${HOOK})"
|
2014-08-27 21:14:12 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Saving cache
|
2015-01-06 02:46:37 -01:00
|
|
|
Save_package_cache chroot
|
2014-08-27 21:14:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove bind mount of build config inside chroot.
|
|
|
|
umount chroot/live-build/config
|
|
|
|
rmdir chroot/live-build/config
|
2015-06-05 21:15:19 +00:00
|
|
|
rmdir chroot/live-build
|
2020-03-12 00:38:58 -01:00
|
|
|
|
|
|
|
# Creating stage file
|
2020-03-13 16:11:53 -01:00
|
|
|
Create_stagefile
|