Sindbad~EG File Manager
Current Path : /var/lib/dpkg/info/ |
|
Current File : //var/lib/dpkg/info/omsagent.postrm |
#!/bin/sh
# Calling sequence for RPM pre/post scripts, during upgrade, is as follows:
# 1. Run the %pre section of the RPM being installed.
# 2. Install the files that the RPM provides.
# 3. Run the %post section of the RPM.
# 4. Run the %preun of the old package.
# 5. Delete any old files not overwritten by the newer version.
# (This step deletes files that the new package does not require.)
# 6. Run the %postun hook of the old package.
#
# Thus, if we're an upgrade, skip all of this cleanup
ETC_DIR=/etc/opt/microsoft/omsagent
VAR_DIR=/var/opt/microsoft/omsagent
WORKSPACE_REGEX='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
if [ "$1" != "upgrade" -a "$1" != "purge" ]; then
# Clean up directory trees: /etc/opt, /var/opt, /opt
# If multi-workspace scenario
for ws_id in `ls -1 $ETC_DIR | grep -E $WORKSPACE_REGEX`
do
echo "Deleting certs and conf directories for workspace $ws_id if empty..."
rmdir $ETC_DIR/$ws_id/certs/ 2> /dev/null
rmdir $ETC_DIR/$ws_id/conf/ 2> /dev/null
rm /opt/microsoft/omsagent/bin/omsagent-$ws_id 2> /dev/null
rm -rf $VAR_DIR/$ws_id/tmp/ 2> /dev/null
rmdir $VAR_DIR/$ws_id/state/ 2> /dev/null
# /var/opt/microsoft/omsagent/<wkspc>/run/ and log/ should be left for later service start
done
# Clean up installinfo.txt file (registered as "conf" file to pass rpmcheck)
rm -f $ETC_DIR/sysconf/installinfo.txt*
rmdir $ETC_DIR/sysconf 2> /dev/null
# Clean up symbolic links if multi-workspace scenario
rm $ETC_DIR/certs 2> /dev/null
rm $ETC_DIR/conf 2> /dev/null
rm $VAR_DIR/tmp 2> /dev/null
rm $VAR_DIR/state 2> /dev/null
rm $VAR_DIR/run 2> /dev/null
rm $VAR_DIR/log 2> /dev/null
# Clean up directory tree if agent installed or upgraded without onboarding. No symbolic links.
rmdir $ETC_DIR/certs/ 2> /dev/null
rmdir $ETC_DIR/conf/ 2> /dev/null
rmdir $VAR_DIR/tmp/ 2> /dev/null
rmdir $VAR_DIR/state/ 2> /dev/null
rmdir $VAR_DIR/run/ 2> /dev/null
rmdir $VAR_DIR/log/ 2> /dev/null
# Remove parent folders if they are empty
rmdir $ETC_DIR 2> /dev/null
rmdir /etc/opt/microsoft 2> /dev/null
rmdir /etc/opt 2> /dev/null
rmdir $VAR_DIR 2> /dev/null
rmdir /opt/microsoft/omsagent/bin/ 2> /dev/null
rmdir /opt/microsoft/omsagent/ 2> /dev/null
# Clean up logrotate
rm -f /etc/logrotate.d/omsagent*
rm -f /etc/cron.d/omsagent
fi
RemoveSudoersSupport() {
# Unconfigure sudo configuration
#
# Just unconfigure everything we could have done so things are left in clean state
if [ -f /etc/sudoers.d/omsagent ]; then
rm -f /etc/sudoers.d/omsagent
fi
grep -q '# Begin sudo configuration for omsagent' /etc/sudoers
if [ $? -eq 0 ]; then
cp /etc/sudoers /etc/sudoers.bak
sed '/^# Begin sudo configuration for omsagent/,/# End sudo configuration for omsagent$/ d' /etc/sudoers.bak > /etc/sudoers
fi
}
SudoSupportsIncludeDirective() {
# Algorithm:
# If #includedir exists in /etc/sudoers AND /etc/sudoers.d exists,
# Then Use /etc/sudoers.d
# Else Append to /etc/sudoers
INCLUDEDIR=0
egrep -q "^#includedir" /etc/sudoers && INCLUDEDIR=1
if [ $INCLUDEDIR -eq 1 -a -d /etc/sudoers.d ]; then
return 0
else
return 1
fi
}
# If we're called for upgrade, don't do anything
if [ "$1" != "upgrade" -a "$1" != "purge" ]; then
# Restart the OMI server in case an agent is running under service account
/opt/omi/bin/service_control restart
# Unconfigure sudo if it's already configured
RemoveSudoersSupport
# Remove the service accounts
echo "Deleting nxautomation service account ..."
userdel nxautomation 2> /dev/null
echo "Deleting omsagent service account ..."
userdel omsagent 2> /dev/null
if [ $? -eq 0 ]; then
# Depending on system settings, the groups may not have been deleted
egrep -q "^nxautomation:" /etc/group
if [ $? -eq 0 ]; then
echo "Deleting nxautomation group ..."
groupdel nxautomation
fi
egrep -q "^omsagent:" /etc/group
if [ $? -eq 0 ]; then
echo "Deleting omsagent group ..."
groupdel omsagent
fi
fi
fi
exit 0
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists