summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 06dcecafccccab18a69c7242971a5f6c58fdbb10 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Maintainer:  Paul Severance <paulseverance+aur@gmail.com>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Preston <pentie [at] gmail.com>

# Install: https://docs.newrelic.com/docs/servers/new-relic-servers-linux/installation-configuration/servers-installation-other-linux
# source PKGBUILD
# Edit PKGBUILD.local and set your RUNAS user
# makepkg -scCfi
# Watch screen for Install instructions.

# UnInstall cleanup: (as root)
#    systemctl status newrelic-sysmond.service
#    systemctl stop newrelic-sysmond.service
#    systemctl disable newrelic-sysmond.service
#    pacman -R newrelic-sysmond
# Sub in the username you picked into the following
#    rm -rf '/var/log/newrelic' '/etc/newrelic' '/.newrelic'

set -u
pkgname='newrelic-sysmond'
pkgver='2.3.0.132'
pkgrel='1'
pkgdesc='collect, monitor, and analyze critical server load metrics including CPU, memory, network, process, disk utilization and capacity'
arch=('i686' 'x86_64')
url='http://newrelic.com/'
license=('custom')
depends=('glibc' 'bash' 'grep' 'sed' 'awk' 'systemd')
makedepends=('binutils')
backup=('etc/newrelic/nrsysmond.cfg')
install="${pkgname}.install"
_verwatch=('http://download.newrelic.com/server_monitor/archive/' '\([0-9][^/]\+\)/' 'l')
source=("${_verwatch[0]}${pkgver}/${pkgname}-${pkgver}-linux.tar.gz"
        "${pkgname}.logrotate"
        "${pkgname}.inst.sh"
        "${pkgname}.service")

sha256sums=('8e40894c096ae93d08afe98da5b83a879acf95933f9d13ac83ca35a59b73bb31'
            '02d70a783e30a7b6f8c438b1bae5a57d37d2204d112ccca38eada2b9044a5ebe'
            'bcce083629dcd0827f86247872ee4b42dec2c51349b4cc10c0ce7619f94faf9f'
            '58fade9de4793e22cda75816a74c52d5d9b831ab68bc7b8225aa1bb294b3b31b')

package() {
  set -u
  cd "${srcdir}/${pkgname}-${pkgver}-linux"

  install -dm770 "${pkgdir}/var/log/newrelic" # For some reason the daemon writes files with umask 000

  case "${CARCH}" in
  'i686') install -Dpm755 'daemon/nrsysmond.x86' "${pkgdir}/usr/bin/nrsysmond";;
  'x86_64') install -Dpm755 'daemon/nrsysmond.x64' "${pkgdir}/usr/bin/nrsysmond";;
  *)echo "${}";;
  esac

  install -Dpm755 "${srcdir}/newrelic-sysmond.inst.sh" "${pkgdir}/usr/bin/newrelic-sysmond-inst"

  # The installer makes this file chmod 640. Anything in this file can be found
  # with ps -ef, ls -l /etc/default, or cat newrelic-sysmond.service by any
  # user so there's no reason to go through all the chmod hassle for a file
  # that has nothing to hide.
  install -dm750 "${pkgdir}/etc/newrelic" # The New Relic instructions say 600 but this is clearly wrong.
  install -Dpm640 'nrsysmond.cfg' -t "${pkgdir}/etc/newrelic/"
  sed -i -e '# Forward location of this setting' \
         -e 's:^#pidfile=.*$'":&\n# In Arch Linux this setting is found in /usr/lib/systemd/system/${pkgname}.service:g" \
    "${pkgdir}/etc/newrelic/nrsysmond.cfg"
  install -Dpm755 'scripts/nrsysmond-config' -t "${pkgdir}/usr/bin/"
  sed -i -e '# Our sed recognizes tab escape sequences' \
         -e 's:\t\]:\\t]:g' \
    "${pkgdir}/usr/bin/nrsysmond-config"
  install -Dpm644 "scripts/${pkgname}.default.debian" "${pkgdir}/etc/default/${pkgname}"
  sed -i -e "# Disable a setting we don't use" \
         -e 's;^nrdaemon=.*$'";# The nrdaemon is set by the Arch Linux package installer and cannot be changed here.\n#&;g" \
         -e '# Provide change requirements for RUNAS' \
         -e 's;^RUNAS=.*$'";#&\n# In Arch Linux the RUNAS setting is found in /usr/lib/systemd/system/${pkgname}.service as User=;g" \
     "${pkgdir}/etc/default/${pkgname}"
  install -Dpm644 'INSTALL.txt' 'LICENSE.txt' -t "${pkgdir}/usr/share/doc/newrelic/"
  install -Dpm644 "${srcdir}/${pkgname}.service" -t "${pkgdir}/usr/lib/systemd/system/"
  sed -i -e "# Apply user group info" \
         -e "s;NEWRELIC_USER;${_opt_ASUSER};g" \
     "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"
  install -Dpm644 "${srcdir}/${pkgname}.logrotate" "${pkgdir}/etc/logrotate.d/${pkgname}"

  # Ensure there are no forbidden paths. Place at the end of package() and comment out as you find or need exceptions. (git-aurcheck)
  ! test -d "${pkgdir}/bin" || { echo "Line ${LINENO} Forbidden: /bin"; false; }
  ! test -d "${pkgdir}/sbin" || { echo "Line ${LINENO} Forbidden: /sbin"; false; }
  ! test -d "${pkgdir}/lib" || { echo "Line ${LINENO} Forbidden: /lib"; false; }
  ! test -d "${pkgdir}/share" || { echo "Line ${LINENO} Forbidden: /share"; false; }
  ! test -d "${pkgdir}/usr/sbin" || { echo "Line ${LINENO} Forbidden: /usr/sbin"; false; }
  ! test -d "${pkgdir}/usr/local" || { echo "Line ${LINENO} Forbidden: /usr/local"; false; }
  #! grep -lr "/sbin" "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /sbin"; false; }
  ! grep -lr "/usr/tmp" "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /usr/tmp"; false; }
  #! grep -lr "/usr/local" "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /usr/local"; false; }
  #! pcre2grep -Ilr "(?<!/usr)/bin" "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /bin"; false; }
  set +u
}

[ ! -s 'PKGBUILD.local' ] && cat > 'PKGBUILD.local' << EOF
# Set your RUNAS user here
# root is insecure and unnecesary
# Default: newrelic
_opt_ASUSER='newrelic'
EOF
source 'PKGBUILD.local'

set +u