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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions prefsCleaner.sh
Expand Up @@ -2,12 +2,23 @@

## prefs.js cleaner for Linux/Mac
## author: @claustromaniac
## version: 1.6
## version: 1.7

## 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
CelestialNebula marked this conversation as resolved.
Show resolved Hide resolved
printf 'You should not 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.

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.

exit 1
fi

readonly CURRDIR=$(pwd)

## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed)
Expand Down Expand Up @@ -138,7 +149,7 @@ echo -e "\n\n"
echo " ╔══════════════════════════╗"
echo " ║ prefs.js cleaner ║"
echo " ║ by claustromaniac ║"
echo " ║ v1.6 ║"
echo " ║ v1.7 ║"
echo " ╚══════════════════════════╝"
echo -e "\nThis script should be run from your Firefox profile directory.\n"
echo "It will remove any entries from prefs.js that also exist in user.js."
Expand Down
13 changes: 12 additions & 1 deletion updater.sh
Expand Up @@ -2,12 +2,23 @@

## arkenfox user.js updater for macOS and Linux

## version: 3.5
## version: 3.6
## Author: Pat Johnson (@overdodactyl)
## Additional contributors: @earthlng, @ema-pe, @claustromaniac, @infinitewarp

## DON'T GO HIGHER THAN VERSION x.9 !! ( because of ASCII comparison in update_updater() )

# Check if running as root and if any files have the owner/group as root/wheel.
if [ "${EUID:-$(id -u)}" -eq 0 ]; then
CelestialNebula marked this conversation as resolved.
Show resolved Hide resolved
printf 'You should not 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 '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
exit 1
fi

readonly CURRDIR=$(pwd)

SCRIPT_FILE=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
Expand Down