#!/bin/bash cmd=${0##*/} dashf= for arg in "$@"; do case "$arg" in -*f*) dashf=1 ;; esac case "$arg" in -*p*) [ "$cmd" = halt ] && cmd=poweroff ;; esac done [ "$dashf" ] || exec -a "$0" /sbin/halt.distrib "$@" read pids < /run/sendsigs.omit.d/samizdat for p in $pids; do if [ -e /proc/$p/root -a ! /proc/$p/root -ef / ]; then initramfs=/proc/$p/root break fi done panic() { set -x sync exec -a "$0" /sbin/halt.distrib "$@" } [ "$initramfs" ] || panic cp /sbin/init $initramfs/telinit # Apparently, linux does not allow a direct bind mount of a file on # the initramfs. Therefore, copy the file from the initramfs and bind # mount the copy. mount -o remount,exec /run cp $initramfs/lib/samizdat/init.shutdown /run/ && mount --bind /run/init.shutdown /sbin/init || panic echo $cmd -f > $initramfs/halt $initramfs/telinit u