diff --git a/README.md b/README.md index 24bbb4c..5de87ac 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,29 @@ A Firefox userChrome.css theme that aims to recreate the look and feel of the Ch thumbnail screenshot ## How to install +### Via Linux and MacOS shell script +Paste this into your terminal emulator: +```sh +# Linux may not have $TMPDIR set by default +TMP_DIR="${TMPDIR:-$(dirname $(mktemp))}" + +curl https://raw.githubusercontent.com/bmFtZQ/edge-frfox/create-install-script/install.sh > $TMP_DIR/installer.sh && chmod +x $TMP_DIR/installer.sh && sh $TMP_DIR/installer.sh +``` + +### Via Windows Powershell script +**NOTE**: You may need to `Set-ExecutionPolicy RemoteSigned` for this to work, by default, windows will use `Restricted`. +1. Open Powershell as Administrator +2. Type `Set-ExecutionPolicy RemoteSigned` +3. It might ask you to confirm, you should read the contents of [install.ps1](https://raw.githubusercontent.com/bmFtZQ/edge-frfox/create-install-script/install.ps1) and the script below to verify it for yourself. +4. Close out of Powershell and start a new normal instance of Powershell (good practice) +5. Paste the following into powershell and hit enter: +```ps +(curl -Uri https://raw.githubusercontent.com/bmFtZQ/edge-frfox/create-install-script/install.ps1 -UseBasicParsing).Content > $env:temp/installer.ps1; powershell $env:temp\installer.ps1 +``` + +Uninstallation can be done by just writing `uninstall` as a parameter above, so `.../installer.sh uninstall` or `...\installer.ps1 uninstall` for macos/linux and windows respectively + +### Manual Installation 1. Go to `about:support` and click the "Open Folder/Show in Finder" button for the root directory of your browser profile/s. 2. Download and copy the `chrome` folder into the profile folder. 3. Go to about:config and change these preferences: diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..85fd55a --- /dev/null +++ b/install.ps1 @@ -0,0 +1,118 @@ +# 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))"; +$CHANGED_PREFS=@("toolkit.legacyUserProfileCustomizations.stylesheets", "svg.context-properties.content.enabled", "layout.css.color-mix.enabled"); + +# UTILITY FUNCTIONS +function set_pref { + param ( + $Pref, + $Bool + ) + + Write-Output "setting $pref to $bool in prefs.js"; + "user_pref(`"$pref`", $bool);" | out-file "$PROFILE_ROOTDIR/prefs.js" -Encoding ASCII -append +} + +function delete_pref { + param ( + $Pref + ) + + $Prefsjs="$PROFILE_ROOTDIR\prefs.js"; + + Write-Output "resetting $Pref to default"; + (Get-Content -Path $Prefsjs) | + ForEach-Object {$_ -Replace "user_pref\(\`"$Pref\`", (true|false)\);", ''} | + Set-Content -Path $Prefsjs; +} + +##################### +# 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 prefs.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]; + +# Check if issued `...\installer.sh uninstall` +if ($args[0] -eq "uninstall") { + Remove-Item "$PROFILE_ROOTDIR/chrome" -Recurse -Confirm:$true; + + Write-Output "uninstalling..."; + foreach ($pref in $CHANGED_PREFS) { + delete_pref $pref; + } + + Write-Output "uninstall complete."; + exit 0; +} + +Write-Output "Checking if git is installed..."; +if (!(Get-Command git -ErrorAction SilentlyContinue)) { + Write-Host "ERROR: git not found... Please install git and try again." -ForegroundColor Red; + exit 0; +} + +Write-Output "Detecting if firefox is installed on your system..." +if (!(Test-Path $FIREFOX_DIR)) { + Write-Host "ERROR: firefox not found..." -ForegroundColor Red; + + Write-Output "Do you want to continue anyway?"; + $continue=Read-Host -Prompt "y/n"; + + if (!("$continue".ToLower() -match "^(y|yes)$")) { + Write-Output "Aborting installation..."; + exit 0; + } +} + +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")); +} + +################# +# INSTALL PHASE # +################# + +Write-Output "Installing..."; +if (!(Test-Path "$("$env:temp\$PROJECT_NAME")")) { + Write-Output "Cloning $GITHUB_REPO into $env:temp\$PROJECT_NAME..."; + + git clone $GITHUB_REPO "$env:temp\$PROJECT_NAME"; +} + +Write-Output "Copying files to $PROFILE_ROOTDIR\chrome..."; +Remove-Item "$PROFILE_ROOTDIR\chrome" -Recurse -ErrorAction SilentlyContinue -Confirm:$false -Force; +Copy-Item "$env:temp\$PROJECT_NAME\chrome" -Destination $PROFILE_ROOTDIR -Recurse -Force; + +# 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 ($pref in $CHANGED_PREFS) { + set_pref $pref "true"; +} + +Write-Host "Installation complete! Please start firefox to see the changes.`n" -ForegroundColor Green; diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..c83fbe9 --- /dev/null +++ b/install.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +# VARIABLES, CHANGE AS NEEDED +GITHUB_REPO="https://github.com/bmFtZQ/edge-frfox.git" +PROJECT_NAME=$(basename $GITHUB_REPO | cut -d '.' -f 1) +TMP_DIR="${TMPDIR:-$(dirname $(mktemp))}" + +if [[ $OSTYPE == "darwin"* ]]; then + FIREFOX_DIR=$HOME/Library/Application\ Support/Firefox/Profiles +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-); +CHANGED_PREFS=("toolkit.legacyUserProfileCustomizations.stylesheets" "svg.context-properties.content.enabled" "layout.css.color-mix.enabled") + +# COLORS +GREEN='\033[0;32m' +YELLOW='\033[0;93m' +NC='\033[0m' +CYAN='\033[0;36m' + +# UTILITY FUNCTIONS +set_pref() { + echo "setting $1 to $2 in prefs.js"; + echo "user_pref(\"$1\", $2);" >> $PROFILE_ROOTDIR/prefs.js; +} + +delete_pref() { + echo "resetting $1 to default" + sed -i "/user_pref(\"$1\", \(true\|false\));/d" $PROFILE_ROOTDIR/prefs.js; +} + +##################### +# 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 prefs.js" + exit 0; +fi + +# Prompting for correct install directory +read -e -i "$PROFILE_ROOTDIR" -p $'Enter profile root directory: \e[36m' newdir +echo -e -n "${NC}" +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}"; + ans="n" + read -e -i "$ans" -p "Do you want to delete $PROFILE_ROOTDIR/chrome? (y/n): " in + ans="${in:-$ans}"; + + if [[ ${ans,,} =~ ^(yes|y)$ ]]; then + rm -rf $PROFILE_ROOTDIR/chrome; + fi + + echo "uninstalling..."; + for pref in ${CHANGED_PREFS[@]}; do + delete_pref $pref; + done; + + echo "uninstall complete." + exit 0; +fi + +git --version 2>&1 > /dev/null; +if [ ! $? -eq 0 ]; then + echo "ERROR: git is not installed... Please install it." + exit 0; +fi + +echo "Detecting if firefox is installed on your system..." +if [ ! -f /usr/bin/firefox ] && { [ ! -f /usr/lib/firefox/firefox ] && [ ! -f /usr/lib/firefox-developer-edition/firefox ]; }; then + echo "ERROR: firefox not found..." + + ans="y" + read -e -i "$ans" -p "Do you want to continue anyway? (y/n): " in + ans="${in:-$ans}"; + + if [[ ! ${ans,,} =~ ^(yes|y)$ ]]; then + exit 0; + fi +fi + +################# +# INSTALL PHASE # +################# + +echo "Installing..." +if [ ! -d $TMP_DIR/$PROJECT_NAME ]; then + echo "cloning repository"; + if ! git clone $GITHUB_REPO $TMP_DIR/$PROJECT_NAME; then + echo "Error while cloning repository into $TMP_DIR/$PROJECT_NAME..." + exit 0; + fi +fi + +echo "Copying theme folder..." +cp -r $TMP_DIR/$PROJECT_NAME/chrome "$PROFILE_ROOTDIR" + +# firefox will automatically sort out any duplicate issues, whatever is at the end of the file takes priority, so this works. +echo "Adding necessary configs..." +for pref in ${CHANGED_PREFS[@]}; do + set_pref $pref "true" +done; + +if [[ $OSTYPE == "darwin"* ]]; then + set_pref "widget.macos.native-context-menus" "false" +fi + +echo -e "${GREEN}Finished successfully! Please start firefox to see the changes.";