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
prefsCleaner.sh (for Linux/Mac) #405
Conversation
Make sure you let CHEF-KOCH know, so he can plagiarize it |
Really appreciate this @claustromaniac! I did a quick test (nothing extensive) and it seems to work great! My only comment/suggestion after a quick run would be about the shebang. Instead of When using the first, I noticed two "problems" on macOS (neither of huge concern, admittedly):
|
Thanks @overdodactyl. I had my share of doubts about the shebang. I'll change it right away :) |
Little off topic here (I can open a new issue if that's preferable), but what's your guy's opinion on integrating the cleaners and updaters through some means? Couple possibilities would be to combine into one script, another would be for the updater to call/execute the cleaner script after it updates to the latest user.js. |
For me it would be nice if the updater could detect the presence of the cleaner and call it. Maybe with a prompt after the updating is over. |
Or better yet, a prompt before the updating even begins. |
Before would be ideal I think! Might be nice to show the prompt even if it isn't present...if that's the case, the script would download the cleaner script, make it executable and eventually run it. Similar idea to the code lines here: https://github.com/overdodactyl/ShadowFox/blob/master/scripts/ShadowFox_updater_linux.sh#L113-L129 If you think there might be frequent updates to the cleaner script, the updater could also run a check for version number and install the latest one if necessary. Similar to lines here: https://github.com/overdodactyl/ShadowFox/blob/master/scripts/ShadowFox_updater_mac.sh#L50-L67 |
If someone doesn't want to use the cleaner for some reason they would get that prompt continuously, unless we managed to make it happen only once somehow (like with a config file or something). I think I would rather add a message in the updater informing users that it can now launch the cleaner if it's present. It could even be a read-this-while-you-wait sort of message, to make it even less intrusive.
Frankly, I tried my best to make both this and the windows version of the cleaner as complete and robust as I could from the beginning so I wouldn't have to push many updates in the future, but I don't think that's a bad idea at all. It could be a worthy addition, or at least it wouldn't hurt. |
Would definitely be a bother to be asked each time, that's a good point. I do wonder if there are many use cases where one wouldn't want to use the cleaner though? |
You and me both. But if such use cases exist, I won't want to be pushy :) |
I like the idea but why would before be better than after?
IMO it would be nice to prompt if the cleaner is present and maybe show a message if it isn't. Something like "You may want to reset deprecated/removed prefs now. Check out our prefsCleaner scripts." with a link to 1 of our wiki pages. |
It wouldn't be better by itself. I was thinking that if we added a prompt like "Would you like to run the prefsCleaner afterwards?" and I added a parameter to the cleaners so they can run unattended, the users would then be allowed to walk away after all those prompts and leave the thing doing its business. Neither the updaters nor the cleaners take long to run, though, so it might not be worth it. IDK. It was just a thought. |
Oh okay, yeah that makes sense. |
|
https://stackoverflow.com/questions/229551/string-contains-in-bash
^^ 87 upvotes. I know you're currently using
this way you don't need the asterisks around |
Yes, in double quotes, so $1 expands. 👍
As keen as always, I see. That was a total oversight on my part. Thanks :) I'll look into it.
The problem I saw with that is the prefnames include special characters (most notably DOT), that would have to be escaped (I think). I initially considered using arrays for that, but I figured the overhead would be worse since I would have to loop over the whole array once for each line in prefs.js. Also, the code wouldn't look as clean that way IMO. IDK. |
good point, I didn't think about that |
prefsCleaner.sh
Outdated
## create backup folder if it doesn't exist | ||
mkdir -p userjs_backups; | ||
bakfile="userjs_backups/prefs.js.backup.$(date +"%Y-%m-%d_%H%M")" | ||
mv prefs.js "${bakfile}" && echo -e "\nprefs.js backed up: $bakfile" |
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.
Another bit borrowed from @overdodactyl's code. This got me thinking... should I add more code comments to this thing? I usually add them very sparingly (never really got used to it).
prefsCleaner.sh
Outdated
while [ -e webappsstore.sqlite-shm ] | ||
do | ||
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" | ||
read -p "Press any key to continue." |
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.
Not fully convinced about this part. It's all or nothing. Thinking ahead, it might be better to do the check just once (not looping) in case webappsstore.sqlite-shm
becomes a permanent file someday.
The script doesn't work in my linux vm. Haven't you tested it? I have to say I'm a bit disappointed :) The problem is that the 1st And does it really need the This works for me and produces the same prefs.js as the Windows version when ran against the same prefs.js and user.js: grep -E "${prefexp}" user.js >/tmp/userjs_updater_temp.dat
while read line; do
## blah blah
done < /tmp/userjs_updater_temp.dat |
|
prefsCleaner.sh
Outdated
mv prefs.js "${bakfile}" | ||
if [ ! $? ]; then | ||
fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile" | ||
fi |
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.
mv prefs.js "${bakfile}" || fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile"
?
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.
Yeah, I originally wrote it the other way around (if it doesn't fail do stuff). The if clause was a remnant of it. Didn't think it through.
@earthlng Did you even test the thing ONLY removing the As I said, I don't mind writing the temp file but I really wish I could understand your vm lol |
Yeah sorry about that. The VM is a very old and never-updated snapshot of an already running archlinux. 🤦♂️ But yes I tested all kinds of things and nothing except what I wrote above worked. |
Alright, I trust you. I'll just archive this X file and move on then. |
@overdodactyl I'm using the same subfolder as the updater for the backups (even though the name is userjs_backups). What do you think? Would you rather have them in separate folders? |
Woohoo! wrapping it in double-quotes works! done <<< "`grep -E "$prefexp" user.js`" works with and without |
Damn I'm sooo sorry man, now you already wasted even more time making changes for me! SOOOORRY |
Nah, don't be sorry. I'd say it's great that you had that issue with the script and not random users, since you could find a solution. Thanks 👍
Most of the time, probably not. Unless there is some weird way it can break the logic (not aware of any), it's better to leave it there. It's just to interpret backlashes literally. |
I prefer If you're happy with that, I'm ready to commit it. |
That's why I asked @overdodactyl about it (read above). I don't really care about the name of the folder but if I were to have them spawn in a subfolder, I'd rather have them in the same subfolder as the user.js backups created by the updater. (I didn't pick the name of the folder). It doesn't matter anyway. That can be changed anytime. Feel free to merge this if you want. |
Thanks @claustromaniac ! |
Glad to contribute. Thanks for all the input, as always. |
np, thanks for your patience |
Hi @claustromaniac you caught me while real life was giving me a beating. But since I asked for this, I wanted to thank you. I just now ran it on my main profile and, as far as I can tell, it worked great. So thanks. Cheers. |
I hope real life is treating you better now, and I'm glad the script works well for you. Be sure to let me know if you ever have any issues with it or if you think it can be improved. I'll try to make some of the changes discussed here as soon as I manage to escape my current procrastination cycle, so don't be shy. |
hello @claustromaniac :) fFF_check() {
# there are many ways to see if firefox is running or not, some more reliable than others
# this isn't elegant and might not be future-proof but should at least be compatible with any environment
while [ -e webappsstore.sqlite-shm ]; do
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n"
read -p "Press any key to continue."
done
} i don't think this is working - i never see this message if i run the script while FF is running would something like this be better perhaps? ... |
Confirming:
Alternative I would suggest to use |
in that case something like this maybe ???... iFile=`ls "$sFirefoxDir" | grep '^lock$' | wc -l` |
Does |
Yes
No |
i don't have any *shm files in the profile folder on linux |
@rusty-snake are you on linux too, or Mac? |
Linux |
look for `lock` file instead of `webappsstore.sqlite-shm` to detect if firefox is running or not (with this profile) see #405 (comment) and follow-up comments. Thanks @atomGit for reporting the issue and @rusty-snake for confirming it.
okay, done. Thanks guys |
look for `lock` file instead of `webappsstore.sqlite-shm` to detect if firefox is running or not (with this profile) see arkenfox/user.js#405 (comment) and follow-up comments. Thanks @atomGit for reporting the issue and @rusty-snake for confirming it.
Long overdue port of the prefsCleaner.bat for Unix-like systems. I was bored and had the time for it so.. why not?
This is my very first shell script ever, and I have only tested it with a minimal Cygwin install, so all feedback is very welcome. I did my best aiming for compatibility and reliability but, being a beginner and all, it would surprise me if this couldn't be improved still.
Bear in mind that I couldn't let go of bash-only syntax completely, so this won't work in other shells.
@1xPdd, I hope you're still up for testing.
Download link for the lazy ones.(the PR was merged, grab the one in this repository instead)