blob: 253c878b04f0f784548d2d84dd7bc5adee7bdeed [file] [log] [blame] [raw]
#!/bin/sh
# Fake root with reminder
# Copyright 2015-2023 Rivoreo
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
kernel_name="`uname -s`"
is_running_systemd_system_mode() {
local f
[ "$kernel_name" = Linux ] || return
f="`readlink /proc/1/exe`" || return
f="${f% (deleted)}"
[ "${f##*/}" = systemd ] && return
[ -S /run/systemd/private ] || systemctl is-enabled basic.target > /dev/null 2>&1
}
is_running_busybox_init() {
local f
[ "$kernel_name" = Linux ] || return
f="`readlink /proc/1/exe`" || return
f="${f% (deleted)}"
case "${f##*/}" in
busybox|busybox-*)
true
;;
*)
false
;;
esac
}
if is_running_systemd_system_mode; then
for c in reboot halt poweroff; do eval "${c}_command='systemctl $c'"; done
shutdown_reminder="Please use 'systemctl {reboot|halt|poweroff}' instead"
elif is_running_busybox_init; then
for c in reboot halt poweroff; do eval "${c}_command='busybox $c'"; done
shutdown_reminder="Please use 'busybox {reboot|halt|poweroff}' instead"
elif [ -x /sbin/telinit ]; then
reboot_command="telinit 6"
halt_command=
poweroff_command="telinit 0"
shutdown_reminder="Please use 'telinit <runlevel>' instead"
else
reboot_command="init 6"
halt_command=
poweroff_command="init 0"
shutdown_reminder="Please use 'init <runlevel>' instead"
fi
c="${0##*/}"
case "$c" in
reboot|halt|poweroff)
echo "This command is a no-op"
eval "replacement=\$${c}_command"
if [ -n "$replacement" ]; then
printf "Please use '%s' instead if you really want to do this\\n" "$replacement"
else
echo "It is no longer available on this system"
fi
;;
shutdown)
printf 'This command is a no-op\n%s\n' "$shutdown_reminder"
;;
*)
printf 'Command %s not supported\n' "$c"
;;
esac 1>&2
false