A simple wrapper for the poweroff command to prevent you from doing stupid things
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
anna fbbb614930
fix license text and copyright
2 months ago
.gitignore initial commit uwu 2 months ago
Makefile initial commit uwu 2 months ago
README.md add usage hint 2 months ago
poweroff_guard.8 fix license text and copyright 2 months ago
poweroff_guard.c fix license text and copyright 2 months ago

README.md

poweroff_guard

This utility is a proxy for poweroff to prevent you from accidentally shutting down the wrong system. It does this by printing a warning message and asking for confirmation followed by a countdown before executing the actual command.

It is most useful when creating an alias for poweroff in your shell, like:

alias poweroff=/usr/local/sbin/poweroff_guard

Important Consideration

If the standard output is not a tty, this behaves exactly like the regular poweroff.

Build

Open a shell in this directory and type make. Optionally, you may want to append any of the following options:

  • POWEROFF_PATH=/path/to/poweroff: Specify a custom (absolute) path for the the real poweroff command. The default is to use the one in your $PATH.
  • COUNTDOWN_SECS=n: Start the countdown timer at n seconds, the default is 10.
  • EXTRA_CFLAGS=...: Append extra flags to the C compiler.

For example:

# build with default options
make
# build with all custom options
make \
	POWEROFF_PATH=/bin/custom_poweroff \
	COUNTDOWN_SECS=5 \
	EXTRA_CFLAGS="-O2 -march=native"

Watch out: If you want to recompile with different options, you MUST execute a make clean first. Make will erroneously think the binary is already up to date otherwise.

Installation

Do the exact same as building, but append install at the end of the command. For example:

# build and install with default options
make install
# build and install with all custom options
make \
	POWEROFF_PATH=/sbin/custom_poweroff \
	COUNTDOWN_SECS=5 \
	EXTRA_CFLAGS="-O2 -march=native" \
	install

Copyright © 2022 anna .

This program is licensed under the 2-clause BSD license. The license text is at the end of the poweroff_guard.c file.