| Current Path : /var/lib/dpkg/info/ |
| Current File : //var/lib/dpkg/info/rmmagent.preinst |
#!/bin/sh
# Reference: https://wiki.debian.org/MaintainerScripts
set -e
if [ -n "${RMM_DEBUG}" ]; then
echo "Running: $0 $@"
set -x
fi
RMM_BASE="/usr/local/rmmagent"
SVC_NAME="rmmagent"
LOG_DIR="/var/log/rmmagent"
SYSTEM_CTL="$(command -v systemctl 2>/dev/null || true)"
INVOKE_RC="$(command -v invoke-rc.d 2>/dev/null || true)"
# Init logs, if not available
mkdir -p "${LOG_DIR}"
logInfo() # message
{
logMessage "$1" false
if [ -n "${RMM_DEBUG}" ]; then
echo "$1"
fi
}
logWarning() # message
{
logMessage "$1" true
echo "$1"
}
logMessage() # message, isWarning
{
if [ -d "${LOG_DIR}" ]; then
Prefix="I"
if ${2}; then
Prefix="W"
fi
echo "[`date '+%Y-%m-%d %H:%M:%S'`] [${Prefix}] $1" >> "${LOG_DIR}/package_script.log"
fi
}
stopService()
{
logInfo "Stop service"
if [ -x "${SYSTEM_CTL}" ]; then
logInfo "Stopping with systemd"
"${SYSTEM_CTL}" stop "${SVC_NAME}.service"
elif [ -x "/etc/init.d/${SVC_NAME}" ]; then
logInfo "Stopping with init.d"
if [ -x "${INVOKE_RC}" ]; then
"${INVOKE_RC}" "${SVC_NAME}" stop
else
"/etc/init.d/${SVC_NAME}" stop
fi
fi
}
migrateFromLegacyAgent()
{
if "${RMM_BASE}/rmmagentd" --version 2>&1 >/dev/null | grep -q "Undefined argument '--version'"; then
logInfo "Legacy Agent detected. Terminating."
"${RMM_BASE}/rmmagentd" --terminate >/dev/null 2>&1 || logInfo "Legacy Agent was not installed"
fi
}
logInfo "preinst script is executing: $1 command"
case "$1" in
upgrade)
stopService
migrateFromLegacyAgent
;;
install|abort-upgrade)
;;
*)
logWarning "preinst called with unknown argument '$1'" >&2
exit 1
;;
esac
exit 0