You are not logged in.
I am writing a script that will request superuser authorization during execution and continue execution. I have an error when requesting rights, but I can't figure out at what point it happens. The fact is that the TS_DIRECTORY variable resets the previously entered data after requesting sudo rights. I ask for help:
#!/bin/sh
SRC_PATH=$(pwd)/build
PACKAGES=./packages.list
read -ep "Путь расположения корневого каталога: " TS_DIRECTORY
DST_PATH=$TS_DIRECTORY/build
if [ "$(id -nu)" != "root" ]; then
sudo --reset-timestamp
read -sp "Для выполнения необходимо ввести пароль суперпользователя: " PASSWORD
exec sudo --stdin --prompt '' "$0" "$@" <<< "$PASSWORD"
exit 1
fi
if [ ! -e $TS_DIRECTORY ]; then
echo "Указанной директории не существует!"
exit 1
fi
echo $TS_DIRECTORY
echo $DST_PATH
Offline
https://man.archlinux.org/man/core/sudo … e-env=list
But you may just want to move the priv elevation to the top and I also don't understand why you read the password into a variable?
Offline
I also don't understand why you read the password into a variable?
To create a huge security hole, of course!
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
So this reads something into TS_DIRECTORY, then launches itself with sudo (thus prompting the user again for TS_DIRECTORY), no? Or what exactly is said "error"?
By the way: Both `read -p` and `<<<` are not POSIX features, so the `#!/bin/sh` shebang isn't correct (and it would fail if /bin/sh is symlinked against something that doesn't support those).
They look like bash/zsh features, so #!/bin/bash or #!/usr/bin/zsh (or the variant with /usr/bin/env) would be correct.
Offline