Changed method to determine whether host provided is reachable so it works on Linux as well (Fixes #1)

Added a more verbose usage/help when invoking the script without parameters (and support -h parameter)
This commit is contained in:
2016-09-23 11:22:53 +02:00
parent 049e440433
commit b0bb909d1b

View File

@@ -1,11 +1,11 @@
#!/bin/bash -e #!/bin/bash -e
# #
# copy_crashplan_id shell scripts to copy the connection key from a remote # copy_crashplan_id - shell scripts to copy the connection key from a remote
# (e.g. headless) Crashplan instance and setup the local # (e.g. headless) Crashplan instance and setup the local
# machine's Crashplan client to connect to it using port # machine's Crashplan client to connect to it using port
# forwarding over an open SSH connection. See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer # forwarding over an open SSH connection. See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer
# #
# Version 1.0, latest version at: https://gitlab.lindenaar.net/scripts/crashplan # Version 1.1, latest version at: https://gitlab.lindenaar.net/scripts/crashplan
# #
# Copyright (c) 2016 Frederik Lindenaar # Copyright (c) 2016 Frederik Lindenaar
# #
@@ -24,7 +24,7 @@
HOST= # name of machine runnig crashplan HOST= # name of machine runnig crashplan
USER= # userid to use to login to machine USER= # userid to use to login to machine
# Leave blank for current user # Leave blank for current user
SRC_SYSTEM=Linux # either Linux, Darwin, osx or detect SRC_SYSTEM=Linux # either Linux, Darwin, osx or detect
# Autodetects if blank (ssh conn, slow!) # Autodetects if blank (ssh conn, slow!)
@@ -56,13 +56,22 @@ file_location() {
esac esac
} }
myname=`basename "$0" .sh`
# determine the connection parameters based on command line and configuration # determine the connection parameters based on command line and configuration
if [ $# -gt 2 -o $# -eq 0 -a -z "$HOST" ]; then if [ $# -gt 2 -o "$1" == "-h" -o "$1" == "--help" -o $# -eq 0 -a -z "$HOST" ]; then
echo "usage: $0 [user@]hostname [linux|osx|detect]" cat<<EOH
if [ -n "$HOST" ]; then
echo " or just $0 to copy from $HOST" usage: $myname [user@]hostname [linux|osx|detect]${HOST:+"
fi or just $myname to copy from $HOST"}
Copy the connection key from a remote (e.g. headless) Crashplan instance and
setup the Crashplan client on local machine to connect to it using SSH port
forwarding (enable with ssh -L $PORT:$ADDR:4243 <name of Crashplan server>)
See also https://support.code42.com/CrashPlan/4/Configuring/Using_CrashPlan_On_A_Headless_Computer
EOH
exit 2 exit 2
elif [ $# -gt 0 ]; then elif [ $# -gt 0 ]; then
conn=$1 conn=$1
@@ -73,7 +82,7 @@ else
fi fi
# ensure the host is reachable # ensure the host is reachable
if ping -o $HOST > /dev/null 2>&1; then if ping -c 1 $HOST > /dev/null 2>&1; then
echo "copying Crashplan connect key from $HOST" echo "copying Crashplan connect key from $HOST"
else else
die "unable to reach host $HOST" die "unable to reach host $HOST"
@@ -101,7 +110,6 @@ src=`file_location source "$SRC_SYSTEM"`
dst=`file_location destination "$os"` dst=`file_location destination "$os"`
# use script name to generate a temp file name, ensure the temp file is removed # use script name to generate a temp file name, ensure the temp file is removed
myname=`basename "$0" .sh`
tmpfile=`mktemp -t "$myname"` tmpfile=`mktemp -t "$myname"`
trap 'rm -f "$tmpfile"' 0 trap 'rm -f "$tmpfile"' 0