From cf540a861757572e38e3d5fbd641b909953a3f9d Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 11 Mar 2014 00:43:36 +0100 Subject: Moved usage on top and added some error checking --- cf-remote | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/cf-remote b/cf-remote index 2d4a245..b7d6b69 100755 --- a/cf-remote +++ b/cf-remote @@ -8,6 +8,28 @@ REMOTE_HOST=localhost REMOTE_PORT=22 TUNNEL_PORT=2269 +function usage { + echo "Usage: $0 [OPTIONS] COMMAND [ARGS] +COMMANDS : + init : init the remote host testing environment + exec : update remote host and run cf-agent -K [ARGS] + clean : cleans the remote host testing environment +Options : + -b : the git branch you are testing (default master) + -l : the login to ssh with (default root) + -h : the host to test your policies onto (default localhost) + -p : the port to ssh to (default 22) + -t : the port with which to establish the reverse tunnel to your machine + -f : override remote lock" >&2 + exit 1 +} + +function cleanup { + echo "Unknown error, rerun with bash -x for further information" } +} + +trap cleanup ERR + function run_ssh { local CMD=$1 local RETURN=${2:-} @@ -34,22 +56,6 @@ function run_ssh_interactive { return $code } -function usage { - echo "Usage: $0 [OPTIONS] COMMAND [ARGS] -COMMANDS : - init : init the remote host testing environment - exec : update remote host and run cf-agent -K [ARGS] - clean : cleans the remote host testing environment -Options : - -b : the git branch you are testing (default master) - -l : the login to ssh with (default root) - -h : the host to test your policies onto (default localhost) - -p : the port to ssh to (default 22) - -t : the port with which to establish the reverse tunnel to your machine - -f : override remote lock" >&2 - exit 1 -} - function lock { run_ssh 'mkdir /srv/cfengine-lock' || { run_ssh "cat /srv/cfengine-lock/lock" owner @@ -89,6 +95,10 @@ case "${1:-}" in ;; exec) lock + run_ssh 'test -d /srv/cfengine' || { + echo "/srv/cfengine doesn't exist on ${REMOTE_HOST}, did you forget to run init?" + exit 1 + } run_ssh_interactive "cd /srv/cfengine && git remote update && git reset --hard origin/${BRANCH} && -- cgit v1.2.3