#!/usr/bin/env bash
set -euo pipefail

case ${USER} in
    root)
        exec su --shell /bin/bash --command "$0 $@" gvm
        ;;
    gvm)
        ;;
    *)
        >&2 echo "Must be run as root or gvm user not ${USER}"
        exit 1
        ;;
esac

while getopts d OPTION "$@"; do
        case ${OPTION} in
                d)
                        set -x
                        ;;
        esac
done
shift $((OPTIND - 1))

greenbone-nvt-sync
# Note that Greenbone recommends to sync CERT *after* SCAP, as the
# former depends on the later. See
# https://github.com/greenbone/gvmd/blob/main/INSTALL.md#keeping-the-feeds-up-to-date
for FEED_TYPE in SCAP CERT GVMD_DATA; do
    greenbone-feed-sync --type ${FEED_TYPE}
done
