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
#
# 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
# 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
#
# 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
#
@@ -56,13 +56,22 @@ file_location() {
esac
}
myname=`basename "$0" .sh`
# determine the connection parameters based on command line and configuration
if [ $# -gt 2 -o $# -eq 0 -a -z "$HOST" ]; then
echo "usage: $0 [user@]hostname [linux|osx|detect]"
if [ -n "$HOST" ]; then
echo " or just $0 to copy from $HOST"
fi
if [ $# -gt 2 -o "$1" == "-h" -o "$1" == "--help" -o $# -eq 0 -a -z "$HOST" ]; then
cat<<EOH
usage: $myname [user@]hostname [linux|osx|detect]${HOST:+"
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
elif [ $# -gt 0 ]; then
conn=$1
@@ -73,7 +82,7 @@ else
fi
# 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"
else
die "unable to reach host $HOST"
@@ -101,7 +110,6 @@ src=`file_location source "$SRC_SYSTEM"`
dst=`file_location destination "$os"`
# use script name to generate a temp file name, ensure the temp file is removed
myname=`basename "$0" .sh`
tmpfile=`mktemp -t "$myname"`
trap 'rm -f "$tmpfile"' 0