Skip to content
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

Merged
merged 5 commits into from Apr 22, 2023

Conversation

CelestialNebula
Copy link
Contributor

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.

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
prefsCleaner.sh Outdated Show resolved Hide resolved
updater.sh Outdated Show resolved Hide resolved
Co-authored-by: Mohammed Anas <triallax@tutanota.com>
prefsCleaner.sh Outdated Show resolved Hide resolved
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

updater.sh Outdated Show resolved Hide resolved
@earthlng
Copy link
Contributor

good idea, thanks!

@earthlng earthlng merged commit f2e4a79 into arkenfox:master Apr 22, 2023
@@ -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'
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'
Copy link

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''
Suggested change
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
Copy link

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,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants