-
Notifications
You must be signed in to change notification settings - Fork 0
/
obliterate_engines_no_warning.sh
executable file
·188 lines (155 loc) · 3.94 KB
/
obliterate_engines_no_warning.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
if test -f /opt/engines/etc/no_obliterate
then
echo "Installation Protected From Obliteration"
echo " You will need to remove the file /opt/engines/etc/no_obliterate to run $0"
exit
fi
if ! test `id |cut -f2 -d=|cut -f1 -d\(` -eq 0
then
echo "This script must be run as root or as sudo $0"
exit
fi
w |grep engines >/dev/null
if test $? -eq 0
then
echo cannot uninstalled while engines user is logged
exit
fi
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
echo "15 seconds until destruction with no visual countdown starting now"
echo "Docker and ALL docker Images will be Deleted -k to keep docker images"
echo "Ctl-C now if this is not want you want"
sleep 20
if test -f /tmp/first_start.log
then
rm /tmp/first_start.log
fi
echo Stopping Engines
service engines stop
rm /lib/systemd/system/engines.service
keep=0
keep_rbenv=0
if test $# -eq 1
then
if test $1 = "-k"
then
keep=1
elif test $1 = "-r"
then
keep_rbenv=1
echo "Keeping rbenv"
fi
fi
if test -d EnginesInstaller
then
# Update first
cd EnginesInstaller
git pull
cd ..
#then obliterate
crontab -u engines -r
rm -rf /var/spool/cron/crontabs/engines
service cron restart
if test -f /usr/bin/docker
then
service docker restart
sleep 5
containers=`docker ps -q | awk '{print $1}' `
if ! test -z "$containers"
then
docker stop $containers
fi
containers=`docker ps -aq | grep -i paused |awk '{print $1}' `
if ! test -z "$containers"
then
docker stop $containers
fi
containers=`docker ps -qa |awk '{print $1}'`
if ! test -z "$containers"
then
docker rm $containers
fi
if test $keep -eq 0
then
images=`docker images -q |awk '{print $1}'`
if ! test -z "$images"
then
docker rmi $images
fi
fi
service docker stop
rm -rf /var/lib/engines
rm -rf /var/log/engines
rm -rf /opt/engines
apt-get -y remove docker-engine
apt-get -y remove lxc-docker
apt-get -y remove docker.io
apt-get -y autoremove
rm /etc/default/docker
if test $keep -eq 0
then
rm -rf /var/lib/docker
fi
fi
engines_id=21000
pids=`ps -axl |grep -v grep | awk '{print "_" $2 "_ " $3}' |grep _21000_ | awk '{ print $2}'`
if ! test -z "$pids"
then
kill -TERM $pids
fi
pids=`ps -axl |grep -v grep | awk '{print "_" $2 "_ " $3}' |grep _21000_ | awk '{ print $2}'`
if ! test -z "$pids"
then
kill -KILL $pids
fi
sleep 6
pids=`ps -axl |grep -v grep | awk '{print "_" $2 "_ " $3}' |grep _21000_ | awk '{ print $2}'`
if ! test -z "$pids"
then
echo "engines user still has processes running pid(s) $pids"
exit
fi
gw_ifac=`netstat -nr |grep ^0.0.0.0 | awk '{print $8}' |head -1`
ip=`/sbin/ifconfig $gw_ifac |grep "inet addr" | cut -f 2 -d: |cut -f 1 -d" "`
userdel -r engines
service cron restart
#cat /etc/resolvconf/resolv.conf.d/head | grep -v "nameserver $ip" >/tmp/.local
#mv /tmp/.local /etc/resolvconf/resolv.conf.d/head
##cat /etc/resolv.conf | grep -v "$ip" >/tmp/.local
##mv /tmp/.local /etc/resolv.conf
if ! test -f /etc/network/if-up.d/engines_set_ip.sh
then
rm /etc/network/if-up.d/engines_set_ip.sh
fi
rm -r EnginesInstaller
groupdel containers
#usermod backup -r -G engines
usermod -G backup backup
rm /etc/sudoers.d/engines
groupdel engines
if test $keep_rbenv -eq 0
then
echo "Removing rbenv"
rm -rf /usr/local/rbenv
cat ~/.bashrc | grep -v rbenv >/tmp/.b
mv /tmp/.b ~/.bashrc
fi
rm /etc/network/if-up.d/set_ip.sh
if test -d /home/engines/.ssh
then
rm -r /home/engines/.ssh
fi
rm -fr /home/engines/.rbenv
groupdel docker
groupdel engines
cp -rp /opt/engines/system/uninstall/* /
update-grub
else
echo Script must be run as root from the dir that contains EnginesInstaller
fi