#!/bin/bash | |
# crashplan_remote.sh | |
# Author: Luca Zorzi (@LucaTNT) | |
# License: WTFPL (http://www.wtfpl.net) | |
# | |
# Connects to CrashPlan running in a FreeNAS jail and launches the Desktop APP, then reverts all the settings back to their defaults | |
CRASHPLAN_SERVER="192.168.1.78" | |
CRASHPLAN_USER="luca" | |
# Backup the current .ui_info config file | |
sudo cp /Library/Application\ Support/CrashPlan/.ui_info /Library/Application\ Support/CrashPlan/LOCAL.ui_info | |
# Get token and port from the jail, combine them to form a .ui_info config file | |
ssh $CRASHPLAN_USER@$CRASHPLAN_SERVER cat /var/lib/crashplan/.ui_info > /tmp/REMOTE.ui_info | |
CRASHPLAN_PORT=`cat /tmp/REMOTE.ui_info | grep -oE '[0-9]{4},' | grep -oE '[0-9]{4}' | head -n 1` | |
CRASHPLAN_TOKEN=`cat /tmp/REMOTE.ui_info | awk -F ',' '{print $2}'` | |
rm /tmp/REMOTE.ui_info | |
echo "PORT: $CRASHPLAN_PORT" | |
echo "TOKEN: $CRASHPLAN_TOKEN" | |
echo "4200,$CRASHPLAN_TOKEN,127.0.0.1" | sudo tee /Library/Application\ Support/CrashPlan/.ui_info > /dev/null; | |
echo ".ui_info updated, creating SSH tunnel..." | |
# -f: background | |
# -N: No command sent to SSH server | |
# -M: Master mode, required to be able to control ssh while in the background | |
# -S: Socket file, used to control ssh | |
# -L: Bind port $CRASHPLAN_PORT on the remote host (127.0.0.1, relative to the server) to the local port 4200 | |
ssh -f -N -M -S /tmp/crashplan-remote.sock -L 4200:127.0.0.1:$CRASHPLAN_PORT $CRASHPLAN_USER@$CRASHPLAN_SERVER | |
echo "SSH tunnel established, launching CrashPlan Desktop" | |
/Applications/CrashPlan.app/Contents/MacOS/CrashPlan > /dev/null 2>&1 | |
echo "CrashPlan Desktop closed, terminating SSH tunnel..." | |
# Terminate the connection using the specified socket file (-S) | |
ssh -S /tmp/crashplan-remote.sock -O exit $CRASHPLAN_USER@$CRASHPLAN_SERVER | |
echo "Restoring local CrashPlan settings..." | |
sudo cp /Library/Application\ Support/CrashPlan/LOCAL.ui_info /Library/Application\ Support/CrashPlan/.ui_info | |
echo "CrashPlan Desktop closed, terminating SSH tunnel..." | |
# Terminate the connection using the specified socket file (-S) | |
ssh -S /tmp/crashplan-remote.sock -O exit $CRASHPLAN_USER@$CRASHPLAN_SERVER | |
echo "Restoring local CrashPlan settings..." | |
sudo mv /Library/Application\ Support/CrashPlan/LOCAL.ui_info /Library/Application\ Support/CrashPlan/.ui_info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment