Commit b0bb909d1be47d11956cdf707f5e59f256daef8f

Authored by Frederik Lindenaar
1 parent 049e4404

Changed method to determine whether host provided is reachable so it works on Li…

…nux as well (Fixes #1)

Added a more verbose usage/help when invoking the script without parameters (and support -h parameter)
Showing 1 changed file with 18 additions and 10 deletions
copy_crashplan_id
1 #!/bin/bash -e 1 #!/bin/bash -e
2 # 2 #
3 -# copy_crashplan_id shell scripts to copy the connection key from a remote 3 +# copy_crashplan_id - shell scripts to copy the connection key from a remote
4 # (e.g. headless) Crashplan instance and setup the local 4 # (e.g. headless) Crashplan instance and setup the local
5 # machine's Crashplan client to connect to it using port 5 # machine's Crashplan client to connect to it using port
6 # forwarding over an open SSH connection. See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer 6 # forwarding over an open SSH connection. See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer
7 # 7 #
8 -# Version 1.0, latest version at: https://gitlab.lindenaar.net/scripts/crashplan 8 +# Version 1.1, latest version at: https://gitlab.lindenaar.net/scripts/crashplan
9 # 9 #
10 # Copyright (c) 2016 Frederik Lindenaar 10 # Copyright (c) 2016 Frederik Lindenaar
11 # 11 #
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 HOST= # name of machine runnig crashplan 24 HOST= # name of machine runnig crashplan
25 USER= # userid to use to login to machine 25 USER= # userid to use to login to machine
26 # Leave blank for current user 26 # Leave blank for current user
27 -SRC_SYSTEM=Linux # either Linux, Darwin, osx or detect 27 +SRC_SYSTEM=Linux # either Linux, Darwin, osx or detect
28 # Autodetects if blank (ssh conn, slow!) 28 # Autodetects if blank (ssh conn, slow!)
29 29
30 30
@@ -56,13 +56,22 @@ file_location() { @@ -56,13 +56,22 @@ file_location() {
56 esac 56 esac
57 } 57 }
58 58
  59 +myname=`basename "$0" .sh`
59 60
60 # determine the connection parameters based on command line and configuration 61 # determine the connection parameters based on command line and configuration
61 -if [ $# -gt 2 -o $# -eq 0 -a -z "$HOST" ]; then  
62 - echo "usage: $0 [user@]hostname [linux|osx|detect]"  
63 - if [ -n "$HOST" ]; then  
64 - echo " or just $0 to copy from $HOST"  
65 - fi 62 +if [ $# -gt 2 -o "$1" == "-h" -o "$1" == "--help" -o $# -eq 0 -a -z "$HOST" ]; then
  63 + cat<<EOH
  64 +
  65 +usage: $myname [user@]hostname [linux|osx|detect]${HOST:+"
  66 + or just $myname to copy from $HOST"}
  67 +
  68 +Copy the connection key from a remote (e.g. headless) Crashplan instance and
  69 +setup the Crashplan client on local machine to connect to it using SSH port
  70 +forwarding (enable with ssh -L $PORT:$ADDR:4243 <name of Crashplan server>)
  71 +
  72 +See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer
  73 +
  74 +EOH
66 exit 2 75 exit 2
67 elif [ $# -gt 0 ]; then 76 elif [ $# -gt 0 ]; then
68 conn=$1 77 conn=$1
@@ -73,7 +82,7 @@ else @@ -73,7 +82,7 @@ else
73 fi 82 fi
74 83
75 # ensure the host is reachable 84 # ensure the host is reachable
76 -if ping -o $HOST > /dev/null 2>&1; then 85 +if ping -c 1 $HOST > /dev/null 2>&1; then
77 echo "copying Crashplan connect key from $HOST" 86 echo "copying Crashplan connect key from $HOST"
78 else 87 else
79 die "unable to reach host $HOST" 88 die "unable to reach host $HOST"
@@ -101,7 +110,6 @@ src=`file_location source &quot;$SRC_SYSTEM&quot;` @@ -101,7 +110,6 @@ src=`file_location source &quot;$SRC_SYSTEM&quot;`
101 dst=`file_location destination "$os"` 110 dst=`file_location destination "$os"`
102 111
103 # use script name to generate a temp file name, ensure the temp file is removed 112 # use script name to generate a temp file name, ensure the temp file is removed
104 -myname=`basename "$0" .sh`  
105 tmpfile=`mktemp -t "$myname"` 113 tmpfile=`mktemp -t "$myname"`
106 trap 'rm -f "$tmpfile"' 0 114 trap 'rm -f "$tmpfile"' 0
107 115