File: /var/lib/dpkg/info/nutanix-guest-agent.prerm
#!/bin/sh
# This `DEBIAN/prerm` script is run pre-uninstallation
set -e
NGT_ROOT=/usr/local/nutanix/ngt/
SERVICE_CONFIG_DIR=/etc/systemd/system/
DAEMON_CONFIG_DIR=/etc/init.d/
PRESET_DIR=/etc/systemd/system-preset
NGT_DAEMON_NAME=ngt_guest_agent
SSR_DAEMON_NAME=ngt_self_service_restore
NGT_SERVICE_NAME=$NGT_DAEMON_NAME.service
SSR_SERVICE_NAME=$SSR_DAEMON_NAME.service
NGT_PRESET_NAME=50-$NGT_DAEMON_NAME.preset
SSR_PRESET_NAME=50-$SSR_DAEMON_NAME.preset
NGT_DAEMON_PATH=$DAEMON_CONFIG_DIR/$NGT_DAEMON_NAME
SSR_DAEMON_PATH=$DAEMON_CONFIG_DIR/$SSR_DAEMON_NAME
NGT_SERVICE_PATH=$SERVICE_CONFIG_DIR/$NGT_SERVICE_NAME
SSR_SERVICE_PATH=$SERVICE_CONFIG_DIR/$SSR_SERVICE_NAME
stop_sysvinit_services() {
if [ -f $NGT_DAEMON_PATH ]; then
echo "Stopping $NGT_DAEMON_NAME daemon..."
$NGT_DAEMON_PATH stop >/dev/null 2>&1 || :
update-rc.d -f $NGT_DAEMON_NAME remove >/dev/null 2>&1 || :
echo "$NGT_DAEMON_NAME daemon stopped."
fi;
if [ -f $SSR_DAEMON_PATH ]; then
echo "Stopping $SSR_DAEMON_NAME daemon..."
$SSR_DAEMON_PATH stop >/dev/null 2>&1 || :
update-rc.d -f $SSR_DAEMON_NAME remove >/dev/null 2>&1 || :
echo "$SSR_DAEMON_NAME daemon stopped."
fi;
}
stop_services() {
if ( ps --no-headers -o comm 1 | grep "systemd" ); then
if [ -f $NGT_SERVICE_PATH ]; then
echo "Stopping $NGT_SERVICE_NAME systemctl service..."
systemctl --no-reload disable $NGT_SERVICE_NAME > /dev/null 2>&1 || :
systemctl stop $NGT_SERVICE_NAME > /dev/null 2>&1 || :
echo "$NGT_SERVICE_NAME service stopped."
fi;
if [ -f $SSR_SERVICE_PATH ]; then
echo "Stopping $SSR_SERVICE_NAME systemctl service..."
systemctl --no-reload disable $SSR_SERVICE_NAME > /dev/null 2>&1 || :
systemctl stop $SSR_SERVICE_NAME > /dev/null 2>&1 || :
echo "$SSR_SERVICE_NAME service stopped."
fi;
else
echo "systemctl not supported by OS. Using sysvinit."
stop_sysvinit_services
fi
}
case "$1" in
upgrade|abort-upgrade)
echo "Prerm: Nutanix guest agent debian package getting upgraded."
;;
*)
echo "Nutanix Guest Agent is getting uninstalled, stopping running services"
stop_services
echo "Removing Desktop icon and shortcuts."
$NGT_ROOT/python36/python3 $NGT_ROOT/src/deb_installer_utils.py uninstall
echo "Notify CVM of agent uninstallation."
$NGT_ROOT/python36/python3 -E $NGT_ROOT/python/bin/guest_cli.py notify_cvm_of_uninstallation
echo "Successfully notified CVM of agent uninstallation."
;;
esac