#!/bin/sh

set -eu

URL="${SJEKKIP_URL:-https://sjekkip.no/onlyip.php}"

usage() {
    cat <<'EOF'
Usage: sjekkip [--help]

Print your public IP address using sjekkip.no.
EOF
}

case "${1:-}" in
    --help|-h)
        usage
        exit 0
        ;;
    "")
        ;;
    *)
        echo "sjekkip: unknown option: $1" >&2
        usage >&2
        exit 1
        ;;
esac

if command -v curl >/dev/null 2>&1; then
    exec curl -fsSL "$URL"
fi

if command -v wget >/dev/null 2>&1; then
    exec wget -qO- "$URL"
fi

echo "sjekkip: curl or wget is required" >&2
exit 1
