1
Fork 0

firefox: rework config mechanism again

This commit is contained in:
Alan Faubert 2019-09-11 12:59:17 -04:00
parent d9c1cce83b
commit 88fb1b33f7
6 changed files with 22 additions and 17 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/firefox/proxies
/firefox/configs
/firefox/*.proxy
/gcloud
/git/.git-credentials

View File

@ -4,7 +4,8 @@ My config files for various things. Use `config.sh` to automate the setup of sev
Things that are not checked in but which should live in this directory:
- `firefox/proxies/`
- `firefox/configs/`
- `firefox/*.proxy`
- `gcloud/`
- `git/.git-credentials`
- `git/github_token`

View File

@ -16,7 +16,7 @@ while :; do
apt- 'apt' apt-refresh ' update/upgrade/autoremove/autoclean' apt-fakeroot ' Install and use fakeroot-tcp' apt-jq ' Install jq' apt-make ' Install make' \
docker- 'Docker' docker-cli ' Install CLI' docker-relay ' Install relay (WSL)' \
wsl- 'WSL' wsl-win ' Create ~/win symlink to %USERPROFILE%' wsl-hosts ' Create /etc/hosts symlink to system' \
firefox- 'Firefox' firefox-proxy-win ' Create snippets for proxy configs (Windows)' firefox-win ' Create profile user.js files (Windows)' \
firefox- 'Firefox' firefox-rebuild-win ' Rebuild configs from templates (Windows)' firefox-link-win ' Create user.js symlinks (Windows)' \
win- 'Windows' win-scancode-map ' Swap caps lock and context key' \
--notags --default-item "$ACTION" 3>&2 2>&1 1>&3-)"
case "$ACTION" in
@ -160,28 +160,32 @@ while :; do
sudo rm -rf /etc/hosts &&
sudo ln -s /c/Windows/System32/drivers/etc/hosts /etc/hosts
;;
firefox-proxy-win)
rm -f "$ROOT"/firefox/*.proxy
mapfile -t PROXIES < <(ls "$ROOT"/firefox/proxies -p | grep -v /)
for PROXY in ${PROXIES[@]}; do echo 'user_pref("network.proxy.autoconfig_url", "'file:///"$ROOTWINSLASH"/firefox/proxies/"$PROXY"$'");\nuser_pref("network.proxy.type", 2);' > "$ROOT"/firefox/$PROXY.proxy; done
firefox-rebuild-win)
ls -p "$ROOT"/firefox/configs | while read CONFIG; do
truncate -s0 "$ROOT"/firefox/configs/"$CONFIG"
IFS='+' read -a PIECES <<< "$CONFIG"
for PIECE in "${PIECES[@]}"; do
[ -f "$ROOT"/firefox/"$PIECE" ] && cat "$ROOT"/firefox/"$PIECE" >> "$ROOT"/firefox/configs/"$CONFIG"
[ -f "$ROOT"/firefox/"$PIECE".proxy ] && echo 'user_pref("network.proxy.autoconfig_url", "'file:///"$ROOTWINSLASH"/firefox/"$PIECE".proxy$'");\nuser_pref("network.proxy.type", 2);' >> "$ROOT"/firefox/configs/"$CONFIG"
done
done
true
;;
firefox-win)
firefox-link-win)
PROFILE_DIR="$(wslpath "$(cmd.exe /c echo %APPDATA%\\Mozilla\\Firefox\\Profiles | tr -d '\r')")"
mapfile -t PROFILES < <(ls "$PROFILE_DIR")
PROFILES_ARGS=()
for ((i=0; i < ${#PROFILES[@]}; i++)); do PROFILES_ARGS[2*i]="${PROFILES[$i]}"; PROFILES_ARGS[2*i+1]="${PROFILES[$i]}"; done
mapfile -t TEMPLATES < <(ls -p "$ROOT"/firefox | grep -v /)
TEMPLATES_ARGS=()
for ((i=0; i < ${#TEMPLATES[@]}; i++)); do TEMPLATES_ARGS[2*i]="${TEMPLATES[$i]}"; TEMPLATES_ARGS[2*i+1]="${TEMPLATES[$i]}"; done
mapfile -t CONFIGS < <(ls -p "$ROOT"/firefox/configs)
CONFIGS_ARGS=()
for ((i=0; i < ${#CONFIGS[@]}; i++)); do CONFIGS_ARGS[2*i]="${CONFIGS[$i]}"; CONFIGS_ARGS[2*i+1]="${CONFIGS[$i]}"; done
while :; do
PROFILE="$(whiptail --title 'Select profile' --menu '' 22 60 15 "${PROFILES_ARGS[@]}" --notags --default-item "$PROFILE" 3>&2 2>&1 1>&3-)"
[ "$PROFILE" = '' ] && break
truncate -s0 "$PROFILE_DIR"/"$PROFILE"/user.js
while :; do
TEMPLATE="$(whiptail --title "Add template to $PROFILE" --menu '' 22 60 15 "${TEMPLATES_ARGS[@]}" --notags --default-item "$TEMPLATE" 3>&2 2>&1 1>&3-)"
[ "$TEMPLATE" = '' ] && break
cat "$ROOT"/firefox/"$TEMPLATE" >> "$PROFILE_DIR"/"$PROFILE"/user.js
done
CONFIG="$(whiptail --title "Link $PROFILE to config" --menu '' 22 60 15 "${CONFIGS_ARGS[@]}" --notags --default-item "$CONFIG" 3>&2 2>&1 1>&3-)"
[ "$CONFIG" = '' ] && break
rm -f "$PROFILE_DIR"/"$PROFILE"/user.js
cmd.exe /c mklink %APPDATA%\\Mozilla\\Firefox\\Profiles\\"$PROFILE"\\user.js "$ROOTWIN"\\firefox\\configs\\"$CONFIG"
done
;;
win-scancode-map)