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

create install script #81

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a1e88f8
create install script
DanielSGH Feb 9, 2023
41ac13d
add variables to top for easy configuration
DanielSGH Feb 9, 2023
5c028ce
detect profile folder automatically
DanielSGH Feb 9, 2023
58b032a
add uninstall option
DanielSGH Feb 9, 2023
9888aed
edit README.md
DanielSGH Feb 9, 2023
0c341de
clean up and optimize pref-setting method
DanielSGH Feb 10, 2023
bcf1ea1
README.md fix linux/macos install section
DanielSGH Feb 11, 2023
a9cd914
detect if firefox is running
DanielSGH Feb 11, 2023
7e0ba72
check dev edition
DanielSGH Feb 15, 2023
366f9a9
check if firefox running before uninstall
DanielSGH Feb 15, 2023
8779076
add windows install.ps1
DanielSGH Feb 16, 2023
3d5d7a9
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Feb 16, 2023
77a7866
*nix: MacOS fixes, better active profile assumptions, colors
DanielSGH Feb 16, 2023
ce08109
Windows: add same check method for active profile
DanielSGH Feb 16, 2023
240b302
Update README.md for Windows users
DanielSGH Feb 17, 2023
ce32c02
Merge branch 'main' into create-install-script
DanielSGH Dec 23, 2023
5c280b8
unpack repo tarball, add optional tweaks support, fix macOS issues, r…
DanielSGH Dec 24, 2023
55869dc
add easier (un)installation instructions in README.md
DanielSGH Dec 25, 2023
1e646e6
append user.js file (or create it if it doesn't exist) instead of ove…
DanielSGH Dec 25, 2023
038ecf7
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Dec 25, 2023
82c9592
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Dec 26, 2023
2df1f9a
Windows: made equivalent to linux bash script + uninstall removes use…
DanielSGH Dec 26, 2023
f1e020b
fix bug: Tee-Object produced poorly encoded text
DanielSGH Dec 26, 2023
3c6b806
change install instructions for windows powershell
DanielSGH Dec 26, 2023
3904b78
Linux: when uninstalling, user.js lines are removed, not the whole file.
DanielSGH Dec 26, 2023
6e7237d
Linux: add reviewing of settings before removal from user.js in unins…
DanielSGH Dec 27, 2023
34ed2b3
Windows: add reviewing of settings before removal from user.js in uni…
DanielSGH Dec 27, 2023
83de61c
Remove comments from README.md install instructions
DanielSGH Dec 28, 2023
e554a3d
add quotes to macOS FIREFOX_DIR path
DanielSGH Dec 28, 2023
beba1e3
use mktemp to manage temporary directory
DanielSGH Dec 28, 2023
35a56ff
create ask_question function to simplify code
DanielSGH Dec 29, 2023
17f27f2
Windows: remove error message for Copy-Item and Remove-Item
DanielSGH Dec 29, 2023
36ca23d
Windows: add ask_question function
DanielSGH Dec 29, 2023
24a8a7b
Windows: System.IO fix for appending, append_to_file function, defaul…
DanielSGH Dec 29, 2023
e8eaba6
Linux: set default option to 'yes' in uninstall
DanielSGH Dec 29, 2023
85b7be3
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Dec 29, 2023
bf54faf
Linux: revert delete_pref to use regex again
DanielSGH Dec 29, 2023
723cbd8
Linux: optionally delete_pref in prefs.js too, don't add user pref if…
DanielSGH Dec 30, 2023
73ba064
Windows: add option to remove prefs from prefs.js too and create backups
DanielSGH Dec 30, 2023
8142087
Windows: revert append_to_file function
DanielSGH Dec 30, 2023
f1a1894
Windows: don't add user preff if already exists in user.js
DanielSGH Dec 30, 2023
49a4f16
Windows: fix error with Contains() when user.js doesn't exist
DanielSGH Dec 31, 2023
272b2c2
Windows: remove macOS pref from OPTIONALS array
DanielSGH Dec 31, 2023
f15ab72
Linux: remove 'tee' command from installation process
DanielSGH Dec 31, 2023
a90eb56
Linux: add quotes around PROFILE_ROOTDIR variables
DanielSGH Dec 31, 2023
635e88a
Linux: remove grep error messages, fix reset_all variable
DanielSGH Dec 31, 2023
67e9fbd
remove bash 3.2 dependency from uninstall process
DanielSGH Dec 31, 2023
7bbe534
add portable version of sed
DanielSGH Dec 31, 2023
c078f2f
only ask to remove optional pref if exists
DanielSGH Dec 31, 2023
fc5f89e
Windows: only ask to remove optional pref if exists
DanielSGH Dec 31, 2023
6eec232
Linux: add to_lowercase function
DanielSGH Dec 31, 2023
16f7235
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Jan 9, 2024
73d11c0
Merge branch 'bmFtZQ:main' into create-install-script
DanielSGH Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ A Firefox userChrome.css theme that aims to recreate the look and feel of Micros
Screenshot: macOS / Firefox 120 / Tweaks: rounded corners, hide forward button.

## How to install
### Via Linux and macOS shell script
Paste this into your terminal emulator:
```sh
DanielSGH marked this conversation as resolved.
Show resolved Hide resolved
bash -c "$(curl -fsSL https://raw.githubusercontent.com/bmFtZQ/edge-frfox/HEAD/install.sh)"
```
Attach `-s uninstall` at the end of this command to uninstall.

### Via Windows Powershell script
Paste this into powershell:
```ps
powershell -nop -ExecutionPolicy Bypass -c "Invoke-Command -ScriptBlock ([scriptblock]::Create([System.Text.Encoding]::UTF8.GetString((New-Object Net.WebClient).DownloadData('https://raw.githubusercontent.com/bmFtZQ/edge-frfox/HEAD/install.ps1'))))"
```
Attach `-ArgumentList $('uninstall')` **inside the quotes** at the end to uninstall.

### Manual Installation
1. Go to `about:support` and click the "Open Folder/Show in Finder" button for the root directory of your browser profile.
2. Download the repository and extract the files.
3. From the repository folder, copy the `chrome` folder and `user.js` file into your Firefox profile folder.
Expand Down
186 changes: 186 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Get-ExecutionPolcy = "Restricted" by default

# VARIABLES, CHANGE AS NEEDED
$GITHUB_REPO="https://github.com/bmFtZQ/edge-frfox.git"
$PROJECT_NAME=$($GITHUB_REPO.Split("/")[-1] -replace ".git", "")
$FIREFOX_DIR="$env:APPDATA\Mozilla\Firefox";
$PROFILE_ROOTDIR="$($FIREFOX_DIR)\Profiles\$((Select-String -Path "$($FIREFOX_DIR)\profiles.ini" -Pattern "Path=.*\.(dev-edition-default|default-.*)" | Select-Object -Last 1).Line.Substring(14))";
$OPTIONALS=@{
"browser.theme.dark-private-windows" = "false"
Copy link
Owner

Choose a reason for hiding this comment

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

While we're here, add the new optional preference for Windows: browser.theme.windows.accent-color-in-tabs.enabled = true.

};

# UTILITY FUNCTIONS
function set_pref {
param (
$Pref,
$Bool
)

Write-Output "setting $pref to $bool in user.js";
$path="$PROFILE_ROOTDIR\user.js"
$output=(Write-Output "user_pref(`"$pref`", $bool);" | % { $_ -replace ' +$','' })
[System.IO.File]::AppendAllLines([string]$path, [string[]]$output)
}

function delete_pref {
param (
$Pref,
$Bool
)

Write-Output "resetting $Pref to default";
(Get-Content "$PROFILE_ROOTDIR\user.js").Replace($Pref, "") |
Set-Content -Path "$PROFILE_ROOTDIR\user.js";

if ($Bool) {
(Get-Content "$PROFILE_ROOTDIR\prefs.js").Replace($Pref, "") |
Set-Content -Path "$PROFILE_ROOTDIR\prefs.js";
}
}

function ask_question {
param($prompt, $defaultAns)

$userInput = (Read-Host -Prompt "$prompt").ToLower()
$userInput = if (-not $userInput) { $defaultAns } else { $userInput }

$userInput -eq 'yes' -or $userInput -eq 'y'
}

#####################
# PRE-INSTALL PHASE #
#####################

$firefox_proc=Get-Process firefox -ErrorAction SilentlyContinue;
if ($firefox_proc) {
Write-Host "ERROR: Before installing, please make sure firefox is not running.`nOtherwise, changes cannot be made to user.js" -ForegroundColor Red;
exit 0;
}

# Prompting for correct install directory
Write-Output "
Please enter the path to your firefox profile directory.
This can be found by opening about:support in firefox and looking for the Profile root directory.
Press CTRL+C to abort installation now."
Write-Host "Automatically detected: $PROFILE_ROOTDIR" -ForegroundColor Cyan;
Write-Output "Press ENTER to use this directory, or type in a new one.";
$ans=Read-Host "Path";
$PROFILE_ROOTDIR=($PROFILE_ROOTDIR,$ans)[[bool]$ans];

if (!(Test-Path "$PROFILE_ROOTDIR")) {
Write-Host "ERROR: firefox profile directory could not be found..." -ForegroundColor Red;

do {
$PROFILE_ROOTDIR=Read-Host -Prompt "Enter active root directory found in about:support here";
if (!(Test-Path "$PROFILE_ROOTDIR")) {
Write-Host "invalid directory: specified location does not exist. Try again..." -ForegroundColor Red;
}
} while (!(Test-Path "$PROFILE_ROOTDIR"));
}

# Check if issued `...\installer.sh uninstall`
if ($args[0] -eq "uninstall") {
Write-Host "NOTE: This is the final opportunity to abort uninstallation by pressing Ctrl+C" -ForegroundColor Yellow;
Remove-Item "$PROFILE_ROOTDIR\chrome" -Recurse -Confirm:$true -Force -ErrorAction SilentlyContinue;

$reset_all = ask_question "Reset settings in about:config to default? (a backup of user.js and prefs.js will be created if yes) [y/N]: " "n";
if ($reset_all) {
Copy-Item "$PROFILE_ROOTDIR\user.js" "$PROFILE_ROOTDIR\user.js.bak"
Copy-Item "$PROFILE_ROOTDIR\prefs.js" "$PROFILE_ROOTDIR\prefs.js.bak"
}

# Download changed user.js from online
$fail=$false
Invoke-Webrequest -Uri "https://raw.githubusercontent.com/bmFtZQ/edge-frfox/main/user.js" -UseBasicParsing -OutFile "$env:temp\user.js"
if (!($?)) {
Write-Host "WARNING: Failed to retrieve online user.js prefs. Continuing..." -ForegroundColor Yellow
$fail=$true
}

Write-Output "uninstalling...";
if (!$fail) {
$FETCHED_PREFS= @()
$FETCHED_PREFS += Select-String -Path "$env:temp\user.js" -Pattern "user_pref\(`"([a-zA-Z0-9.-]+)`",\s*(true|false)\);" | ForEach-Object {$_.Line -replace ".*\\", ""}
foreach ($pref in $FETCHED_PREFS) {
delete_pref "$pref" $reset_all;
}
}

$ans = "y"
Write-Host "NOTE: enter 'a' to answer 'yes' to all questions." -ForegroundColor Cyan
Copy link
Owner

Choose a reason for hiding this comment

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

Same thing as mentioned in the bash shell script.

foreach ($key in $OPTIONALS.Keys) {
$setting = "user_pref(`"${key}`", $($OPTIONALS[$key]));"

if (-not ($ans.ToLower() -match "^(all|a)$")) {
if (!(Get-Content "$PROFILE_ROOTDIR\user.js").Contains($setting)) {
continue
}

$ans = "y"
$in = Read-Host -Prompt "Remove setting $setting from user.js? [Y/a/n]"
$ans = if ($in) { $in.ToLower() } else { $ans }

if (-not ($ans -match "^(yes|y|all|a)$")) {
continue
}
}

delete_pref "$setting" $reset_all;
}

Write-Output "uninstall complete.";
exit 0;
}

#################
# INSTALL PHASE #
#################

Write-Output "Installing...";
Write-Output "Downloading source code...";

$response = Invoke-WebRequest -Uri "https://github.com/bmFtZQ/edge-frfox/archive/refs/heads/main.zip" -OutFile "$env:temp\edge-frfox.zip"
if (!($?)) {
Write-Host "ERROR: Failed to download source code from https://github.com/bmFtZQ/edge-frfox/archive/refs/heads/main.zip." -ForegroundColor Red;
Write-Host "$($response.StatusCode)"
exit 0;
}

Expand-Archive -Path "$env:temp\$PROJECT_NAME.zip" -DestinationPath "$env:temp" -Force
if (!($?)) {
Write-Host "ERROR: Failed to extract $env:temp\$PROJECT_NAME.zip." -ForegroundColor Red;
Write-Host "Message: $($Error[0].Exception.Message)";
exit 0;
}

Write-Host "Copying theme folder..."
Copy-Item -Recurse -Path "$env:temp\$PROJECT_NAME-main\chrome" -Destination $PROFILE_ROOTDIR -Force
$path="$PROFILE_ROOTDIR\user.js"
(Get-Content "$env:temp\$PROJECT_NAME-main\user.js") | ForEach-Object {
if (Test-Path "$path") {
if (! (Get-Content "$path").Contains($_)) {
[System.IO.File]::AppendAllLines([string]$path, [string[]]$_)
}
} else {
[System.IO.File]::AppendAllLines([string]$path, [string[]]$_)
}
}

# firefox will automatically sort out any duplicate issues, whatever is at the end of the file takes priority, so this works.
Write-Output "Setting preferences...";
foreach ($key in $OPTIONALS.Keys) {
$path="$PROFILE_ROOTDIR\user.js";
if (Test-Path "$path") {
if ((Get-Content $path).Contains("user_pref(`"${key}`", $($OPTIONALS[$key]));")) {
continue
}
}

if (!(ask_question "Set $key to $($OPTIONALS[$key])? [y/N]" "n")) {
continue
}

set_pref "$key" "$($optionals[$key])";
}

Write-Host "Installation complete! Please start firefox to see the changes.`n" -ForegroundColor Green;
190 changes: 190 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/bin/bash

# VARIABLES, CHANGE AS NEEDED
GITHUB_REPO="https://github.com/bmFtZQ/edge-frfox.git"
PROJECT_NAME=$(basename $GITHUB_REPO | cut -d '.' -f 1)

if [[ $OSTYPE == "darwin"* ]]; then
FIREFOX_DIR="$HOME/Library/Application Support/Firefox"
else
FIREFOX_DIR=$HOME/.mozilla/firefox
fi;

PROFILE_ROOTDIR=$FIREFOX_DIR/$(grep -E "Path=.*\.(dev-edition-default|default-.*)" "$FIREFOX_DIR/profiles.ini" | tail -1 | cut -c 6-);
OPTIONALS=(
"widget.macos.native-context-menus" "false"
"browser.theme.dark-private-windows" "false"
Copy link
Owner

Choose a reason for hiding this comment

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

Same as in the powershell script, but with widget.gtk.rounded-bottom-corners.enabled = true instead.

)

# COLORS
GREEN='\033[0;32m'
YELLOW='\033[0;93m'
NC='\033[0m'
CYAN='\033[0;36m'
RED='\033[0;31m'

# UTILITY FUNCTIONS
set_pref() {
echo "setting $1 to $2 in user.js";
echo "user_pref(\"$1\", $2);" >> "$PROFILE_ROOTDIR/user.js";
}

delete_pref() {
echo "resetting $(echo $1 | cut -d '"' -f 2) to default";
case $(sed --help 2>&1) in
*GNU*) sed_i () { sed -i "$@"; };;
*) sed_i () { sed -i '' "$@"; };;
esac

sed_i "/$1/d" "$PROFILE_ROOTDIR/user.js"

if $2; then
sed_i "/$1/d" "$PROFILE_ROOTDIR/prefs.js"
fi;
}

to_lowercase() {
echo "$1" | tr "[:upper:]" "[:lower:]"
}

ask_question() {
local defaultAns="$2"

read -e -p "$1" in
defaultAns="${in:-$defaultAns}";
defaultAns="$(to_lowercase "$defaultAns")"
[[ $defaultAns =~ ^(yes|y)$ ]];
}

#####################
# PRE-INSTALL PHASE #
#####################

firefox_proc=$(pgrep firefox);
if [ ! -z $firefox_proc ]; then
echo "Before (un)installing, please make sure firefox is not running."
echo "Otherwise, changes cannot be made to user.js"
exit 0;
fi

# Prompting for correct install directory
echo "Please enter the path to your firefox profile directory."
echo "This can be found by opening about:support in firefox and looking for the Profile root directory."
echo "Press CTRL+C to abort installation now."

echo -e "${CYAN}Automatically detected: $PROFILE_ROOTDIR${NC}"
read -e -p "Press ENTER to use this directory, or type in a new one: " newdir
PROFILE_ROOTDIR="${newdir:-$PROFILE_ROOTDIR}"

if [ ! -d "$PROFILE_ROOTDIR" ]; then
echo "ERROR: firefox profile directory could not be found"

while [ ! -d "$PROFILE_ROOTDIR" ]; do
read -p "Enter active root directory found in \"about:profiles\" here: " PROFILE_ROOTDIR;

if [ ! -d "$PROFILE_ROOTDIR" ]; then
echo "invalid directory: specified location does not exist. Try again..."
fi
done;
fi

# Check if issued `./installer.sh uninstall`
if [[ $1 == "uninstall" ]]; then
echo -e "${YELLOW}NOTE: This is the final opportunity to abort uninstallation by pressing Ctrl+C${NC}";
if ask_question "Delete all files in $PROFILE_ROOTDIR/chrome? [Y/n]: " "y"; then
rm -rf "$PROFILE_ROOTDIR/chrome";
fi;

if ask_question "Reset settings in about:config to default? (a backup of user.js and prefs.js will be created if yes) [y/N]: " "n"; then
reset_all=true;
else
reset_all=false;
fi;

if $reset_all; then
cp "$PROFILE_ROOTDIR/prefs.js" "$PROFILE_ROOTDIR/prefs.js.bak";
cp "$PROFILE_ROOTDIR/user.js" "$PROFILE_ROOTDIR/user.js.bak";
fi;

# Download changed user.js from online
FETCHED_PREFS=();
if ping -c 1 raw.githubusercontent.com &> /dev/null; then
while read l;
do FETCHED_PREFS+=("$l");
done < <(curl -s "https://raw.githubusercontent.com/bmFtZQ/edge-frfox/main/user.js" | grep -E "user_pref\(\"([a-zA-Z0-9.-]+)\",\s*(true|false)\);")
else
echo -e "${YELLOW}WARNING: Failed to retrieve online user.js prefs. Continuing...${NC}"
fi;

for ((i = 0; i < ${#FETCHED_PREFS[@]}; i++)); do
delete_pref "${FETCHED_PREFS[i]}" $reset_all;
done;

ans="y"
echo -e "${CYAN}NOTE: enter 'a' to answer 'yes' to all questions.${NC}";
Copy link
Owner

Choose a reason for hiding this comment

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

The following section does not seem to work in either Linux or macOS it shows the prompt, but then nothing happens. The next line printed to the terminal is uninstall complete.

I think this section can just be removed, deleting the contents of user.js can just be handled by the other section (if the user input yes for that question).

for ((i = 0; i < ${#OPTIONALS[@]}; i+=2)); do
setting="user_pref(\"${OPTIONALS[i]}\", ${OPTIONALS[i+1]});";

if [[ ! "$ans" =~ ^(all|a)$ ]]; then
if ! grep -qF "$setting" "$PROFILE_ROOTDIR/user.js" --no-messages; then
continue;
fi;

ans="y"
read -e -p "Remove setting $setting from user.js? [Y/a/n]: " in
ans="${in:-$ans}";
ans=$(to_lowercase "$ans");

if [[ ! "$ans" =~ ^(yes|y|all|a)$ ]]; then
continue;
fi
fi;

delete_pref "$setting" $reset_all;
done;

echo "uninstall complete."
exit 0;
fi

#################
# INSTALL PHASE #
#################

echo "Installing..."
TMP_DIR=$(mktemp -d -t "$PROJECT_NAME.XXXXXX");
if ! curl -L "https://github.com/bmFtZQ/edge-frfox/archive/refs/heads/main.tar.gz" | tar xz -C $TMP_DIR --strip-components=1; then
echo -e "${RED}Installation failed: ${NC}Failed to get github repo tarball and extract it";
exit 0;
fi

echo "Copying theme folder...";
cp -r $TMP_DIR/chrome "$PROFILE_ROOTDIR";
cat $TMP_DIR/user.js |
while read line; do
path="$PROFILE_ROOTDIR/user.js";
if ! grep -qF "$line" "$path" --no-messages; then
echo "$line" >> "$path";
fi;
done;

#####################
# OPTIONAL SETTINGS #
#####################

echo "Optional settings, refer to https://github.com/bmFtZQ/edge-frfox/tree/main#how-to-install";
for ((i = 0; i < ${#OPTIONALS[@]}; i += 2)); do
if grep -qF "user_pref(\"${OPTIONALS[i]}\", ${OPTIONALS[i+1]});" "$PROFILE_ROOTDIR/user.js" --no-messages; then
continue;
fi;

if ! ask_question "Set ${OPTIONALS[i]} to ${OPTIONALS[i+1]}? [y/N]: " "n"; then
continue;
fi;

set_pref ${OPTIONALS[i]} ${OPTIONALS[i+1]}

done;


echo -e "${GREEN}Finished successfully! Please start firefox to see the changes.";