New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updater.sh/prefsCleaner.sh: Check for root and abort #1651
Conversation
Check if running as root and if any files have the owner/group as root|wheel. Abort on both. Should (hopefully) prevent stuff like: arkenfox#1587 Discussion: arkenfox#1595
Co-authored-by: Mohammed Anas <triallax@tutanota.com>
elif [ -n "$(find ./ -user 0 -o -group 0)" ]; then | ||
printf 'It looks like this script was previously run with elevated privileges, | ||
you will need to change ownership of the following files to your user:\n' | ||
find . -user 0 -o -group 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid running find . -user 0 -o -group 0
twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do:
pc_ROOT_ID="$(find . -user 0 -o -group 0)"
...
elif [ -n "${pc_ROOT_ID}" ]; then
...
printf '%s\n' "${pc_ROOT_ID}"
...
but I think this makes the code more indirect for no real gain.
Co-authored-by: Mohammed Anas <triallax@tutanota.com>
good idea, thanks! |
@@ -10,7 +10,7 @@ | |||
|
|||
# Check if running as root and if any files have the owner/group as root/wheel. | |||
if [ "${EUID:-"$(id -u)"}" -eq 0 ]; then | |||
printf 'You should not run this with elevated privileges (such as with doas/sudo).\n' | |||
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be escaped/quoted, otherwise it is a syntax error breaking the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' | |
printf 'You shouldn'"'"'t run this with elevated privileges (such as with doas/sudo).\n' |
|
||
## special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh | ||
|
||
## DON'T GO HIGHER THAN VERSION x.9 !! ( because of ASCII comparison in update_prefsCleaner() ) | ||
|
||
# Check if running as root and if any files have the owner/group as root/wheel. | ||
if [ "${EUID:-"$(id -u)"}" -eq 0 ]; then | ||
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, this is still incorrect and broken. You don't want single quotes here. As you will get this error:
line 13: syntax error near unexpected token `('
line 13: ` printf 'You shouldn\'t run this with elevated privileges (such as with doas/sudo).\n''
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' | |
printf "You shouldn't run this with elevated privileges (such as with doas/sudo).\n" |
Really ought to run these shell scripts through Shellcheck as well and fix the other errors.
if [ "${EUID:-"$(id -u)"}" -eq 0 ]; then | ||
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' | ||
exit 1 | ||
elif [ -n "$(find ./ -user 0 -o -group 0)" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This find check will cause issues when you want to run the script in another directory (not the current directory) ie option -p
printf 'You shouldn't run this with elevated privileges (such as with doas/sudo).\n' | ||
exit 1 | ||
elif [ -n "$(find ./ -user 0 -o -group 0)" ]; then | ||
printf 'It looks like this script was previously run with elevated privileges, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf 'It looks like this script was previously run with elevated privileges, | |
printf "It looks like this script was previously run with elevated privileges, | |
you will need to change ownership of the following files to your user:\n" |
Don't use single quotes.
Check if running as root and if any files have the owner/group as root|wheel. Abort on both.
Should (hopefully) prevent stuff like: #1587
Discussion: #1595
This does not attempt to correct the permissions, just notify the user
and abort.
If I followed #1587 right.
The original person didn't realize that it appended and subsequent
people tried to run with elevated privileges. This should at least fix
the second.