blob: 5420f042d69e295cc726f14e98381767347ab030 (
plain) (
tree)
|
|
#!/bin/bash
source "$(dirname "${BASH_SOURCE[0]}")/scripts/rebash/core.sh"
core.import exceptions
core.import logging
core.import utils
core.import "$(core_abs_path "$(dirname "${BASH_SOURCE[0]}")/scripts/build.sh")"
# set log level via dracut logging options
_parse_dracut_args() {
local verbose=false
local debug=false
while true; do
case "$1" in
--stdlog)
shift
local level="$1"
shift
[[ "$level" -ge 4 ]] && debug=true
;;
--verbose)
shift
verbose=true
;;
'')
break
;;
*)
shift
;;
esac
local level
$verbose && level=info
$debug && level=debug
logging.set_level "$level"
logging.set_commands_level debug
done
$debug
return $?
}
_debug=0
_parse_dracut_args ${dracut_args[*]} || _debug=$?
clean() {
# NOTE: This method is currently triggered manually and not supported by
# dracut itself.
build_clean_xmount "$moddir/binaries/xmount/"
build_clean_qemu_xmount "$moddir/binaries/qemu-xmount/"
build_clean_dnbd3 "$moddir/binaries/dnbd3/"
build_clean_systemd_preserve_process_marker \
"$moddir/binaries/systemd-preserve-process-marker/"
return 0
}
check() {
exceptions.activate
# NOTE: xmount must be compiled before qemu_xmount
local xmount_is_built=true
if [[ ! -f "$moddir/binaries/xmount/trunk/build/src/xmount" ]]; then
if ! build_compile_xmount "$moddir/binaries/xmount/"; then
xmount_is_built=false
fi
fi
if $xmount_is_built && [[ \
! -f "$moddir/binaries/qemu-xmount/libxmount_input_qemu.so" \
]]; then
build_compile_qemu_xmount "$moddir/binaries/qemu-xmount/" || \
xmount_is_built=false
fi
$xmount_is_built || logging.warn \
"Compiling \"xmount\" failed -> No support for container files (only raw images)."
if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" ]] || \
[[ ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]
then
build_compile_dnbd3 "$moddir/binaries/dnbd3/"
[[ $? != 0 ]] && return 1
fi
if [[ ! -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then
build_compile_systemd_preserve_process_marker \
"$moddir/binaries/systemd-preserve-process-marker/"
[[ $? != 0 ]] && return 1
fi
# NOTE: This are workarounds for:
# - distributions where "systemd-udevd" doesn't lives in "/usr/lib" but in
# "/lib".
local alternate_systemd_udevd_location='/lib/systemd/systemd-udevd'
if [[ ! -f "${systemdutildir}/systemd-udevd" ]] && \
[[ -f "$alternate_systemd_udevd_location" ]]; then
mkdir --parents "${initdir}${systemdutildir}"
ln --symbolic --force "$alternate_systemd_udevd_location" \
"${initdir}${systemdutildir}/systemd-udevd"
#cp "$alternate_systemd_udevd_location" \
# "${initdir}${systemdutildir}/systemd-udevd" 1>&2
fi
# - "/usr/bin/sh" isn't available but "/bin/sh".
if [[ ! -f /usr/bin/sh ]] && [[ -f /bin/sh ]]; then
ln --symbolic --force /bin/sh /usr/bin/sh
fi
exceptions.deactivate
# Tell dracut that this module should only be included if it is required
# explicitly.
return 255
}
depends() {
# NOTE: btrfs module should be used if it would work.
echo base network bash kernel-modules shutdown
}
installkernel() {
inst "$moddir/binaries/dnbd3/build/dnbd3.ko" \
/usr/lib/modules/current/extra/dnbd3.ko
instmods dm_snapshot btrfs crc32c
}
install() {
# region binaries
inst "$moddir/binaries/dnbd3/build/dnbd3-client" /usr/bin/dnbd3-client
inst "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \
/usr/bin/systemd-preserve-process-marker
inst "$moddir/scripts/device-add-write-layer.sh" \
/usr/bin/device-add-write-layer
inst "$moddir/scripts/container-unpack-xmount.sh" \
/usr/bin/container-unpack-xmount
# xmount
local xmount_installation="$moddir/binaries/xmount/trunk/build/release_build"
inst "${xmount_installation}/usr/bin/xmount" /usr/bin/xmount
for file in ${xmount_installation}/usr/lib/xmount/*; do
inst "$file" /usr/lib/xmount/"$(basename "$file")"
done
inst "$moddir/binaries/qemu-xmount/libxmount_input_qemu.so" \
/usr/lib/xmount/libxmount_input_qemu.so
# endregion
# region hooks
inst_hook cmdline 00 "$moddir/hooks/enable-sysrq.sh"
inst_hook cmdline 10 "$moddir/hooks/prepare-kernel-command-line-parameter.sh"
inst_hook cmdline 90 "$moddir/hooks/set-dracut-environment-variables.sh"
# load dnbd3.ko
inst_hook pre-udev 00 "$moddir/hooks/load-custom-kernel-modules.sh"
# get the openslx config from the servers configured in the kernel command
# line (${SLX_SERVER}/${SLX_SERVER_BASE}/config)
inst_hook pre-mount 00 "$moddir/hooks/fetch-config.sh"
# make the final blockdevice for the root system (dnbd3 -> xmount ->
# device-mapper)
if dracut_module_included "systemd-initrd"; then
inst "$moddir/hooks/prepare-root-partition.sh" \
/usr/bin/dnbd3root
inst_simple "${moddir}/services/dnbd3root.service" \
"${systemdsystemunitdir}/dnbd3root.service"
mkdir --parents \
"${initdir}/${systemdsystemunitdir}/dracut-mount.service.requires"
ln_r "${systemdsystemunitdir}/dnbd3root.service" \
"${systemdsystemunitdir}/dracut-mount.service.requires/dnbd3root.service"
mkdir --parents \
"${initdir}/${systemdsystemunitdir}/initrd.target.requires"
ln_r "${systemdsystemunitdir}/dnbd3root.service" \
"${systemdsystemunitdir}/initrd.target.requires/dnbd3root.service"
# copy systemd services to new root (so they don't get killed after
# switch_root)
inst_hook pre-pivot 00 "$moddir/hooks/copy-dnbd3-service-into-newroot.sh"
inst_hook pre-pivot 00 "$moddir/hooks/copy-dracut-systemd-files-into-newroot.sh"
else
inst_hook pre-mount 10 "$moddir/hooks/prepare-root-partition.sh"
fi
inst_hook mount 10 "$moddir/hooks/mount-root-device.sh"
inst_hook pre-pivot 00 "$moddir/hooks/copy-openslx-configuration-into-newroot.sh"
#inst_hook pre-pivot 00 "$moddir/hooks/mount-tmp.sh"
# endregion
# region scripts
local file_path
for file_path in "$moddir/scripts/rebash/"*; do
inst "$file_path" "/usr/lib/rebash/$(basename "$file_path")"
done
# TODO currently not used
# This script is triggered by udev upon finding the right partitions for
# persistent sessions.
#inst "$moddir/scripts/prepare-persistent-disks" \
#/sbin/prepare-persistent-disks
# endregion
# region configuration files
# TODO currently not used
# Udev rules detecting 44, 45, 46 partitions and running
# "prepare-persistent-disks" to prepare persistent partitions.
#inst "$moddir/udev/70-openslx-disk.rules" /etc/udev/rules.d/70-openslx-disk.rules
# Use terminal readline settings from the template system.
inst /etc/inputrc /etc/inputrc
# endregion
if [[ "$_debug" == 0 ]]; then
inst_multiple lsblk ping ip ifconfig sshd htop tail head vim touch sed \
lsmod sleep route wget find lsof strace chroot switch_root pivot_root \
mount fdisk mkfs.xfs env busybox ps agetty tree \
insmod blockdev partx dmsetup sed cut awk tr insmod \
blockdev partx dmsetup cat cut awk losetup dd mkfs.ext4 grep \
basename dirname sort mktemp diff qemu-img genfstab mountpoint
else
inst_multiple insmod blockdev partx dmsetup sed cat cut awk tr touch \
losetup grep basename dirname mktemp diff sleep wget mount sort \
qemu-nbd bash genfstab mountpoint dd
fi
}
# region vim modline
# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:
# endregion
|