#!/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 run as root" 1>&2
   exit 1
fi

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

# we can't run greenbone-nvt-sync as root. Use _gvm user
echo -e "${GREEN}[*]${RESET} Updating NVT (Network Vulnerability Tests feed from Greenbone Security Feed/Community Feed)"
runuser -u _gvm greenbone-nvt-sync

echo -e "${GREEN}[>]${RESET} Updating Vulnerability Tests info into Redis store from VT files"
#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

echo -e "\n${GREEN}[+]${RESET} GVM feeds updated"
