_pkgname='tomcat8'
_gid_tomcat_name='tomcat8'
_gid_tomcat=57
_uid_tomcat_name='tomcat8'
_uid_tomcat=57

post_install() {
  if ! getent group ${_gid_tomcat_name} >/dev/null 2>&1; then
    groupadd -g ${_gid_tomcat} ${_gid_tomcat_name}
  fi
  if ! getent passwd ${_uid_tomcat_name} >/dev/null 2>&1; then
    useradd  -u ${_uid_tomcat} -g ${_gid_tomcat_name} -d /usr/share/${_pkgname} -s /bin/false ${_uid_tomcat_name}
  fi

  if [ -f lib/modules/$(uname -r)/kernel/security/capability.ko ]; then
    echo 'It appears that your current kernel has linux security'
    echo 'capabilities built as a module. Tomcat requires this'
    echo ' functionality to operate.'
  fi
}

post_upgrade() {
  post_install $1
}

pre_remove() {
  if getent passwd ${_uid_tomcat_name} > /dev/null 2>&1; then
    userdel ${_uid_tomcat_name}
  fi
  if getent group ${_gid_tomcat_name} > /dev/null 2>&1; then
    groupdel ${_gid_tomcat_name}
  fi

  echo "To fully clean Tomcat's file, consider removing directories /var/{lib,tmp,log}/${_pkgname}"
}
