executable_firefox-temp-profile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. set -o errexit -o pipefail
  3. logs_directory="$HOME/.local/var/log/firefox"
  4. mkdir -p "$logs_directory"
  5. OVERLAY=true
  6. profile="$(TMPDIR="${HOME}/.local/tmp" mktemp -d -t "firefox.XXXXXXXXXX")"
  7. FIREFOX_DEFAULT_PROFILE="j56dvo43.default-1520714705340"
  8. case "$1" in
  9. "default")
  10. profile_source_directory="${HOME}/.mozilla/firefox/${FIREFOX_DEFAULT_PROFILE}"
  11. if [[ $OVERLAY == true ]]
  12. then
  13. overlay_rw_directory="$(TMPDIR="${HOME}/.local/tmp" mktemp -d -t "overlay.XXXXXXXXXX")"
  14. exec &> >(tee -a "${logs_directory}/$(basename overlay_rw_directory).log")
  15. upper_directory="${overlay_rw_directory}/upper"
  16. workdir_directory="${overlay_rw_directory}/work"
  17. trap "set +e; sudo umount '$profile'; rmdir '$profile'; sudo rm -rf '$overlay_rw_directory'" EXIT
  18. mkdir -p "$upper_directory"
  19. mkdir -p "$workdir_directory"
  20. sudo mount -t overlay overlay -o "lowerdir=${profile_source_directory},upperdir=${upper_directory},workdir=${workdir_directory}" "$profile"
  21. else
  22. trap 'rm -rf "$profile"' EXIT
  23. rsync --archive "${profile_source_directory}/" "${profile}/"
  24. fi
  25. ;;
  26. esac
  27. firefox --new-instance --profile "$profile" "$@"