Update 4 files
- /home/dot_local/share/firefox/profiles.ini - /home/.chezmoiscripts/universal/run_onchange_after_40-firefox.tmpl - /home/.chezmoiscripts/darwin/run_onchange_after_10-configure-macos.tmpl - /home/dot_local/share/firefox/profiles.ini.tmpl
This commit is contained in:
parent
b1fcf67d3f
commit
4a2419b54d
4 changed files with 95 additions and 65 deletions
|
@ -940,4 +940,4 @@ done
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
logg success 'Done applying macOS settings'
|
logg success 'Done applying macOS settings'
|
||||||
logg info 'Some of these changes may require a logout/restart to take effect'
|
logg info 'Some of these changes may require a logout/restart to take effect' && exit 0
|
||||||
|
|
|
@ -12,54 +12,84 @@ for FIREFOX_DIR in '/usr/lib/firefox' '/usr/lib/firefox-esr' '/Applications/Fire
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
### Initiatize Firefox default profiles
|
### Loop through various Firefox profile locations
|
||||||
if command -v org.mozilla.firefox > /dev/null; then
|
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
|
||||||
if [ ! -d "$HOME/.var/app/org.mozilla.firefox" ]; then
|
### Determine executable to use
|
||||||
logg info 'Running Firefox headlessly to generate default profiles'
|
if [ "$SETTINGS_DIR" == "$HOME/.var/app/org.mozilla.firefox" ]; then
|
||||||
firefox --headless &
|
FIREFOX_EXE="$(which org.mozilla.firefox)"
|
||||||
FIREFOX_PID=$!
|
elif [ "$SETTINGS_DIR" == "$HOME/.var/app/io.gitlab.librewolf-community/.librewolf" ]; then
|
||||||
sleep 5
|
FIREFOX_EXE="$(which io.gitlab.librewolf-community)"
|
||||||
kill "$FIREFOX_PID"
|
elif [ "$SETTINGS_DIR" == "$HOME/Library/Application Support/Firefox/Profiles" ]; then
|
||||||
logg info 'Finished running Firefox headlessly'
|
FIREFOX_EXE="/Applications/Firefox.app/Contents/MacOS/firefox"
|
||||||
sleep 5
|
elif [ "$SETTINGS_DIR == "$HOME/Library/Application Support/LibreWolf/Profiles" ]; then
|
||||||
|
FIREFOX_EXE="/Applications/LibreWolf.app/Contents/MacOS/librewolf"
|
||||||
|
elif [ "$SETTINGS_DIR" == "$HOME/snap/firefox/common/.mozilla/firefox" ]; then
|
||||||
|
FIREFOX_EXE="$(which firefox)"
|
||||||
|
else
|
||||||
|
if command -v firefox-esr > /dev/null; then
|
||||||
|
FIREFOX_EXE="$(which firefox-esr)"
|
||||||
|
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)"
|
||||||
|
else
|
||||||
|
logg warn 'Unable to register Firefox executable'
|
||||||
|
logg info "Settings directory: $SETTINGS_DIR"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
logg info 'Renaming default profile folders and assigning them human-readable profile names'
|
### Initiatize Firefox default profiles
|
||||||
DEFAULT_RELEASE_PROFILE="$(find "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox" -mindepth 1 -maxdepth 1 -name "*.default-release")"
|
if command -v "$FIREFOX_EXE" > /dev/null; then
|
||||||
DEFAULT_PROFILE="$(find "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox" -mindepth 1 -maxdepth 1 -name "*.default")"
|
if [ ! -d "$SETTINGS_DIR" ]; then
|
||||||
mv "$DEFAULT_RELEASE_PROFILE" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox/profile.default"
|
logg info 'Running Firefox headlessly to generate default profiles'
|
||||||
mv "$DEFAULT_PROFILE" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox/profile.primary"
|
"$FIREFOX_EXE" --headless &
|
||||||
logg info 'Adding a secondary profile'
|
FIREFOX_PID=$!
|
||||||
cp -rf "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox/profile.primary" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox/profile.secondary"
|
sleep 5
|
||||||
logg info "Copying "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" to profile directory"
|
kill "$FIREFOX_PID"
|
||||||
cp -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" "$HOME/.var/app/org.mozilla.firefox/.mozilla/firefox/profiles.ini"
|
logg info 'Finished running Firefox headlessly'
|
||||||
fi
|
sleep 5
|
||||||
|
fi
|
||||||
### Install Firefox addons (using list declared in .chezmoidata.yaml)
|
logg info 'Renaming default profile folders and assigning them human-readable profile names'
|
||||||
if command -v org.mozilla.firefox > /dev/null; then
|
DEFAULT_RELEASE_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default-release")"
|
||||||
for FIREFOX_PLUGIN in {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }}; do
|
DEFAULT_PROFILE="$(find "$SETTINGS_DIR" -mindepth 1 -maxdepth 1 -name "*.default")"
|
||||||
logg info 'Ensuring `'"$FIREFOX_PLUGIN"'` is installed'
|
mv "$DEFAULT_PROFILE" "$SETTINGS_DIR/profile.default"
|
||||||
PLUGIN_HTML="$(mktemp)"
|
mv "$DEFAULT_RELEASE_PROFILE" "$SETTINGS_DIR/profile.primary"
|
||||||
curl --silent "https://addons.mozilla.org/en-US/firefox/addon/$FIREFOX_PLUGIN/" > "$PLUGIN_HTML"
|
logg info 'Adding a secondary profile'
|
||||||
PLUGIN_TMP="$(mktemp)"
|
cp -rf "$SETTINGS_DIR/profile.primary" "$SETTINGS_DIR/profile.secondary"
|
||||||
cat "$PLUGIN_HTML" | htmlq '#redux-store-state' | sed 's/^<scri.*application\/json">//' | sed 's/<\/script>$//' > "$PLUGIN_TMP"
|
logg info "Copying "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" to profile directory"
|
||||||
PLUGIN_ID="$(jq '.addons.bySlug["'"$FIREFOX_PLUGIN"'"]' "$PLUGIN_TMP")"
|
if [ -d /Applications ] && [ -d /System ]; then
|
||||||
if [ "$PLUGIN_ID" != 'null' ]; then
|
# macOS
|
||||||
PLUGIN_FILE_ID="$(jq -r '.addons.byID["'"$PLUGIN_ID"'"].guid' "$PLUGIN_TMP")"
|
cp -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/../profiles.ini"
|
||||||
if [ "$PLUGIN_FILE_ID" != 'null' ]; then
|
else
|
||||||
PLUGIN_URL="$(cat "$PLUGIN_HTML" | htmlq '.InstallButtonWrapper-download-link' --attribute href)"
|
# Linux
|
||||||
PLUGIN_FILENAME="${PLUGIN_FILE_ID}.xpi"
|
cp -f "${XDG_DATA_HOME:-$HOME/.local/share}/firefox/profiles.ini" "$SETTINGS_DIR/profiles.ini"
|
||||||
if [ ! -d "$HOME/.var/app/org.mozilla.firefox/.mozilla/extensions/$PLUGIN_FILENAME" ]; then
|
fi
|
||||||
logg info 'Downloading plugin file for `'"$PLUGIN_FILENAME"'` ('"$FIREFOX_PLUGIN"')'
|
|
||||||
curl "$PLUGIN_URL" -o "$HOME/.var/app/org.mozilla.firefox/.mozilla/extensions/$PLUGIN_FILENAME"
|
### Install Firefox addons (using list declared in .chezmoidata.yaml)
|
||||||
logg success 'Finished downloading `'"$PLUGIN_FILENAME"'` ('"$FIREFOX_PLUGIN"')'
|
for FIREFOX_PLUGIN in {{ list (.firefoxAddOns | toString | replace "[" "" | replace "]" "") | uniq | join " " }}; do
|
||||||
|
logg info 'Ensuring `'"$FIREFOX_PLUGIN"'` is installed'
|
||||||
|
PLUGIN_HTML="$(mktemp)"
|
||||||
|
curl --silent "https://addons.mozilla.org/en-US/firefox/addon/$FIREFOX_PLUGIN/" > "$PLUGIN_HTML"
|
||||||
|
PLUGIN_TMP="$(mktemp)"
|
||||||
|
cat "$PLUGIN_HTML" | htmlq '#redux-store-state' | sed 's/^<scri.*application\/json">//' | sed 's/<\/script>$//' > "$PLUGIN_TMP"
|
||||||
|
PLUGIN_ID="$(jq '.addons.bySlug["'"$FIREFOX_PLUGIN"'"]' "$PLUGIN_TMP")"
|
||||||
|
if [ "$PLUGIN_ID" != 'null' ]; then
|
||||||
|
PLUGIN_FILE_ID="$(jq -r '.addons.byID["'"$PLUGIN_ID"'"].guid' "$PLUGIN_TMP")"
|
||||||
|
if [ "$PLUGIN_FILE_ID" != 'null' ]; then
|
||||||
|
PLUGIN_URL="$(cat "$PLUGIN_HTML" | htmlq '.InstallButtonWrapper-download-link' --attribute href)"
|
||||||
|
PLUGIN_FILENAME="${PLUGIN_FILE_ID}.xpi"
|
||||||
|
if [ ! -d "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME" ]; then
|
||||||
|
logg info 'Downloading plugin file for `'"$PLUGIN_FILENAME"'` ('"$FIREFOX_PLUGIN"')'
|
||||||
|
curl "$PLUGIN_URL" -o "$SETTINGS_DIR/profile.primary/extensions/$PLUGIN_FILENAME"
|
||||||
|
logg success 'Finished downloading `'"$PLUGIN_FILENAME"'` ('"$FIREFOX_PLUGIN"')'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
logg warn 'A null Firefox add-on filename was detected for `'"$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 ID was detected for `'"$FIREFOX_PLUGIN"'`'
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
logg warn 'A null Firefox add-on ID was detected for `'"$FIREFOX_PLUGIN"'`'
|
fi
|
||||||
fi
|
done
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
[Profile2]
|
|
||||||
Name=Secondary
|
|
||||||
IsRelative=1
|
|
||||||
Path=profile.secondary
|
|
||||||
|
|
||||||
[Profile1]
|
|
||||||
Name=Primary
|
|
||||||
IsRelative=1
|
|
||||||
Path=profile.primary
|
|
||||||
Default=1
|
|
||||||
|
|
||||||
[Profile0]
|
|
||||||
Name=Default
|
|
||||||
IsRelative=1
|
|
||||||
Path=profile.default-release
|
|
||||||
|
|
||||||
[General]
|
|
||||||
StartWithLastProfile=1
|
|
||||||
Version=2
|
|
19
home/dot_local/share/firefox/profiles.ini.tmpl
Normal file
19
home/dot_local/share/firefox/profiles.ini.tmpl
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[Profile2]
|
||||||
|
Name=Secondary
|
||||||
|
IsRelative=1
|
||||||
|
Path={{ if eq .host.distro.family "darwin" }}Profiles/{{ end }}profile.secondary
|
||||||
|
|
||||||
|
[Profile1]
|
||||||
|
Name=Primary
|
||||||
|
IsRelative=1
|
||||||
|
Path={{ if eq .host.distro.family "darwin" }}Profiles/{{ end }}profile.primary
|
||||||
|
Default=1
|
||||||
|
|
||||||
|
[Profile0]
|
||||||
|
Name=Default
|
||||||
|
IsRelative=1
|
||||||
|
Path={{ if eq .host.distro.family "darwin" }}Profiles/{{ end }}profile.default
|
||||||
|
|
||||||
|
[General]
|
||||||
|
StartWithLastProfile=1
|
||||||
|
Version=2
|
Loading…
Reference in a new issue