Skip to content

Instantly share code, notes, and snippets.

@earchibald
Last active June 17, 2016 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save earchibald/449a72ffddc9062beed723601385495e to your computer and use it in GitHub Desktop.
Save earchibald/449a72ffddc9062beed723601385495e to your computer and use it in GitHub Desktop.
bash script to set up CrashPlan client on OS X. Should be easily modifiable to support Linux.
#!/usr/bin/env bash
# crashplan-setup.sh
usage () {
echo "Usage: $0 <server> [user]"
exit 255
}
SERVER="$1"
if [[ $1 == '' ]] ; then
usage
fi
if nc -z $SERVER 22 >/dev/null ; then
if [[ $2 != '' ]] ; then
REMOTE_USER=$2
else
REMOTE_USER=admin
fi
echo "Fetching .ui_info from $SERVER as user $REMOTE_USER..."
remote_info=$(ssh ${REMOTE_USER}@${SERVER} "cat /var/lib/crashplan/.ui_info" | perl -ne "print if s/^(.*),[^,]+\$/\$1,$SERVER/")
if [[ $remote_info =~ ^[^,]+,[^,]+,[^,]+$ ]] ; then
for ui_info_candidate in \
"~/Library/Application Support/CrashPlan/.ui_info" \
"/Library/Application Support/CrashPlan/.ui_info" \
"/usr/local/crashplan/conf" \
; do
if [[ -e "$ui_info_candidate" ]] ; then
LOCAL_UI_INFO="$ui_info_candidate"
break
fi
done
echo "Executing sudo to edit $LOCAL_UI_INFO (may require your user password)..."
if sudo perl -ni -e "print '$remote_info'" "$LOCAL_UI_INFO" ; then
echo '...done!'
echo "Opening CrashPlan client...";
open -a crashplan
else
echo '...failed!'
echo "Error trying to update $LOCAL_UI_INFO (failed sudo?)"
fi
else
echo "Error getting info from remote host! Stopping without changing local .ui_info file..."
exit 254
fi
else
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment