File: gvm-start

package info (click to toggle)
gvm 25.04.3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 108 kB
  • sloc: sh: 626; makefile: 2
file content (76 lines) | stat: -rwxr-xr-x 2,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash

## Quit on error
set -e

## Colour for bash prompt
RED="\033[01;31m"
GREEN="\033[01;32m"
YELLOW="\033[01;33m"
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

## Define PORT and URL
PORT="9392"
URL="https://127.0.0.1:${PORT}"

## Check if GVM is already running
if systemctl is-active --quiet gsad && systemctl is-active --quiet gvmd && systemctl is-active --quiet ospd-openvas && systemctl is-active --quiet notus-scanner; then
    echo -e "${YELLOW}[i]${RESET} GVM services are already running"
    exit 0
fi

## Check if something is already on the port
if lsof -Pi :${PORT} -sTCP:LISTEN -t >/dev/null ; then
  echo -e "${RED}[-]${RESET} Something is already using port: ${PORT}/tcp" 1>&2
  lsof -Pi :${PORT} -sTCP:LISTEN
  echo ""
  ps -f $(lsof -Pi :${PORT} -sTCP:LISTEN -t)
  echo ""
  exit 1
fi

## Display information to user
echo -e "${GREEN}[>]${RESET} Please wait for the GVM services to start."
echo -e "${GREEN}[>]${RESET}"
echo -e "${GREEN}[>]${RESET} You might need to refresh your browser once it opens."
echo -e "${GREEN}[>]${RESET}"
echo -e "${GREEN}[>]${RESET}  Web UI (Greenbone Security Assistant): ${URL}\n"

## Start services
systemctl start notus-scanner gvmd ospd-openvas
sleep 5s
# better start gsa after
systemctl start gsad

## Check services status
systemctl --no-pager -l status gsad gvmd ospd-openvas

## Add soft link to support new ospd socket name and avoid scanning errors failing with "Interrupted at 0%"
## More info: https://bugs.kali.org/view.php?id=8813
ln -sf /var/run/ospd/ospd-openvas.sock /var/run/ospd/ospd.sock

if dpkg-query -W -f'${db:Status-Status}' greenbone-security-assistant 2>/dev/null | grep -q ^installed; then
  ## Countdown
  echo -ne "\n${GREEN}[>]${RESET} Opening Web UI (${URL}) in: "
  for x in {5..1}; do
    echo -n "$x... "
    sleep 1s
  done
  echo ""

  ## Open browser, changed by grisutheguru to start the browser in the user's context and environment
  if [ -n "$SUDO_USER" ]; then
    # if startet with sudo, open browser in user's context
    runuser -u "$SUDO_USER" xdg-open "${URL}" 2>/dev/null >/dev/null &
  else
    # if started as root without sudo, print URL and let the user open the browser
    printf "Daemons started. To open GVM's webinterface call: %s\n" "${URL}"
  fi

fi