aboutsummaryrefslogtreecommitdiffstats
path: root/testing/simplesnap/0001-fix-simplesnap-line-2-dotlockfile-command-not-found.patch
blob: 2c2954ff7e9c883449890ea3afa9c8fb82c11775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From f477a6895512c77eef3637581ab36ad8319a0204 Mon Sep 17 00:00:00 2001
From: Henrik Riomar <henrik.riomar@gmail.com>
Date: Mon, 18 Jun 2018 19:15:54 +0200
Subject: [PATCH] fix: simplesnap: line 2??: dotlockfile: command not found

Closes: #12
---
 simplesnap | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/simplesnap b/simplesnap
index 6d60885..63fc0c2 100755
--- a/simplesnap
+++ b/simplesnap
@@ -149,15 +149,11 @@ done
 SSHCMD="${SSHCMD:-ssh}"
 WRAPCMD="${WRAPCMD:-simplesnapwrap}"
 
-DATE="gdate"
-gdate &> /dev/null || [ $? -eq 127 ] && DATE="date"
-SED="gsed"
-gsed &> /dev/null || [ $? -eq 127 ] && SED="sed"
-GREP="ggrep"
-ggrep &> /dev/null || [ $? -eq 127 ] && GREP="grep"
-HEAD="ghead"
-ghead -h &> /dev/null || [ $? -eq 127 ] && HEAD="head"
-
+command -v gdate > /dev/null && DATE="gdate" || DATE="date"
+command -v gsed > /dev/null && SED="gsed" || SED="sed"
+command -v ggrep > /dev/null && GREP="ggrep" || GREP="grep"
+command -v ghead > /dev/null && HEAD="ghead" || HEAD="head"
+command -v dotlockfile > /dev/null && LOCKMETHOD="dotlockfile" || LOCKMETHOD="mkdir"
 
 # Validating
 [ -n "$SSHCMD" ] || syntaxerror "Invalid SSH command: $SSHCMD"
@@ -244,23 +240,17 @@ fi
 
 LOCKFILE="${MOUNTPOINT}/${HOST}/.lock"
 
-if dotlockfile -r 0 -l -p "${LOCKFILE}"; then
-  LOCKMETHOD="dotlockfile"
+if [ x"$LOCKMETHOD" = x"dotlockfile" ] && ${LOCKMETHOD} -r 0 -l -p "${LOCKFILE}" ; then
   logit "Lock obtained at ${LOCKFILE} with dotlockfile"
   trap "ECODE=$?; dotlockfile -u \"${LOCKFILE}\"; exit $ECODE" EXIT INT TERM
-else
-  RETVAL="$?"
-  if [ "$RETVAL" = "127" ]; then
-    LOCKMETHOD="mkdir"
-    mkdir "${LOCKFILE}" || exiterror "Could not obtain lock at ${LOCKFILE}; if $0 is not already running, rmdir that path."
+elif [ x"$LOCKMETHOD" = x"mkdir" ]; then
+    ${LOCKMETHOD} "${LOCKFILE}" || exiterror "Could not obtain lock at ${LOCKFILE}; if $0 is not already running, rmdir that path."
     logit "Lock obtained at ${LOCKFILE} with mkdir"
     trap "ECODE=$?; rmdir \"${LOCKFILE}\"" EXIT INT TERM
-  else
+else
     exiterror "Could not obtain lock at ${LOCKFILE}; $0 likely already running."
-  fi
 fi
 
-
 reap () {
   DATASET="$1"
        # We always save the most recent.
-- 
2.17.1