
# This oneshot service checks for /usr/bin/{reboot,poweroff,halt,shutdown}
# and if they are part of runit-void it renames them and copies the 66
# utilities in their place. It must be enabled, especially if one
# changes between the two init systems. There is a similar script for
# runit core-services that does the opposite and runs by default with runit.
# The service makes sure that the user has the proper utilities for the
# init system they are currently running.

[main]
@type = oneshot
@version = 0.0.3
@description = "Switch initutils"
@user = ( root )

[start]
@build = custom
@shebang = "/bin/sh -c"
@execute = ( 

poweroff_util=$(readlink -f /usr/bin/poweroff)

if grep -q "s6-svscan" /proc/1/cmdline && [ $(pgrep -u root 66-shutdownd) ]; then
        if [ "$poweroff_util" != /usr/bin/poweroff ]; then
		for i in reboot poweroff halt shutdown; do
            mv /usr/bin/${i} /usr/bin/${i}.runit
            cp /etc/66/${i} /usr/bin/${i}
            done
            fi
fi
)
