From 6c9245be0a6600800cb5753db621bc1f9eb8ded5 Mon Sep 17 00:00:00 2001 From: maride Date: Fri, 21 Jun 2024 10:23:52 +0200 Subject: [PATCH] Add comments, add check for required arguments --- usr/sbin/sshutterd | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/usr/sbin/sshutterd b/usr/sbin/sshutterd index ceab9a7..d98f113 100755 --- a/usr/sbin/sshutterd +++ b/usr/sbin/sshutterd @@ -1,18 +1,27 @@ #!/bin/bash -if [ -f "/etc/sshutter.conf" ]; then - . /etc/sshutter.conf -fi - function log { echo "$(date +'%Y-%m-%d %H:%M:%S') $@" } +# Include config file if present +if [ -f "/etc/sshutter.conf" ]; then + . /etc/sshutter.conf +fi + +# Check if args are given +if [ "$WHITELIST" -eq "" ] || [ "$PORT" -eq "" ] || [ "$TARGET" -eq "" ]; then + echo "Error: you need to specify WHITELIST, PORT and TARGET, either in /etc/sshutter.conf or through environment variables." 1>&2 + exit 1 +fi + +# Check if permissions are high enough if [ "$UID" -ne 0 ]; then echo "Error: must be root." 1>&2 exit 1 fi +# Main loop while [ true ]; do ping -c 3 "$TARGET" 1>/dev/null if [ "$?" -eq 0 ]; then