Compare commits

...

5 Commits

Author SHA1 Message Date
the-sane
2dd9b51ab1 Clarify error message 2023-01-20 19:38:02 -05:00
the-sane
dd9bfc3351 Clarify error message 2023-01-20 19:27:31 -05:00
the-sane
b009265951 Improve try_exec error handling 2023-01-20 19:26:25 -05:00
the-sane
394cfa9392 Improve comment 2023-01-20 19:15:51 -05:00
the-sane
5b2e202b4f Fix try_exec failure detection 2023-01-20 19:13:27 -05:00

View File

@ -233,7 +233,7 @@ debug_print() {
# Try to execute a supplied command as root
# Expects one string argument
try_exec() {
# This function expects one string arguments
# This function expects one string argument
if [ "$#" -lt 1 ]; then
printf "\nScript error: The try_exec() function expects an argument. Aborting.\n"
read -n 1 -s -p "Press any key..."
@ -245,19 +245,25 @@ try_exec() {
if [ -x "$(command -v pkexec)" ]; then
pkexec sh -c "$1"
# Check the return value
if [ "$?" -eq 126 ] || [ "$?" -eq 127 ]; then
# Check the exit status
statuscode="$?"
if [ "$statuscode" -eq 126 ] || [ "$statuscode" -eq 127 ]; then
# User cancel or error
retval=1
fi
else
elif [ -x "$(command -v sudo)" ]; then
sudo sh -c "$1"
# Check the return value
if [ "$?" -eq 1 ]; then
# Check the exit status
statuscode="$?"
if [ "$statuscode" -eq 1 ]; then
# Error
retval=1
fi
else
# We don't know how to perform this operation with elevated privileges
printf "\nNeither Polkit nor sudo appear to be installed. Unable to execute the command with the required privileges.\n"
retval=1
fi
return "$retval"
@ -2074,7 +2080,7 @@ eac_workaround() {
# Try to modify /etc/hosts as root
try_exec "printf '\n$eac_hosts #Star Citizen EAC workaround\n' >> /etc/hosts"
if [ "$?" -eq 1 ]; then
message info "Something went wrong. Unable to modify /etc/hosts.\n\nReturning to main menu."
message info "Authentication failed or there was an error modifying /etc/hosts.\nSee terminal for more information.\n\nReturning to main menu."
return 0
fi