Changed the way we generate the api data back to the original. Clarified
comments. Added more logic to how we obtain the public IPv4 address,
such that input is sanitized.
If curl is not found, then the rest of the script can't run so we exit
with an error code. We try to use DNS if HTTPS fails to obtain
a valid IP. Added log messages for these events.
Changed back so that curl is used by default, however dig can be used
as a backup if curl is not installed on the system. Additionally took
my fear of code injection into account by sanitizing the remote input
through a regex.
Used shell built-in command -v to determine if dig is installed and if
it is, use it as default for getting the ip-address. Also made the use
of brackets consistent and updated the the way the data variable is
created before it is sent with curl to make it more readable in the
code.
Permits to run the script on simpler/lighter Linux distributions,
e.g. OpenWRT, where the grep utility available does not permit to use
Perl extended regexp (the `grep -P` option)
Instead of creating a log file. This change leverages the syslog. This allows us to not have to manually rotate logs, or worry about the log file filling up the file system. This also give us timestamps of the logging without having to create the timestamps ourselves. Messages are logged to /var/log/messages by default.