Add comments, add check for required arguments

This commit is contained in:
maride 2024-06-21 10:23:52 +02:00
parent 4e450a270d
commit 6c9245be0a

View File

@ -1,18 +1,27 @@
#!/bin/bash #!/bin/bash
if [ -f "/etc/sshutter.conf" ]; then
. /etc/sshutter.conf
fi
function log { function log {
echo "$(date +'%Y-%m-%d %H:%M:%S') $@" 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 if [ "$UID" -ne 0 ]; then
echo "Error: must be root." 1>&2 echo "Error: must be root." 1>&2
exit 1 exit 1
fi fi
# Main loop
while [ true ]; do while [ true ]; do
ping -c 3 "$TARGET" 1>/dev/null ping -c 3 "$TARGET" 1>/dev/null
if [ "$?" -eq 0 ]; then if [ "$?" -eq 0 ]; then