Skip to content

Commit

Permalink
fix argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
filiparag committed Feb 21, 2023
1 parent aabb7f6 commit 8fd7780
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions hetzner_ddns.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#!/bin/sh

self='hetzner_ddns'

if ! [ -z "$1" ]; then
self="${self}.$1"
fi
daemon=0

for arg in $(seq "$#"); do
param="$(eval "echo \$$arg")"
case "$param" in
'--daemon'|'-d')
daemon=1;;
'--help'|'-h')
man hetzner_ddns;
exit 0;;
*)
self="${self}.$param";;
esac
done

# Read variabels from configuration file
if test -G "/usr/local/etc/$self.conf"; then
. "/usr/local/etc/$self.conf"
records_escaped="$(echo "$records" | sed 's:\*:\\\*:g')"
else
>&2 echo 'unable to read configuration file'
>&2 echo "unable to read configuration file /usr/local/etc/$self.conf"
exit 78
fi

Expand Down Expand Up @@ -195,7 +205,7 @@ run_ddns() {
done
}

if [ "$1" = '--daemon' ]; then
if [ "$daemon" = '1' ]; then
# Deamonize and write PID to file
if touch "/var/run/$self.pid";
then
Expand Down

0 comments on commit 8fd7780

Please sign in to comment.