moved sudo checking and command execution to separate functions
This commit is contained in:
parent
3e22f4ebbd
commit
eddbe307c2
31
pman.sh
31
pman.sh
@ -7,6 +7,24 @@ command=""
|
|||||||
more_arguments=false
|
more_arguments=false
|
||||||
su_needed=false
|
su_needed=false
|
||||||
|
|
||||||
|
# If sudo is needed and necessary (and installed), prepend it, if not installed throw error
|
||||||
|
check_sudo() {
|
||||||
|
if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then
|
||||||
|
if command -v "sudo" &>/dev/null; then
|
||||||
|
command="sudo $command"
|
||||||
|
else
|
||||||
|
echo "sudo command needed but not found" > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute the command
|
||||||
|
execute_command() {
|
||||||
|
check_sudo
|
||||||
|
$command $command_args "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
# Check if yay (aur)
|
# Check if yay (aur)
|
||||||
if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then
|
if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then
|
||||||
command="yay"
|
command="yay"
|
||||||
@ -81,15 +99,4 @@ elif [ "$more_arguments" = "true" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If sudo is needed and necessary (and installed), prepend it, if not installed throw error
|
execute_command "${@}"
|
||||||
if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then
|
|
||||||
if command -v "sudo" &>/dev/null; then
|
|
||||||
command="sudo $command"
|
|
||||||
else
|
|
||||||
echo "sudo command needed but not found" > /dev/stderr
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Execute the command
|
|
||||||
$command $command_args "${@}"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user