diff options
-rwxr-xr-x | build-initramfs.sh | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/build-initramfs.sh b/build-initramfs.sh index e41a642a..5b5e9597 100755 --- a/build-initramfs.sh +++ b/build-initramfs.sh @@ -348,6 +348,76 @@ initialize_dracut() { ./configure || exit 1 make dracut-install || exit 1 make dracut-util + # add a few handy functions to dracut + if ! [ -s dracut-init.sh ]; then + echo "no dracut-init.sh" + exit 1 + fi + # One tab then 4 spaces, tab will get removed by -EOF + cat >> dracut-init.sh <<-"EOF" + + slx_service() { + local _name _desc _tmpfile + declare -a _before=() _after=() _requires=() _wants=() + _name="$1" + _desc="$2" + shift 2 + while (( $# > 0 )); do + case "$1" in + --wbefore) + _wants+=("$2") + ;& + --before) + _before+=("$2") + ;; + --wafter) + _wants+=("$2") + ;& + --after) + _after+=("$2") + ;; + --wants) + _wants+=("$2") + ;; + --requires) + _requires+=("$2") + ;; + *) + dfatal "Invalid option: '$1'" + exit 10 + esac + shift 2 + done + if [ -z "$_desc" ]; then + dfatal "Cannot install service without description" + exit 1 + fi + mkdir --parents "${initdir}/usr/local/slx-services" + _tmpfile="/tmp/dracut-service-$RANDOM" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/slx-services/${_name}.sh" || exit 10 + { + echo "[Unit]" + echo "Description=${_desc}" + [ -n "${_wants}" ] && echo "Wants=${_wants[*]}" + [ -n "${_requires}" ] && echo "Requires=${_requires[*]}" + [ -n "${_before}" ] && echo "Before=${_before[*]}" + [ -n "${_after}" ] && echo "After=${_after[*]}" + echo "" + echo "[Service]" + echo "Type=oneshot" + echo "RemainAfterExit=yes" + echo "ExecStart=/usr/local/slx-services/${_name}.sh" + } > "${_tmpfile}" + inst_simple "${_tmpfile}" \ + "${systemdsystemunitdir}/${_name}.service" || exit 10 + rm -f -- "${_tmpfile}" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd.target.wants" || exit 10 + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/initrd.target.wants/${_name}.service" || exit 10 + } + EOF popd || exit 1 return $? } |