aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-09-14 16:57:18 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-09-14 17:41:58 +1200
commitf38d67dd576b77b58dafcd3a58516c51542733e3 (patch)
tree899f1b42bb9c41784f715e42df3091cc50f0228b
parentAdd self-identification (diff)
downloadpsshd-f38d67dd576b77b58dafcd3a58516c51542733e3.tar.gz
psshd-f38d67dd576b77b58dafcd3a58516c51542733e3.zip
Search for needed commands in PATH
-rwxr-xr-xpsshd27
1 files changed, 12 insertions, 15 deletions
diff --git a/psshd b/psshd
index faec1bf..f8dcdc6 100755
--- a/psshd
+++ b/psshd
@@ -17,20 +17,17 @@
# Name self
self=psshd
-# Path to autossh binary (not any wrapper script)
-autossh='/usr/lib/autossh/autossh'
+# Extend path to find autossh and start-stop-daemon binaries
+PATH=/usr/lib/autossh/autossh:/sbin:$PATH
-# Path to start-stop-daemon binary
-startstopdaemon='/sbin/start-stop-daemon'
-
-# Neither of those are likely to be in your PATH if you're a normal user, so we
-# hardcode the paths and test for their existence
-if [[ ! -x "$autossh" ]]; then
- printf "Can't execute ${autossh}!\n" >&2
- exit 1
-elif [[ ! -x "$startstopdaemon" ]]; then
- printf "Can't execute ${startstopdaemon}!\n" >&2
- exit 1
+# Check we have access to the required binaries
+if ! type -p autossh >/dev/null; then
+ printf '%s - Could not find autossh in PATH\n' "$script" >&2
+ exit 127
+fi
+if ! type -p start-stop-daemon >/dev/null; then
+ printf '%s - Could not find start-stop-daemon in PATH\n' "$script" >&2
+ exit 127
fi
# Get port in options
@@ -72,10 +69,10 @@ AUTOSSH_PORT="$port"
export AUTOSSH_PIDFILE AUTOSSH_PORT
# Use start-stop-daemon to run it sanely
-"$startstopdaemon" \
+start-stop-daemon \
--start \
--quiet \
--pidfile "$AUTOSSH_PIDFILE" \
- --exec "$autossh" \
+ --exec "$(type -p autossh)" \
-- "$@"