Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active November 8, 2019 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/f8964b9a37826b2876eab9d7b16bb424 to your computer and use it in GitHub Desktop.
Save ivan/f8964b9a37826b2876eab9d7b16bb424 to your computer and use it in GitHub Desktop.
Share Firefox profile between two Linux machines without Firefox Sync
#!/usr/bin/env bash
"$@"
if [[ $HOSTNAME != "ra" ]]; then
push-mozilla
fi
#!/usr/bin/env bash
# The design here does not involve NFS, but ra is still treated as a master from
# which plato "checks out" ~/.mozilla and rsyncs it back as soon as Firefox exits.
set -eu -o pipefail
. ~/bin/fix-env-vars
# Enable high-resolution touchpad scroll, which Firefox 70 still doesn't enable
# by default.
export MOZ_USE_XINPUT2=1
firefox=/run/current-system/sw/bin/firefox
profile=$HOME/.mozilla/firefox/aaaaaaaa.default
# if Firefox is already running, don't do any of the profile management below
if pgrep firefox; then
exec "$firefox" "$@"
fi
# Shoot down the Firefox running on the other computer
if [[ $HOSTNAME == "ra" ]]; then
# plato will rsync over its profile back to ra when firefox exits, so we
# need to run quit-firefox on plato and wait for the profile to arrive.
#
# plato may be down, so use the first ssh to probe whether machine is up.
# This avoids applying a short timeout to the quit-firefox, which may take
# longer.
(timeout 3 ssh at@plato echo && ssh at@plato "~/bin/quit-firefox") || true
else
ssh at@ra "~/bin/quit-firefox"
# back up profile
rm -rf ~/trash/.mozilla
cp -al ~/.mozilla ~/trash/
# "check out" the profile from ra
pull-mozilla
fi
# Manage devPixelsPerPx manually because Firefox doesn't get it right
pixelsperpx=1.0
if [[ $HOSTNAME = "ra" ]]; then
pixelsperpx=1.7
fi
for prefs in "$profile"/prefs.js; do
echo "Fixing $prefs"
sed -i -r "s/user_pref\(\"layout\.css\.devPixelsPerPx\", \".+\"\);/user_pref(\"layout.css.devPixelsPerPx\", \"$pixelsperpx\");/g" "$prefs"
done
exec ~/bin/firefox-and-push-mozilla "$firefox" "$@"
#!/usr/bin/env bash
panel_environ() {
cat "/proc/$(pgrep -u "$(whoami)" xfce4-panel)/environ" | tr '\0' '\n'
}
export DISPLAY=$( panel_environ | grep '^DISPLAY=' | sed -r 's,^[^=]+=,,g')
export XAUTHORITY=$( panel_environ | grep '^XAUTHORITY=' | sed -r 's,^[^=]+=,,g')
export DBUS_SESSION_BUS_ADDRESS=$(panel_environ | grep '^DBUS_SESSION_BUS_ADDRESS=' | sed -r 's,^[^=]+=,,g')
export XDG_CURRENT_DESKTOP=$( panel_environ | grep '^XDG_CURRENT_DESKTOP=' | sed -r 's,^[^=]+=,,g')
export XDG_SESSION_ID=$( panel_environ | grep '^XDG_SESSION_ID=' | sed -r 's,^[^=]+=,,g')
export XDG_SEAT=$( panel_environ | grep '^XDG_SEAT=' | sed -r 's,^[^=]+=,,g')
export XDG_RUNTIME_DIR=$( panel_environ | grep '^XDG_RUNTIME_DIR=' | sed -r 's,^[^=]+=,,g')
export SHELL_SESSION_ID=$( panel_environ | grep '^SHELL_SESSION_ID=' | sed -r 's,^[^=]+=,,g')
export SESSION_MANAGER=$( panel_environ | grep '^SESSION_MANAGER=' | sed -r 's,^[^=]+=,,g')
#!/bin/sh
set -e
rsync -avX --delete at@ra:.mozilla ~/
#!/bin/sh
set -e
rsync -avX --delete ~/.mozilla at@ra:
#!/usr/bin/env bash
enable -f /run/current-system/sw/lib/bash/sleep sleep
. ~/bin/fix-env-vars
windows=$(wmctrl -l | grep -P ' Mozilla Firefox$' | cut -f 1 -d ' ')
for window in $windows; do
wmctrl -i -c "$window"
done
while pgrep -f firefox-and-push-mozilla; do
sleep 0.05
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment