# shellcheck shell=bash
# shellcheck source=scripts/shared/lib/source_only
. "${BASH_SOURCE%/*}"/source_only

ensure_shflags() {
    if [ -f /usr/share/shflags/shflags ]; then
	. /usr/share/shflags/shflags
	return
    fi

    if [ ! -f .shflags ]; then
        echo "Downloading shflags ${SHFLAGS_VERSION}"
        if ! curl -L "https://raw.githubusercontent.com/kward/shflags/${SHFLAGS_VERSION}/src/shflags" > .shflags; then
            echo "$0 needs shflags in /usr/share/shflags/shflags or locally as .shflags." 1>&2
            echo "It was unable to download it; please install it and try again." 1>&2
            exit 1
        fi
    fi

    . ./.shflags
}

SHFLAGS_VERSION=${SHFLAGS_VERSION:=1.0.3}
ensure_shflags
