#!/bin/sh locald_dir=/etc/local.d cd "${locald_dir}" || exit 1 svc_dir=/run/systemd/generator wan_dir=${svc_dir}/multi-user.target.wants mkdir -p "${svc_dir}" "${wan_dir}" || exit 1 previous= for f in *.start *.stop; do case "${f}" in *.start) is_start=1 fn=${f%.start} start_cmd="/usr/bin/env ${locald_dir}/${f}" stop_cmd=/bin/true if [ -f "${fn}".stop ]; then stop_cmd="/usr/bin/env ${locald_dir}/${fn}.stop" fi ;; *.stop) is_start= fn=${locald_dir}/${f%.stop} start_cmd=/bin/true stop_cmd="/usr/bin/env ${f}" ;; esac # omit .stop files which have matching .start files [ -z "${is_start}" -a -e "${fn}.start" ] && continue svc_file=gentoo-local-${fn}.service cat > "${svc_dir}/${svc_file}" <<_EOF_ [Unit] Description=Service for local.d/${fn}.* After=multi-user.target graphical.target ${previous} ConditionFileIsExecutable=${locald_dir}/${f} [Service] Type=forking RemainAfterExit=on TimeoutSec=0 ExecStart=${start_cmd} ExecStop=${stop_cmd} _EOF_ ln -s "../${svc_file}" "${wan_dir}/${svc_file}" previous=${svc_file} done