The rewrite is focused on the following five areas of interest:
1. Portability. The scripts have been tested to work in recent versions
of the following operating systems and shells: macOS, Linux (Fedora,
Debian, Ubuntu, openSUSE, Arch, Alpine, NixOS), BSD (FreeBSD,
OpenBSD, NetBSD, DragonFly), SunOS (Solaris, OpenIndiana), Haiku;
bash, dash, ash, ksh, oksh, zsh, XPG4 sh, pdksh, mksh, yash, posh,
gwsh, bosh, osh.
2. Robustness. Employ secure shell scripting techniques, incorporate
battle-tested open source code, clear all ShellCheck warnings, and
fail early.
3. Composability. Put (almost) everything inside functions and make the
scripts dot source friendly.
4. Consistency. Use tput to abstract away terminal color codes, write
templated diagnostic messages and follow conventions in the use of
exit status and redirections.
5. Readability. Comment extensively, assign descriptive names to
variables and functions, and use here-documents to ease reading and
writing multi-line messages.
Known behavioral changes:
1. There are changes to the way some options are parsed and acted on.
For example, when both the -l and -p options are specified, -l will
be ignored; in the old behavior, the last specified option would
take effect. Also, an old quirk where passing the argument 'list' to
-p was equivalent to specifying the -l option has been fixed.
2. The -h, -l and -p options of updater.sh have been added to
prefsCleaner.sh as well.
3. All temporary files are now created using mktemp and no longer
actively deleted, so users won't find them in the working directory
anymore in the case of error.
4. The old prefs.js cleaning logic, which relied on non-POSIX features,
is not preserved in the rewrite.
Resolves#1855Resolves#1446Fixes#1810
* updater.sh/prefsCleaner.sh: Check for root and abort
Check if running as root and if any files have the owner/group as root|wheel.
Abort on both.
Should (hopefully) prevent stuff like: https://github.com/arkenfox/user.js/issues/1587
Discussion: https://github.com/arkenfox/user.js/pull/1595
---------
Co-authored-by: Mohammed Anas <triallax@tutanota.com>
Co-authored-by: earthlng <earthlng@users.noreply.github.com>
- re-arrange the match patterns to fix the remaining issue of dropping lines after the 9999 block
- make it work on Mac too
- use `|` where possible so we don't need to escape the forward-slashes. That saves a few bytes and makes the pattern easier to read
see #1188
this should fix the issue that "All prefs after a multi-line comment declaration, on a single line, are deleted with the remove_comments function from the updater."
* 0 : successful termination
* 2 : command line syntax error
* 1 : catchall for general errors
Plus a few text improvements based on unmerged PR 4fbb2be98d
* rework DOWNLOAD_METHOD, download_file, open_file
* remove legacy command leftover line
* return empty string if download fails and return/exit if this happens and show error message
* fix IFS var typo
* bump version
* add quotes
Co-authored-by: TotallyLeGIT <bbkqx24kxlgvgbss@mailban.de>
when argument `-l` is used, parse profiles.ini instead of just listing folders in the default profiles dir.
This allows to select profiles located outside of the default profiles directory and makes selection easier because it also shows the profile name (and selection is by number instead of having to copy-paste a path)
* Uses `perl` as a last resort if `curl` and `wget` are not available (fixes#537)
* Aborts and notifies user if none of the above are installed
* Better use of functions
* When version numbers are checked, the contents are immediately saved to a temp dir. This allows us to skip using wget/curl/perl a second time
* Improved messages for users
* Added various font colors for ease of use and aesthetics
* updated shebang
* The script now compares its version number to the one online. If there is a newer version of `updater.sh` online it ask the user if he wants to download and run it.
* 2 parameters are supported: `-donotupdate` to disable the update-check and `-update` to auto-download and run the new version without asking
* Backup files are now saved to the directory `userjs_backups` instead of causing more bloat in the profile directory.
this should now work no matter how the script is called (including symlinks) on both Mac and Linux.
+ Storing and restoring the original working directory to prevent problems in certain circumstances.