#!/bin/bash

GREEN="\033[01;32m"
RESET="\033[00m"

# Check if running as root
if [[ $EUID -ne 0 ]]; then
   echo -e "${RED}[-]${RESET} Error: $0 must be ${RED}run as root${RESET}" 1>&2
   exit 1
fi

echo -e "${GREEN}[>]${RESET} Updating OpenVAS feeds"

# we can't run greenbone-nvt-sync as root. Use _gvm user
echo -e "${GREEN}[*]${RESET} Updating: NVT"
runuser -u _gvm greenbone-nvt-sync

echo -e "${GREEN}[>]${RESET} Uploading plugins in Redis"
#upload plugins in redis with openvas
systemctl start redis-server@openvas.service
runuser -u _gvm -- openvas -u

echo -e "${GREEN}[*]${RESET} Updating: GVMD Data"
runuser -u _gvm -- greenbone-feed-sync --type GVMD_DATA

echo -e "${GREEN}[*]${RESET} Updating: Scap Data"
runuser -u _gvm -- greenbone-feed-sync --type SCAP

# CERT feed sync must be done after the SCAP feed
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=968500
echo -e "${GREEN}[*]${RESET} Updating: Cert Data"
runuser -u _gvm -- greenbone-feed-sync --type CERT
