Update file run_onchange_after_40-firefox.tmpl
This commit is contained in:
parent
b55df9faa1
commit
b33250698f
1 changed files with 44 additions and 24 deletions
|
@ -7,26 +7,30 @@
|
||||||
# Firefox plugins: {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }}
|
# Firefox plugins: {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }}
|
||||||
|
|
||||||
### Add Firefox enterprise profile
|
### Add Firefox enterprise profile
|
||||||
# TODO - figure out how to do this for other installations like Flatpak and macOS
|
# 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
|
for FIREFOX_DIR in '/usr/lib/firefox' '/usr/lib/firefox-esr' '/Applications/Firefox.app/Contents/Resources'; do
|
||||||
if [ -d "$FIREFOX_DIR" ] && [ -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox" ] && command -v rsync > /dev/null; then
|
if [ -d "$FIREFOX_DIR" ] && [ -d "${XDG_DATA_DIR:-$HOME/.local/share}/firefox" ] && command -v rsync > /dev/null; then
|
||||||
sudo rsync -artvu "${XDG_DATA_HOME:-$HOME/.local/share}/firefox" "$FIREFOX_DIR"
|
sudo rsync -artvu "${XDG_DATA_DIR:-$HOME/.local/share}/firefox/" "$FIREFOX_DIR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
### Loop through various Firefox profile locations
|
### Loop through various Firefox profile locations
|
||||||
for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox" "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" "$HOME/Library/Application Support/Firefox/Profiles" "$HOME/Library/Application Support/LibreWolf/Profiles" "$HOME/.mozilla/firefox"; do
|
for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox" "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" "$HOME/Library/Application Support/Firefox/Profiles" "$HOME/Library/Application Support/LibreWolf/Profiles" "$HOME/.mozilla/firefox"; do
|
||||||
### Determine executable to use
|
### Determine executable to use
|
||||||
|
logg info "Processing Firefox profile location $SETTINGS_DIR"
|
||||||
|
unset FIREFOX_EXE
|
||||||
if [ "$SETTINGS_DIR" == "$HOME/.var/app/org.mozilla.firefox" ]; then
|
if [ "$SETTINGS_DIR" == "$HOME/.var/app/org.mozilla.firefox" ]; then
|
||||||
if ! command -v org.mozilla.firefox > /dev/null; then
|
if ! command -v org.mozilla.firefox > /dev/null; then
|
||||||
continue
|
continue
|
||||||
|
else
|
||||||
|
FIREFOX_EXE="$(which org.mozilla.firefox)"
|
||||||
fi
|
fi
|
||||||
FIREFOX_EXE="$(which org.mozilla.firefox)"
|
|
||||||
elif [ "$SETTINGS_DIR" == "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" ]; then
|
elif [ "$SETTINGS_DIR" == "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" ]; then
|
||||||
if ! command -v io.gitlab.librewolf-community > /dev/null; then
|
if ! command -v io.gitlab.librewolf-community > /dev/null; then
|
||||||
continue
|
continue
|
||||||
|
else
|
||||||
|
FIREFOX_EXE="$(which io.gitlab.librewolf-community)"
|
||||||
fi
|
fi
|
||||||
FIREFOX_EXE="$(which io.gitlab.librewolf-community)"
|
|
||||||
elif [ "$SETTINGS_DIR" == "$HOME/Library/Application Support/Firefox/Profiles" ]; then
|
elif [ "$SETTINGS_DIR" == "$HOME/Library/Application Support/Firefox/Profiles" ]; then
|
||||||
FIREFOX_EXE="/Applications/Firefox.app/Contents/MacOS/firefox"
|
FIREFOX_EXE="/Applications/Firefox.app/Contents/MacOS/firefox"
|
||||||
if [ ! -f "$FIREFOX_EXE" ]; then
|
if [ ! -f "$FIREFOX_EXE" ]; then
|
||||||
|
@ -38,10 +42,10 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
elif [ "$SETTINGS_DIR" == "$HOME/snap/firefox/common/.mozilla/firefox" ]; then
|
elif [ "$SETTINGS_DIR" == "$HOME/snap/firefox/common/.mozilla/firefox" ]; then
|
||||||
if ! command -v firefox > /dev/null; then
|
FIREFOX_EXE="/snap/bin/firefox"
|
||||||
|
if [ ! -f "$FIREFOX_EXE" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
FIREFOX_EXE="$(which firefox)"
|
|
||||||
elif [ "$SETTINGS_DIR" == "$HOME/.mozilla/firefox" ]; then
|
elif [ "$SETTINGS_DIR" == "$HOME/.mozilla/firefox" ]; then
|
||||||
if command -v firefox-esr > /dev/null; then
|
if command -v firefox-esr > /dev/null; then
|
||||||
FIREFOX_EXE="$(which firefox-esr)"
|
FIREFOX_EXE="$(which firefox-esr)"
|
||||||
|
@ -56,29 +60,33 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app
|
||||||
fi
|
fi
|
||||||
### Initiatize Firefox default profiles
|
### Initiatize Firefox default profiles
|
||||||
if command -v "$FIREFOX_EXE" > /dev/null; then
|
if command -v "$FIREFOX_EXE" > /dev/null; then
|
||||||
|
logg info "Firefox executable set to $FIREFOX_EXE"
|
||||||
if [ ! -d "$SETTINGS_DIR" ]; then
|
if [ ! -d "$SETTINGS_DIR" ]; then
|
||||||
logg info 'Running Firefox headlessly to generate default profiles'
|
logg info 'Running Firefox headlessly to generate default profiles'
|
||||||
"$FIREFOX_EXE" --headless &
|
timeout 8 "$FIREFOX_EXE" --headless
|
||||||
FIREFOX_PID=$!
|
|
||||||
sleep 5
|
|
||||||
kill "$FIREFOX_PID"
|
|
||||||
logg info 'Finished running Firefox headlessly'
|
logg info 'Finished running Firefox headlessly'
|
||||||
sleep 5
|
|
||||||
fi
|
fi
|
||||||
logg info 'Renaming default profile folders and assigning them human-readable profile names'
|
DEFAULT_RELEASE_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default-*")"
|
||||||
DEFAULT_RELEASE_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default-release")"
|
|
||||||
DEFAULT_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default")"
|
DEFAULT_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default")"
|
||||||
mv "$DEFAULT_PROFILE" "$SETTINGS_DIR/profile.default"
|
if [ -n "$DEFAULT_PROFILE" ] && [ "$DEFAULT_PROFILE" != "$SETTINGS_DIR/profile.default" ]; then
|
||||||
mv "$DEFAULT_RELEASE_PROFILE" "$SETTINGS_DIR/profile.primary"
|
logg info "Renaming $DEFAULT_PROFILE to $SETTINGS_DIR/profile.default"
|
||||||
logg info 'Adding a secondary profile'
|
rsync -a "$DEFAULT_PROFILE/" "$SETTINGS_DIR/profile.default"
|
||||||
cp -rf "$SETTINGS_DIR/profile.primary" "$SETTINGS_DIR/profile.secondary"
|
fi
|
||||||
logg info "Copying "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" to profile directory"
|
if [ -n "$DEFAULT_RELEASE_PROFILE" ]; then
|
||||||
|
logg info "Renaming $DEFAULT_RELEASE_PROFILE to $SETTINGS_DIR/profile.primary"
|
||||||
|
rsync -a "$DEFAULT_RELEASE_PROFILE/" "$SETTINGS_DIR/profile.primary"
|
||||||
|
fi
|
||||||
|
if [ ! -d "$SETTINGS_DIR/profile.secondary" ] && [ -d "$SETTINGS_DIR/profile.default" ]; then
|
||||||
|
logg info 'Adding a secondary profile'
|
||||||
|
rsync -a "$SETTINGS_DIR/profile.default/" "$SETTINGS_DIR/profile.secondary"
|
||||||
|
fi
|
||||||
|
logg info "Copying "${XDG_DATA_DIR:-$HOME/.local/share}/firefox/profiles.ini" to profile directory"
|
||||||
if [ -d /Applications ] && [ -d /System ]; then
|
if [ -d /Applications ] && [ -d /System ]; then
|
||||||
# macOS
|
# macOS
|
||||||
cp -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/../profiles.ini"
|
cp -f "${XDG_DATA_DIR:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/../profiles.ini"
|
||||||
else
|
else
|
||||||
# Linux
|
# Linux
|
||||||
cp -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/profiles.ini"
|
cp -f "${XDG_DATA_DIR:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/profiles.ini"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Install Firefox addons (using list declared in .chezmoidata.yaml)
|
### Install Firefox addons (using list declared in .chezmoidata.yaml)
|
||||||
|
@ -94,10 +102,22 @@ for SETTINGS_DIR in "$HOME/snap/firefox/common/.mozilla/firefox" "$HOME/.var/app
|
||||||
if [ "$PLUGIN_FILE_ID" != 'null' ]; then
|
if [ "$PLUGIN_FILE_ID" != 'null' ]; then
|
||||||
PLUGIN_URL="$(cat "$PLUGIN_HTML" | htmlq '.InstallButtonWrapper-download-link' --attribute href)"
|
PLUGIN_URL="$(cat "$PLUGIN_HTML" | htmlq '.InstallButtonWrapper-download-link' --attribute href)"
|
||||||
PLUGIN_FILENAME="${PLUGIN_FILE_ID}.xpi"
|
PLUGIN_FILENAME="${PLUGIN_FILE_ID}.xpi"
|
||||||
if [ ! -d "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME" ]; then
|
PLUGIN_FOLDER="$(echo "$PLUGIN_FILENAME" | sed 's/.xpi$//')"
|
||||||
|
if [ ! -d "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FOLDER" ]; then
|
||||||
logg info 'Downloading plugin file for '"$PLUGIN_FILENAME"' ('"$FIREFOX_PLUGIN"')'
|
logg info 'Downloading plugin file for '"$PLUGIN_FILENAME"' ('"$FIREFOX_PLUGIN"')'
|
||||||
curl "$PLUGIN_URL" -o "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME"
|
if [ ! -d "$SETTINGS_DIR/profile.primary/extensions" ]; then
|
||||||
logg success 'Finished downloading '"$PLUGIN_FILENAME"' ('"$FIREFOX_PLUGIN"')'
|
mkdir -p "$SETTINGS_DIR/profile.primary/extensions"
|
||||||
|
fi
|
||||||
|
curl -sSL "$PLUGIN_URL" -o "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME"
|
||||||
|
# Unzipping like this causes Firefox to complain about unsigned plugins
|
||||||
|
# TODO - figure out how to headlessly enable the extensions in such a way that is compatible with Flatpak / Snap
|
||||||
|
# using the /usr/lib/firefox/distribution/policies.json works but this is not compatible with Flatpak / Snap out of the box
|
||||||
|
# it seems since they do not have access to the file system by default. Also, using the policies.json approach forces
|
||||||
|
# all Firefox profiles to use the same extensions. Ideally, we should find a way to enable the extensions scoped
|
||||||
|
# to the user profile.
|
||||||
|
# logg info 'Unzipping '"$PLUGIN_FILENAME"' ('"$FIREFOX_PLUGIN"')'
|
||||||
|
# unzip "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME" -d "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FOLDER"
|
||||||
|
logg success 'Installed `'"$FIREFOX_PLUGIN"'`'
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
logg warn 'A null Firefox add-on filename was detected for `'"$FIREFOX_PLUGIN"'`'
|
logg warn 'A null Firefox add-on filename was detected for `'"$FIREFOX_PLUGIN"'`'
|
||||||
|
|
Loading…
Reference in a new issue