diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..46b9a35 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +PREFIX?=/usr/local +DESTDIR?= +INSTALL?=install + +SCRIPTS = "kreboot" + +.PHONY: all +all: + @echo "Nothing to build, it is all bash :)" + @echo "Try make install" + +.PHONY: install +install: + $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin/ + $(INSTALL) -m 755 $(SCRIPTS) $(DESTDIR)$(PREFIX)/bin + +.PHONY: uninstall +uninstall: + ./uninstall $(DESTDIR)$(PREFIX)/bin/ $(SCRIPTS) diff --git a/kreboot b/kreboot index e7875c9..26b1b3d 100755 --- a/kreboot +++ b/kreboot @@ -6,6 +6,7 @@ set -u # defaults wait=10 +detach_wait=3 usage() { cat << EOF @@ -13,6 +14,7 @@ Usage: kreboot [option ...] [kernel|boot-index] Options are: --wait, -w N wait N seconds before reboot (default $wait) --nowait don't wait, reboot immediately + --detach Schedule reboot and return. Suitable to remote reboot. --help, -h show this help message Example: @@ -48,6 +50,19 @@ while test $# -gt 0; do --nowait) wait=0 ;; + --detach) + detach=yes + ;; + --detach_wait) + if [ "$#" -lt 2 ]; then + uerr "Option $1 requires an argument" + fi + detach_wait=$2 + if ! printf "%f" $detach_wait > /dev/null 2>&1; then + uerr "Option $1 argument not a number" + fi + shift + ;; -h|--help) usage 0 ;; @@ -85,4 +100,9 @@ if [ "$wait" -ne 0 ]; then sleep $wait fi kexec -l "$kernel" --initrd="$initrd" --command-line="root=$root $args" -systemctl kexec + +if [ -z "detach" ]; then + systemctl kexec +else + setsid bash -c "sleep $detach_wait; systemctl kexec" &>/dev/null < /dev/null & +fi