Skip to content

Instantly share code, notes, and snippets.

@sowderca
Created October 14, 2016 16:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sowderca/6b58b448ffedf38f12a3dbde5a2aa981 to your computer and use it in GitHub Desktop.
Save sowderca/6b58b448ffedf38f12a3dbde5a2aa981 to your computer and use it in GitHub Desktop.
Labtech Uninstall Scripts
#!/bin/sh
me=`basename $0`
if [ $EUID -ne 0 ]; then
echo "This script must be run as root." 1>&2
echo "Execute from a command prompt:" 1>&2
echo "sudo ./$me" 1>&2
if [ "./$me" != "$0" ]; then
echo " or " 1>&2
echo "sudo $0" 1>&2
fi
echo 1>&2
exit 1
fi
if launchctl list | grep com.labtechsoftware.LTSvc; then
launchctl stop com.labtechsoftware.LTSvc &>nul
launchctl remove com.labtechsoftware.LTSvc &>nul
launchctl stop com.labtechsoftware.ltechagent &>nul
launchctl remove com.labtechsoftware.ltechagent &>nul
launchctl unload /Library/LaunchDaemons/com.labtechsoftware.LTSvc.plist &>nul
fi
if launchctl list | grep com.labtechsoftware.LTTray; then
launchctl stop com.labtechsoftware.LTTray &>nul
launchctl remove com.labtechsoftware.LTTray &>nul
launchctl unload /Library/LaunchAgents/com.labtechsoftware.LTTray.plist &>nul
launchctl unload /Library/LaunchDaemons/com.labtechsoftware.LTTray.plist &>nul
fi
if launchctl list | grep com.labtechsoftware.LTUpdate; then
launchctl stop com.labtechsoftware.LTUpdate &>nul
launchctl remove com.labtechsoftware.LTUpdate &>nul
launchctl unload /Library/LaunchDaemons/com.labtechsoftware.LTUpdate.plist &>nul
fi
if launchctl list | grep com.labtechsoftware.LTSvc; then
launchctl stop com.labtechsoftware.LTSvc &>nul
launchctl remove com.labtechsoftware.LTSvc &>nul
launchctl unload /Library/LaunchDaemons/com.labtechsoftware.LTSvc.plist &>nul
fi
rm -rf /usr/LTSvc/ &>nul
rm -rf /usr/local/ltechagent/ &>nul
rm -rf /Library/LaunchDaemons/com.labtechsoftware.LTSvc.plist &>nul
rm -rf /Library/LaunchAgents/com.labtechsoftware.LTTray.plist &>nul
rm -rf /Library/LaunchDaemons/com.labtechsoftware.LTTray.plist &>nul
rm -rf /Library/LaunchDaemons/com.labtechsoftware.LTUpdate.plist &>nul
#!/bin/sh
echo
echo "Uninstalling LabTech."
# If the agent is up, kill it
ps -ef | grep LTAgentMonitor | grep -v grep | awk '{print $2}' | xargs kill 2>/dev/null
ps -ef | grep LTLinuxAgent | grep -v grep | awk '{print $2}' | xargs kill 2>/dev/null
ps -ef | grep LTSystray | grep -v grep | awk '{print $2}' | xargs kill 2>/dev/null
# Determine the flavor of Linux being run
cd /etc
redhat_count=`grep -i redhat * 2>/dev/null | wc -l`
debian_count=`grep -i debian * 2>/dev/null | wc -l`
fedora_count=`grep -i fedora * 2>/dev/null | wc -l`
ubuntu_count=`grep -i ubuntu * 2>/dev/null | wc -l`
centos_count=`grep -i centos * 2>/dev/null | wc -l`
suse_count=`grep -i suse * 2>/dev/null | wc -l`
cd -
count=0
type="FEDORA"
if test $redhat_count -gt $count
then type="REDHAT"
count=$redhat_count
fi
if test $debian_count -gt $count
then type="DEBIAN"
count=$debian_count
fi
if test $fedora_count -gt $count
then type="FEDORA"
count=$fedora_count
fi
if test $ubuntu_count -gt $count
then type="UBUNTU"
count=$ubuntu_count
fi
if test $centos_count -gt $count
then type="CENTOS"
count=$centos_count
fi
if test $suse_count -gt $count
then type="SUSE"
count=$suse_count
fi
# Is the LabTech directory there?
if test -d /usr/lib/labtech
then
# Delete the entire LabTech installation
rm -rf /usr/lib/labtech
fi
# Remove the scripts which attempt to start/stop the agent when the box is re-booted
case $type in
"REDHAT"|"FEDORA"|"CENTOS"|"SUSE")
if test -f /etc/init.d/linux_agent
then
success="F"
chkconfig --del linux_agent 2>/dev/null
# Check exit code
if [ "$?" -eq "0" ]
then
success="T"
else
/sbin/chkconfig --del linux_agent 2>/dev/null
# Check exit code
if [ "$?" -eq "0" ]
then
success="T"
fi
fi
if [ "$success" != "T" ]
then
# Can't find chkconfig. Remove links manually.
RCPATH="NONE"
if test -d /etc/rc.d/rc0.d
then
RCPATH="/etc/rc.d"
elif test -d "/etc/rc0.d"
then
RCPATH="/etc"
fi
if [ "$RCPATH" != "NONE" ]
then
rm -f $RCPATH/rc0.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc1.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc2.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc3.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc4.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc5.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc6.d/K20linux_agent 2>/dev/null
fi
fi
cd /etc/init.d
rm linux_agent
fi
;;
"DEBIAN"|"UBUNTU")
if test -f /etc/init.d/linux_agent
then
cd /etc/init.d
rm linux_agent
success="F"
update-rc.d linux_agent remove 2>/dev/null
# Check exit code
if [ "$?" -eq "0" ]
then
success="T"
else
/usr/sbin/update-rc.d linux_agent remove 2>/dev/null
# Check exit code
if [ "$?" -eq "0" ]
then
success="T"
fi
fi
if [ "$success" != "T" ]
then
# Can't find update-rc.d. Remove links manually.
RCPATH="NONE"
if test -d /etc/rc.d/rc0.d
then
RCPATH="/etc/rc.d"
elif test -d "/etc/rc0.d"
then
RCPATH="/etc"
fi
if [ "$RCPATH" != "NONE" ]
then
rm -f $RCPATH/rc0.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc1.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc2.d/K20linux_agent 2>/dev/null
rm -f $RCPATH/rc3.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc4.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc5.d/S20linux_agent 2>/dev/null
rm -f $RCPATH/rc6.d/K20linux_agent 2>/dev/null
fi
fi
fi
;;
esac
rm -f linux_agent_*
if test -f /lib/systemd/system/linux_agent.service
then
systemctl disable linux_agent.service 1>/dev/null 2>/dev/null
rm -f /lib/systemd/system/linux_agent.service 1>/dev/null 2>/dev/null
fi
echo "Agent has been uninstalled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment