From 9652158c35e2496fdd9b92fc60c9802a0e60a2a2 Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Wed, 1 Feb 2023 08:48:57 +0000 Subject: [PATCH] Update 4 files - /home/dot_local/bin/executable_backup-app-settings - /home/dot_local/bin/executable_install-program - /home/dot_local/share/firefox/profile-switcher.json - /home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl --- .../run_onchange_after_40-firefox.tmpl | 89 ++++++++++++++++++- .../bin/executable_backup-app-settings | 4 +- home/dot_local/bin/executable_install-program | 6 +- .../share/firefox/profile-switcher.json | 9 ++ 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 home/dot_local/share/firefox/profile-switcher.json diff --git a/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl index 1ebe4c30..121f0778 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl @@ -6,6 +6,21 @@ # Firefox plugins: {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }} +### Installs the Firefox Profile Connector on Linux systems (Snap / Flatpak installs are not included in this function, but instead inline below) +function installFirefoxProfileConnector() { + logg info 'Installing the Firefox Profile Connector' + if command -v apt-get > /dev/null; then + sudo apt-get install -y https://github.com/null-dev/firefox-profile-switcher-connector/releases/latest/download/linux-x64.deb + elif command -v dnf > /dev/null; then + sudo dnf install -y https://github.com/null-dev/firefox-profile-switcher-connector/releases/latest/download/linux-x64.rpm + elif command -v yay > /dev/null; then + yay -Ss firefox-profile-switcher-connector + else + logg warn 'apt-get, dnf, and yay were all unavailable so the Firefox Profile Connector helper executable could not be installed' + fi + +} + ### Add Firefox enterprise profile # TODO - figure out how to do this for other installations like Flatpak and macOS and Librewolf for FIREFOX_DIR in '/usr/lib/firefox' '/usr/lib/firefox-esr' '/Applications/Firefox.app/Contents/Resources'; do @@ -24,6 +39,28 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app continue else FIREFOX_EXE="$(which org.mozilla.firefox)" + + ### Firefox Profile Switcher + BASE_DIR="$HOME/.var/app/org.mozilla.firefox" + BIN_INSTALL_DIR="$BASE_DIR/data/firefoxprofileswitcher-install" + MANIFEST_INSTALL_DIR="$BASE_DIR/.mozilla/native-messaging-hosts" + DOWNLOAD_URL="https://github.com/null-dev/firefox-profile-switcher-connector/releases/latest/download/linux-x64.deb" + + ### Ensure Firefox Profile Switcher is not already installed + if [ ! -f "$BIN_INSTALL_DIR/usr/bin/ff-pswitch-connector" ] || [ ! -f "$MANIFEST_INSTALL_DIR/ax.nd.profile_switcher_ff.json" ]; then + ### Download profile switcher + mkdir -p "$BIN_INSTALL_DIR" + TMP_FILE="$(mktemp)" + logg info 'Downloading Firefox Profile Switch connector' + curl -sSL "$DOWNLOAD_URL" -o "$TMP_FILE" + ar p "$TMP_FILE" data.tar.xz | tar xfJ - --strip-components=2 -C "$BIN_INSTALL_DIR" usr/bin/ff-pswitch-connector + rm -f "$TMP_FILE" + + ### Create manifest + logg info 'Copying profile switcher configuration to manifest directory' + mkdir -p "$MANIFEST_INSTALL_DIR" + cat "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profile-switcher.json" | sed 's/PATH_PLACEHOLDER/'"$BIN_INSTALL_DIR"'/' > "$MANIFEST_INSTALL_DIR/ax.nd.profile_switcher_ff.json" + fi fi elif [ "$SETTINGS_DIR" == "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" ]; then if ! command -v io.gitlab.librewolf-community > /dev/null; then @@ -35,7 +72,19 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app FIREFOX_EXE="/Applications/Firefox.app/Contents/MacOS/firefox" if [ ! -f "$FIREFOX_EXE" ]; then continue - fi + else + ### Download Firefox Profile Switcher + if [ ! -d /usr/local/Cellar/firefox-profile-switcher-connector ]; then + logg info 'Ensuring Firefox Profile Switcher is installed' + brew install null-dev/firefox-profile-switcher/firefox-profile-switcher-connector + fi + + ### Ensure Firefox Profile Switcher configuration is symlinked + if [ ! -d "/Library/Application Support/Mozilla/NativeMessagingHosts/ax.nd.profile_switcher_ff.json" ]; then + logg info 'Ensuring Firefox Profile Switcher is configured' + sudo mkdir -p "/Library/Applcation Support/Mozilla/NativeMessagingHosts" + sudo ln -sf "$(brew ls -l firefox-profile-switcher-connector | grep -i ax.nd.profile_switcher_ff.json | head -n1)" "/Library/Application Support/Mozilla/NativeMessagingHosts/ax.nd.profile_switcher_ff.json" + fi elif [ "$SETTINGS_DIR" == "$HOME/Library/Application Support/LibreWolf/Profiles" ]; then FIREFOX_EXE="/Applications/LibreWolf.app/Contents/MacOS/librewolf" if [ ! -f "$FIREFOX_EXE" ]; then @@ -45,13 +94,37 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app FIREFOX_EXE="/snap/bin/firefox" if [ ! -f "$FIREFOX_EXE" ]; then continue + else + ### Firefox Profile Switcher + BASE_DIR="$HOME/snap/firefox/common" + BIN_INSTALL_DIR="$BASE_DIR/firefoxprofileswitcher-install" + MANIFEST_INSTALL_DIR="$BASE_DIR/.mozilla/native-messaging-hosts" + DOWNLOAD_URL="https://github.com/null-dev/firefox-profile-switcher-connector/releases/latest/download/linux-x64.deb" + + ### Ensure Firefox Profile Switcher is not already installed + if [ ! -f "$BIN_INSTALL_DIR/usr/bin/ff-pswitch-connector" ] || [ ! -f "$MANIFEST_INSTALL_DIR/ax.nd.profile_switcher_ff.json" ]; then + ### Download profile switcher + mkdir -p "$BIN_INSTALL_DIR" + TMP_FILE="$(mktemp)" + logg info 'Downloading Firefox Profile Switch connector' + curl -sSL "$DOWNLOAD_URL" -o "$TMP_FILE" + ar p "$TMP_FILE" data.tar.xz | tar xfJ - --strip-components=2 -C "$BIN_INSTALL_DIR" usr/bin/ff-pswitch-connector + rm -f "$TMP_FILE" + + ### Create manifest + logg info 'Copying profile switcher configuration to manifest directory' + mkdir -p "$MANIFEST_INSTALL_DIR" + cat "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profile-switcher.json" | sed 's/PATH_PLACEHOLDER/'"$BIN_INSTALL_DIR"'/' > "$MANIFEST_INSTALL_DIR/ax.nd.profile_switcher_ff.json" + fi fi elif [ "$SETTINGS_DIR" == "$HOME/.mozilla/firefox" ]; then if command -v firefox-esr > /dev/null; then FIREFOX_EXE="$(which firefox-esr)" + installFirefoxProfileConnector elif command -v firefox > /dev/null && [ "$(which firefox)" != *'snap'* ] && [ "$(which firefox)" != *'flatpak'* ] && [ ! -d /Applications ] && [ ! -d /System ]; then # Conditional check ensures Snap / Flatpak / macOS Firefox versions do not try to install to the wrong folder FIREFOX_EXE="$(which firefox)" + installFirefoxProfileConnector else logg warn 'Unable to register Firefox executable' logg info "Settings directory: $SETTINGS_DIR" @@ -91,6 +164,20 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app ### Install Firefox addons (using list declared in .chezmoidata.yaml) for FIREFOX_PLUGIN in {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }}; do + ### Configure profile switcher + if [ "$FIREFOX_PLUGIN" == "" ]; then + if [ -d /Applications ] && [ -d /System ]; then + # macOS + brew install null-dev/firefox-profile-switcher/firefox-profile-switcher-connector + sudo mkdir -p "/Library/Application Support/Mozilla/NativeMessagingHosts" + LATEST_VERSION="$(ls -v /usr/local/Cellar/firefox-profile-switcher-connector | tail -n 1)" + sudo ln -sf "/usr/local/Cellar/firefox-profile-switcher-connector/$LATEST_VERSION/ax.nd.profile_switcher_ff.json" "/Library/Application Support/Mozilla/NativeMessagingHosts/ax.nd.profile_switcher_ff.json" + elif command -v apt-get > /dev/null; then + # Debian/Ubuntu + elif command -v dnf > /dev/null; then + # CentOS / Fedora + elif command -v pacman > /dev/null; then + fi logg info 'Ensuring `'"$FIREFOX_PLUGIN"'` is installed' PLUGIN_HTML="$(mktemp)" curl --silent "https://addons.mozilla.org/en-US/firefox/addon/$FIREFOX_PLUGIN/" > "$PLUGIN_HTML" diff --git a/home/dot_local/bin/executable_backup-app-settings b/home/dot_local/bin/executable_backup-app-settings index 43759fbe..58fdae44 100644 --- a/home/dot_local/bin/executable_backup-app-settings +++ b/home/dot_local/bin/executable_backup-app-settings @@ -1,3 +1,5 @@ #!/usr/bin/env bash -for DESKTOP_APP of BraveSoftware Ferdium "Google Assistant" Mailspring "Standard Notes" TeamViewer zoom.us \ No newline at end of file +for DESKTOP_APP of BraveSoftware Ferdium "Google Assistant" Mailspring "Standard Notes" TeamViewer zoom.us; do + true +done \ No newline at end of file diff --git a/home/dot_local/bin/executable_install-program b/home/dot_local/bin/executable_install-program index 0fa744bd..dec352f5 100644 --- a/home/dot_local/bin/executable_install-program +++ b/home/dot_local/bin/executable_install-program @@ -754,9 +754,9 @@ async function beforeInstall(packageManager) { runCommand('Running yum update', `sudo yum update -y`) } } else if (packageManager === 'flatpak') { - // Issues with Flatpak not downloading updates on CentOS so reverting to ZX way of doing things so stdout can do its thing - // runCommand('Running flatpak update', `timeout 600 sudo flatpak update -y`) - await $`sudo flatpak update -y` + // TODO - figure out why CentOS is failing to update + // and then switch command below for `sudo flatpak update -y` + runCommand('Running flatpak update', `. /etc/os-release && if [ "$ID" != 'centos' ]; then sudo flatpak update -y; fi`) } else if (packageManager === 'gem') { } else if (packageManager === 'go') { } else if (packageManager === 'nix') { diff --git a/home/dot_local/share/firefox/profile-switcher.json b/home/dot_local/share/firefox/profile-switcher.json new file mode 100644 index 00000000..7d00c3bf --- /dev/null +++ b/home/dot_local/share/firefox/profile-switcher.json @@ -0,0 +1,9 @@ +{ + "allowed_extensions": [ + "profile-switcher-ff@nd.ax" + ], + "description": "Profile Switcher for Firefox", + "name": "ax.nd.profile_switcher_ff", + "path": "PATH_PLACEHOLDER/ff-pswitch-connector", + "type": "stdio" +} \ No newline at end of file