#!/bin/bash ## Title: CrashPlan UI Config ## Description: Configure the CrashPlan UI to connect to a remote server or revert back to local host. ## Also fixes a UI crash bug in certain versions. ## Author: Bill Howe ## Date: 08/09/2015 ## Recent Changes: Re-designed into functions, added root and version checking. ## Required, check for root permissions ## check_root=$(id -u) if [ $check_root != 0 ];then echo ">>ERROR: Must have root permissions to execute this script. (either as root user or sudo)" exit 1 fi ## Setting up variables - Configure to Crashplan's root ## CPROOT="/opt/crashplan" ## Store Crashplan version ## CPVERSION="$(awk '/CPVERSION/ {print $3}' ${CPROOT}/log/app.log)" ## Functions ## function initial_symlink_setup { # check to see if either ui file does not exist if [[ ! -f /var/lib/crashplan/.ui_info.local ]]; then # local file does not exist, create it echo ">>Inital Setup: Creating local ui_info version..." sudo cp -v /var/lib/crashplan/.ui_info /var/lib/crashplan/.ui_info.local fi if [[ ! -f /var/lib/crashplan/.ui_info.remote ]]; then echo ">>Initial Setup: Copying remote UI file to local system..." echo -e "=>IP or Hostname of remote system: \c" read INITIALSYSTEM echo -e "=>Username on remote system: \c" read INITIALUSER echo -e ">> Enter login password next to copy remote UI id file to local system." sudo scp ${INITIALUSER}@${INITIALSYSTEM}:/var/lib/crashplan/.ui_info /var/lib/crashplan/.ui_info.remote sudo sed -i 's/^4243/4200/' /var/lib/crashplan/.ui_info.remote # set to local initially sudo ln -fs /var/lib/crashplan/.ui_info.local /var/lib/crashplan/.ui_info fi } function configure_local { echo -e "\n>>Configuring for Local system" if [[ ${CPNEW} == "true" ]];then # Version >= 4.3.0, change symlink sudo ln -sf /var/lib/crashplan/.ui_info.local /var/lib/crashplan/.ui_info else # Version < 4.3.0, edit ui.properties sed -i "s/servicePort=4200/#servicePort=4243/" ${CPROOT}/conf/ui.properties fi echo -e ">>...Complete. CrashPlan UI ready for local system.\n" } function configure_remote { echo -e "\n>>Configuring for Remote System" echo -e "=>IP/Hostname of Remote system to connect to: \c" read REMOTESYSTEM echo -e "=>Username on Remote System: \c" read REMOTEUSER if [[ ${CPNEW} == "true" ]];then # Version >= 4.3.0, change symlink sudo ln -sf /var/lib/crashplan/.ui_info.remote /var/lib/crashplan/.ui_info else # Version < 4.3.0, edit ui.properties sed -i "s/#servicePort=4243/servicePort=4200/" ${CPROOT}/conf/ui.properties fi echo -e ">>Login to remote system via ssh below, then launch CrashPlanDesktop locally from non-ssh terminal or desktop.\n" echo -e ">>Opening SSH connection to remote system..." ssh -L 4200:localhost:4243 ${REMOTEUSER}@${REMOTESYSTEM} } function fix_ui_bug { # Check if CP Version is >= 3.5.3 if [[ $(echo | awk -v n1=${CPVERSION} -v n2=3.5.3 '{if (n1>=n2) print ("true"); else print ("false");}') == "true" ]]; then UITEST1="true" else UITEST1="false" fi # Check if CP Version is <= 3.6.4 if [[ $(echo | awk -v n1=${CPVERSION} -v n2=3.6.4 '{if (n1<=n2) print ("true"); else print ("false");}') == "true" ]]; then UITEST2="true" else UITEST2="false" fi # If both true, fix the bug if [[ ${UITEST1} == "true" && ${UITEST2} == "true" ]];then echo ">>Your Crashplan version, ${CPVERSION}, is affected by the UI Crash Bug, attempting to fix..." echo -e "\n>>Adding '-Dorg.eclipse.swt.browser.DefaultType=mozilla' to ${CPROOT}/bin/run.conf..." sed -i "/GUI_JAVA_OPTS/D" ${CPROOT}/bin/run.conf echo 'GUI_JAVA_OPTS="-Dfile.encoding=UTF-8 -Dapp=CrashPlanDesktop -DappBaseName=CrashPlan -Xms20m -Xmx512m -Djava.net.preferIPv4Stack=true -Dsun.net.inetaddr.ttl=300 -Dnetworkaddress.cache.ttl=300 -Dsun.net.inetaddr.negative.ttl=0 -Dnetworkaddress.cache.negative.ttl=0 -Dc42.native.md5.enabled=false -Dorg.eclipse.swt.browser.DefaultType=mozilla"' >> ${CPROOT}/bin/run.conf echo -e ">>...Done." else echo ">>Your Crashplan version, ${CPVERSION}, is NOT affected by the UI Crash Bug." fi } ### Main Program ### # Check to see if Crashplan version is 4.3.0 or greater, if so, initalize symlinks setup if [[ $(echo | awk -v n1=${CPVERSION} -v n2=4.3.0 '{if (n1>=n2) print ("true"); else print ("false");}') == "true" ]]; then CPNEW="true" initial_symlink_setup else CPNEW="false" fi ## Main Menu ## echo -e "===== CrashPlan UI Configuration =====" echo -e "----- Your Version: ${CPVERSION} -----\n" echo -e "Configure CrashPlan to:" echo -e "1) Connect to Local system" echo -e "2) Connect to Remote headless system" echo -e "3) Fix UI Crash Bug (CP vers 3.5.3 to 3.6.4)" echo -e "q) Quit" echo -e "\nSelection:\c" read CHOICE case ${CHOICE} in 1) # Configure for local configure_local exit 0 ;; 2) #Configure for remote configure_remote ;; 3) #Fix UI Crashing fix_ui_bug exit 0 ;; q) #Quit echo -e "Quiting without making changes.\n" exit 0 ;; *) #Unknwon response, quit echo -e "Invalid selection...quiting.\n" exit 1 ;; esac