pre-uninstall.sh 2.91 KB
Newer Older
1 2
#! /bin/bash
#
3 4
# When uninstall slapos, it will be called by uninstaller. Root right
# required to run this script.
5 6
#
#    /bin/bash/ --login -i pre-uninstall.sh
7
#
8 9
# It will do:
#
10
#    * Remove virtual netcards installed by re6stnet
11
#
Jondy Zhao's avatar
Jondy Zhao committed
12
#    * Remove service cron, cygserver syslog-ng re6stnet
13
#
Jondy Zhao's avatar
Jondy Zhao committed
14
#    * Remove account/group added by slapos configure script
15
#
Jondy Zhao's avatar
Jondy Zhao committed
16
#    * Remove instance and software root /srv/slapgrid /opt/slapgrid
17
#
18 19 20
# Required:
#   grep gawk TASKKILL
#
Jondy Zhao's avatar
Jondy Zhao committed
21
source $(/usr/bin/dirname $0)/slapos-include.sh
22

23 24 25 26 27 28 29 30 31
function slapos_kill_process()
{
    name=$1
    echo "Try to kill all $name ..."
    for pid in $(ps | grep "$name" | gawk '{print $4}') ; do
        echo "Kill pid $pid"
        TASKKILL /F /T /PID $pid
    done
}
Jondy Zhao's avatar
Jondy Zhao committed
32
readonly -f slapos_kill_process
33

34 35 36
#
# Remove services installed by cygwin,
#
37
for name in ${re6stnet_service_name} ${cron_service_name} \
Jondy Zhao's avatar
Jondy Zhao committed
38
    ${syslog_service_name} ${cygserver_service_name} ; do
39
    echo "Removing ervice $name"
40 41 42 43 44 45 46
    cygrunsrv -R $name && echo OK.
done

#
# Stop slapos
#
if [[ -x /opt/slapos/bin/slapos ]] ; then
47
    echo "Stoping slapos node ..."
48 49
    /opt/slapos/bin/slapos node stop all && echo OK.
fi
50
slapos_kill_process /usr/bin/python2.7
51

52
#
53
# Remove virtual netcard installed by slapos
54
#
55 56
echo "Removing network connection ${slapos_ifname}"
ipwin remove *msloop ${slapos_ifname} && echo OK.
57

Jondy Zhao's avatar
Jondy Zhao committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#
# Remove configure files
#
echo Removing /etc/opt/slapos
rm -rf /etc/opt/slapos/ && echo OK.
echo Removing ~/.slapos
rm -rf ~/.slapos && echo OK.

#
# Remove crontab
#
_filename=/var/cron/tabs/${slapos_administrator}
echo "Removing ${_filename}"
rm -rf ${_filename} && echo OK.

#
# Remove default instance root and software root, because it belong to
# slapuser, and would not be removed by the windows uninstaller.
#
[[ -f /srv/slapgrid ]] && echo "Removing /srv/slapgrid" && rm -rf /srv/slapgrid && echo OK.
[[ -f /opt/slapgrid ]] && echo "Removing /opt/slapgrid" && rm -rf /opt/slapgrid && echo OK.

80
#
81
# Remove users installed by slapos
82
#
Jondy Zhao's avatar
Jondy Zhao committed
83
[[ -f /var/empty ]] && echo "Removing /var/empty" && rm -rf /var/empty && echo OK.
84 85 86 87 88 89 90
for _name in $(NET USER) ; do
    if [[ "${_name}" == ${slapos_user_basename}* ]] ; then
        echo "Removing user: ${_name}"
        NET USER ${_name} /DELETE && echo OK.
    elif echo "${_name}" | grep -q -E "(sshd)|(cyg_server)|(${slapos_administrator})" ; then
        echo "Removing user: ${_name}"
        NET USER ${_name} /DELETE && echo OK.
91 92
    fi
done
93 94
echo "Creating /etc/passwd ..."
mkpasswd -l > /etc/passwd && echo OK.
95 96 97

#
# Remove local group installed by slapos node
98
#
99 100 101 102
for _name in $(NET LOCALGROUP | sed -n -e "s/^*//p" | sed -e "s/\\s//g") ; do
    if [[ "${_name}" == grp_${slapos_user_basename}* ]] ; then
        echo "Removing localgroup: ${_name}"
        NET LOCALGROUP ${_name} /DELETE && echo OK.
103 104
    fi
done
105 106
echo "Creating /etc/group ..."
mkgroup -l > /etc/group && echo OK.
Jondy Zhao's avatar
Jondy Zhao committed
107

108 109 110
echo
echo Run pre-uninstall script complete.
echo
111
read -n 1 -t 60 -p "Press any key to exit..."
112
exit 0