Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hello Everyone,
- For Linux Mint users. I just thought I would share this script that will clone your Firefox Profile and YASD "Yet Another Speed Dial" add-on in Firefox to other PSs on your LAN. The main idea is if you have more than one PC on your LAN that run Firefox and they all use YASD you may easily clone from your Master PC, the one you sit at most often, to other PCs on your LAN. You will want to use just one "Master" PC to clone from, or clarity, have this script live on just your Master PC.
- Also, optionally, you may add an alias to your .bashrc; this way, you can just type clonefirefox at the terminal and fire off the script that way.
- This script uses SSH to work, so if you use SSH ports other than the default port "22", you will have to edit the port number in the script.
- If you use Chrome on Linux, you may want to switch to Firefox; it is faster, fewer resources are used with Firefox.
- HTH
- #!/bin/bash
- # === Firefox Profile Multi-PC Cloner (resilient version) ===
- # === CONFIG ===
- REMOTE_PROFILE_DIR=".mozilla/firefox"
- TARGETS=(
- "[email protected]:22"
- "[email protected]:22"
- "[email protected]:22"
- "[email protected]:22"
- "[email protected]:22"
- )
- # === Auto-detect local profile ===
- LOCAL_PROFILE=$(awk -F= '/^Path/ && f {print $2; exit} /^\[Profile[0-9]+\]/ {f=1}' ~/.mozilla/firefox/profiles.ini)
- if [[ -z "$LOCAL_PROFILE" ]]; then
- echo "β Could not auto-detect local Firefox profile. Aborting."
- exit 1
- fi
- LOCAL_PROFILE_DIR="$HOME/.mozilla/firefox/$LOCAL_PROFILE"
- # === Get local IPs/hostname to skip self ===
- LOCAL_IPS=($(hostname -I))
- LOCAL_HOSTNAME=$(hostname)
- # === Create tarball ===
- cd "$HOME/.mozilla/firefox" || exit 1
- TAR_FILE="$HOME/firefox-clone.tar.gz"
- echo "$(date '+%F %T') π¦ Creating profile archive..."
- tar czf "$TAR_FILE" "$LOCAL_PROFILE" profiles.ini
- # === Loop through targets ===
- for entry in "${TARGETS[@]}"; do
- IFS=':' read -r userhost port <<< "$entry"
- user=$(echo "$userhost" | cut -d@ -f1)
- host=$(echo "$userhost" | cut -d@ -f2)
- # Skip self if IP or hostname matches
- if [[ "${LOCAL_IPS[*]}" =~ $host || "$LOCAL_HOSTNAME" == "$host" ]]; then
- echo "$(date '+%F %T') π Skipping self ($host)"
- continue
- fi
- echo -e "\n$(date '+%F %T') π Cloning to $userhost (port $port)..."
- SOCKET_PATH="/tmp/ssh_mux_$user@$host:$port"
- # Try to establish SSH connection with timeout
- if ssh -p "$port" -o ConnectTimeout=5 -o ConnectionAttempts=1 -o ControlMaster=yes -o ControlPersist=300 -o ControlPath="$SOCKET_PATH" -Nf "$userhost" 2>/dev/null; then
- echo "$(date '+%F %T') β Closing Firefox on $host..."
- ssh -p "$port" -o ConnectTimeout=5 -o ControlPath="$SOCKET_PATH" "$userhost" "pkill -u \$USER firefox" 2>/dev/null
- echo "$(date '+%F %T') π Backing up existing profile on $host..."
- ssh -p "$port" -o ConnectTimeout=5 -o ControlPath="$SOCKET_PATH" "$userhost" \
- "mkdir -p ~/.mozilla/firefox/backups && cp -r ~/.mozilla/firefox/* ~/.mozilla/firefox/backups/profile_backup_$(date +%Y%m%d_%H%M%S)"
- echo "$(date '+%F %T') β»οΈ Rotating backups (keeping last 3)..."
- ssh -p "$port" -o ConnectTimeout=5 -o ControlPath="$SOCKET_PATH" "$userhost" \
- "cd ~/.mozilla/firefox/backups && ls -dt profile_backup_* 2>/dev/null | tail -n +4 | xargs -r rm -rf"
- echo "$(date '+%F %T') π€ Sending archive..."
- scp -P "$port" -o ConnectTimeout=5 -o ControlPath="$SOCKET_PATH" "$TAR_FILE" "$userhost:~"
- echo "$(date '+%F %T') π Extracting profile on remote..."
- ssh -p "$port" -o ConnectTimeout=5 -o ControlPath="$SOCKET_PATH" "$userhost" \
- "rm -rf ~/.mozilla/firefox/* && mkdir -p ~/.mozilla/firefox && tar xzf ~/firefox-clone.tar.gz -C ~/.mozilla/firefox/"
- echo "$(date '+%F %T') β Done with $userhost"
- # Close SSH connection
- ssh -O exit -o ControlPath="$SOCKET_PATH" "$userhost" 2>/dev/null
- else
- echo "$(date '+%F %T') β οΈ Skipping $userhost: SSH connection failed or timed out."
- fi
- done
- # === Clean up ===
- echo "$(date '+%F %T') π§Ή Cleaning up local tarball..."
- rm -f "$TAR_FILE"
- echo -e "\n$(date '+%F %T') π Firefox profile has been cloned to all reachable targets."
- exit 0
- ################################################################################
- .bashrc
- ################################################################################
- Ensure the script is in your home directory
- Ensure the script is executable
- chmod +x clone_firefox_profile.sh
- Open your .bashrc in your home directory
- nano .bashrc
- I added my special aliases under what you see below that is in a .bashrc file
- After you save the .bashrc don't forget to run "source ~/.bashrc" to update the .bashrc file
- also sudo -i to root and do the same to the.bashrc that lives in /root
- # Alias definitions.
- # You may want to put all your additions into a separate file like
- # ~/.bash_aliases, instead of adding them here directly.
- # See /usr/share/doc/bash-doc/examples in the bash-doc package.
- if [ -f ~/.bash_aliases ]; then
- . ~/.bash_aliases
- fi
- #begin my add
- alias clonefirefox="~/clone_firefox_profile.sh"
- #end my add
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement