-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.py
executable file
·146 lines (123 loc) · 4.51 KB
/
uninstall.py
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
#!/usr/bin/env python
# Copyright 2008 David Selby dave6502@googlemail.com
# GNU General Public Licence (GPL)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
import os, sys, pwd, ConfigParser
def uninstall():
"""
A very simple automated uninstall script ... this code is not bombproof !
"""
print """\033[1;31m
Welcome to the kmotion v1.1xb uninstaller. Apart from the kmotion directory
all traces of kmotion will be uninstalled. This includes
(1) A link from /etc/apache2/sites-enabled/ to this directory
(2) The addition of 'kmotion' and 'kmotion_reload' in /usr/bin/
(3) The addition of 'sudo -u <name> motion &' in /etc/rc.local\033[1;32m
Type \'uninstall\' ENTER to start uninstall :\033[1;37m""",
if raw_input() != 'uninstall':
print
sys.exit()
print
# check we are running as root
print_checking('Checking install is running as root')
uid = os.getuid()
if uid != 0:
print_fail( 'Install needs to be runs as root, try \'sudo install\'')
return
print_ok()
login = os.environ['SUDO_USER']
# check we can read ./daemons/daemon.rc - if we can't assume we are not in the root directory
print_checking('Checking install is running in correct directory')
parser = ConfigParser.SafeConfigParser()
parsed = parser.read('./daemons/daemon.rc')
if parsed != ['./daemons/daemon.rc']:
print_fail( 'Please \'cd\' to the kmotion root directory')
return
print_ok()
# delete link from /etc/apache2/sites-enabled/
print_checking('Deleteing apache2 \'sites-enabled\' link')
if os.path.islink('/etc/apache2/sites-enabled/kmotion_vhost'):
os.remove('/etc/apache2/sites-enabled/kmotion_vhost')
print_ok()
else:
print_fail('apache2 \'sites-enabled\' link already deleted')
# restart apache2
print_checking('Restarting apache2')
print_ok()
print
os.system('/etc/init.d/apache2 restart')
print
# delete /usr/bin/kmotion
print_checking('Deleteing /usr/bin/kmotion')
if os.path.isfile('/usr/bin/kmotion'):
os.remove('/usr/bin/kmotion')
print_ok()
else:
print_fail('/usr/bin/kmotion already deleted')
# delete /usr/bin/kmotion_reload
print_checking('Deleteing /usr/bin/kmotion_reload')
if os.path.isfile('/usr/bin/kmotion_reload'):
os.remove('/usr/bin/kmotion_reload')
print_ok()
else:
print_fail('/usr/bin/kmotion_reload already deleted')
# remove kmotion from /etc/rc.local
print_checking('Removing \'kmotion\' from \'/etc/rc.local\' for auto startup')
f = open('/etc/rc.local', 'r')
lines = f.readlines()
f.close
f = open('/etc/rc.local', 'w')
detected = False
for line in lines:
if line == 'sudo -u %s kmotion &\n' % login:
detected = True
continue
f.write(line)
f.close
if detected:
print_ok()
else:
print_fail('\'kmotion\' already removed from \'/etc/rc.local\'')
## # remove 127.0.0.1 kmotion from /etc/hosts
## print_checking('Removeing \'127.0.0.1 kmotion\' from \'/etc/hosts\'')
## f = open('/etc/hosts', 'r')
## lines = f.readlines()
## f.close
##
## f = open('/etc/hosts', 'w')
## for line in lines:
## if line == '127.0.0.1\tkmotion\n': continue
## f.write(line)
## f.close
## print_ok()
## print
def print_checking(text):
"""
Given a text string colorise to green and calculate the number of '.'s
"""
length = len(text)
print '\033[1;32m%s' % text,
print '.' * (65 - length) ,
print '\033[1;37m',
def print_ok():
"""
Colorise a green [ok]
"""
print '\033[1;32m[OK]\033[1;37m'
def print_fail(text):
"""
Given a text string colorise to red and prepend a [fail]
"""
print '\033[1;31m[FAIL] : %s\033[1;37m' % text
uninstall()