PXE icon indicating copy to clipboard operation
PXE copied to clipboard

Improvement suggestion for iventoy.sh

Open EvilSupahFly opened this issue 6 months ago • 0 comments

The iventoy.sh script is pretty handy, but rather than have it terminate if not being run as root, like this:

uid=$(id -u)
if [ $uid -ne 0 ]; then
    echo "Please use sudo or run the script as root."
    exit 1
fi

I suggest doing this instead:

# Check if script is being run as root, and if not,
# Call script with sudo and pass original arguments
[[ $EUID -ne 0 ]] && exec sudo "$0" "$@"

This way, if you didn't run as root, the script call sudo to prompt you for the password and re-run itself with all your original arguments.

EvilSupahFly avatar Aug 23 '24 01:08 EvilSupahFly