summaryrefslogtreecommitdiff
path: root/net-mgmt/nagios2/files/pkg-install.in
blob: 2575727530e05cdbab46853eac98fe630d9c801e (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD$
#

NAGIOSDIR=%%NAGIOSDIR%%
NAGIOSUSER=%%NAGIOSUSER%%
NAGIOSGROUP=%%NAGIOSGROUP%%

ask() {
  local question default answer

  question=$1
  default=$2
  if [ -z "${PACKAGE_BUILDING}" ]; then
    read -p "${question} [${default}]? " answer
  fi
  if [ "x${answer}" = "x" ]; then
    answer=${default}
  fi
  echo ${answer}
}

yesno() {
  local default question answer

  question=$1
  default=$2
  while :; do
    answer=$(ask "${question}" "${default}")
    case "${answer}" in
      [Yy][Ee][Ss]|[Yy])
        return 0
        ;;
      [Nn][Oo]|[Nn])
        return 1
        ;;
    esac
    echo "Please answer yes or no."
   done
}

if [ "$2" = "PRE-INSTALL" ]; then
  if /usr/sbin/pw group show "${NAGIOSGROUP}" 2>&1 >/dev/null; then
    echo "You already have a \"${NAGIOSGROUP}\" group, so I will use it."
  else
    echo "You need a \"${NAGIOSGROUP}\" group."
    if yesno "Would you like me to create it" "YES"; then
      /usr/sbin/pw groupadd "${NAGIOSGROUP}" -h - || exit
      echo "Done."
    else
      echo "Please create the \"${NAGIOSGROUP}\" group manually and try again."
      exit 1
    fi
  fi

  if /usr/sbin/pw user show "${NAGIOSUSER}" 2>&1 >/dev/null; then
    echo "You already have a \"${NAGIOSUSER}\" user, so I will use it."
  else
    echo "You need a \"${NAGIOSUSER}\" user."
    if yesno "Would you like me to create it" "YES"; then
      /usr/sbin/pw useradd "${NAGIOSUSER}" -g "${NAGIOSGROUP}" -h - -d "${NAGIOSDIR}" \
        -s /sbin/nologin -c "Nagios pseudo-user" || exit
    else
      echo "Please create the \"${NAGIOSUSER}\" user manually and try again."
      exit 1
    fi
  fi
fi