Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active September 10, 2018 05:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/5c6447fe40a112d23be08af0bd351497 to your computer and use it in GitHub Desktop.
Save ivan/5c6447fe40a112d23be08af0bd351497 to your computer and use it in GitHub Desktop.
Share a Chrome profile on multiple Linuxes without Chrome Sync
#!/bin/bash
set -eu -o pipefail
# We share a Chrome profile on multiple machines using a network filesystem,
# but we can't have more than one Chrome using it at the same time.
#
# Read SingletonLock to determine which machine Chrome is running on
# and Chrome's PID, then quit it on the remote machine if necessary.
profile=$HOME/.config/google-chrome
hostname=$(hostname)
host_pid=$(readlink -- "$profile/SingletonLock" || echo "$hostname-0")
host=$(echo "$host_pid" | sed -r -- 's/-[0-9]+$//g')
pid=$(echo "$host_pid" | egrep -o -- '[0-9]+$')
if [[ "$hostname" != "$host" ]]; then
echo "Chrome is running on $host, sshing in to quit it..."
timeout 5s ssh "$USER@$host" "kill -INT $pid && wait-for-process-exit $pid"
fi
exec /usr/bin/google-chrome "--user-data-dir=$profile" "$@"
@ivan
Copy link
Author

ivan commented Sep 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment