aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2014-03-11 00:43:36 +0100
committerJulien Dessaux2014-03-11 00:43:36 +0100
commitcf540a861757572e38e3d5fbd641b909953a3f9d (patch)
tree763574c3103bf4f355ca1058fa5b90d157d272aa
parentInitial draft (diff)
downloadcf-remote-master.tar.gz
cf-remote-master.tar.bz2
cf-remote-master.zip
Moved usage on top and added some error checkingHEADmaster
Diffstat (limited to '')
-rwxr-xr-xcf-remote42
1 files 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 <branch> : the git branch you are testing (default master)
+ -l <remote_login> : the login to ssh with (default root)
+ -h <remote_host> : the host to test your policies onto (default localhost)
+ -p <remote_port> : the port to ssh to (default 22)
+ -t <tunnel_port> : 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 <branch> : the git branch you are testing (default master)
- -l <remote_login> : the login to ssh with (default root)
- -h <remote_host> : the host to test your policies onto (default localhost)
- -p <remote_port> : the port to ssh to (default 22)
- -t <tunnel_port> : 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} &&