aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2018-01-04 21:48:04 +0100
committerKamil Cholewiński <harry666t@gmail.com>2018-01-04 22:01:11 +0100
commit511ffe59743d0121cee2148ef05e552266d948af (patch)
tree8d82902b6f3c706664486cb259d99138fe1211cc
parentf9106ca0a9dc73b0f793b47ae8f454abb76330af (diff)
downloadjudo-511ffe59743d0121cee2148ef05e552266d948af.zip
judo-511ffe59743d0121cee2148ef05e552266d948af.tar.gz
judo-511ffe59743d0121cee2148ef05e552266d948af.tar.bz2
Fix directory paths
This fixes a bug where directory paths did not behave exactly as documented in the readme. Since this breaks all of my personal scripts that relied on this bug, I'll be bumping the version too :)
-rwxr-xr-xexamples/bootstrap/script2
-rw-r--r--host.go54
2 files changed, 46 insertions, 10 deletions
diff --git a/examples/bootstrap/script b/examples/bootstrap/script
index 01b1702..5b890d8 100755
--- a/examples/bootstrap/script
+++ b/examples/bootstrap/script
@@ -2,5 +2,5 @@
set -eu
echo "Bootstrapping ${HOSTNAME}!"
echo "My current working directory: $(pwd)"
-data="$(cat ./bootstrap/data.txt)"
+data="$(cat ./examples/bootstrap/data.txt)"
echo "My data: $data"
diff --git a/host.go b/host.go
index 07ed2a5..0132011 100644
--- a/host.go
+++ b/host.go
@@ -66,21 +66,57 @@ func (host *Host) SendRemoteAndRun(job *Job) (err error) {
}
}()
+ // Figure out the correct path for the remote script
+ var remoteScriptDir string
+ if job.Script.dirmode {
+ remoteScriptDir = path.Join(
+ workdir,
+ job.Script.fname,
+ )
+ } else {
+ remoteScriptDir = path.Join(
+ workdir,
+ path.Dir(job.Script.fname),
+ )
+ }
+
+ // Create remote directory structure
+ if err = host.SSH(
+ job,
+ fmt.Sprintf("mkdir -p %s", remoteScriptDir),
+ ); err != nil {
+ return err
+ }
+
// push files to remote
- host.pushFiles(job, job.Script.fname, workdir)
+ if job.Script.dirmode {
+ if err = host.pushFiles(
+ job,
+ job.Script.fname,
+ // We need to strip one level of path, otherwise
+ // scp will duplicate it. Eh...
+ path.Dir(remoteScriptDir),
+ ); err != nil {
+ return err
+ }
+ } else {
+ if err = host.pushFiles(
+ job,
+ job.Script.fname,
+ remoteScriptDir,
+ ); err != nil {
+ return err
+ }
+ }
- // are we in dirmode?
+ // Figure out what is the remote command
var remoteCommand string
- if !job.Script.dirmode {
- remoteCommand = path.Join(
- workdir,
- path.Base(job.Script.fname),
- )
+ if job.Script.dirmode {
+ remoteCommand = path.Join(remoteScriptDir, "script")
} else {
remoteCommand = path.Join(
- workdir,
+ remoteScriptDir,
path.Base(job.Script.fname),
- "script",
)
}