forked from trackmastersteve/alienfx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.py
More file actions
311 lines (265 loc) · 9.32 KB
/
Copy pathremove.py
File metadata and controls
311 lines (265 loc) · 9.32 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/usr/bin/env python3
#
# remove.py
#
# Copyright (C) 2013-2014 Ashwin Menon <ashwin.menon@gmail.com>
# Copyright (C) 2015-2026 Track Master Steve <trackmastersteve@gmail.com>
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# Alienfx 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 alienfx. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
"""
AlienFX Uninstaller
This script removes the AlienFX application and all its files from a Linux system.
"""
import os
import sys
import shutil
import subprocess
from pathlib import Path
# Color codes for terminal output
class Colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
def print_header(message):
print(f"\n{Colors.HEADER}{Colors.BOLD}{message}{Colors.ENDC}")
def print_success(message):
print(f"{Colors.OKGREEN}✓ {message}{Colors.ENDC}")
def print_warning(message):
print(f"{Colors.WARNING}⚠ {message}{Colors.ENDC}")
def print_error(message):
print(f"{Colors.FAIL}✗ {message}{Colors.ENDC}")
def print_info(message):
print(f"{Colors.OKCYAN}ℹ {message}{Colors.ENDC}")
def remove_file(filepath):
"""Remove a single file."""
try:
if os.path.exists(filepath):
os.remove(filepath)
print_success(f"Removed: {filepath}")
return True
else:
print_warning(f"Not found: {filepath}")
return False
except Exception as e:
print_error(f"Failed to remove {filepath}: {e}")
return False
def remove_directory(dirpath):
"""Remove a directory and all its contents."""
try:
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
print_success(f"Removed directory: {dirpath}")
return True
else:
print_warning(f"Directory not found: {dirpath}")
return False
except Exception as e:
print_error(f"Failed to remove directory {dirpath}: {e}")
return False
def get_python_site_packages():
"""Get the site-packages directory path."""
try:
import site
site_packages = site.getsitepackages()
return site_packages
except Exception as e:
print_warning(f"Could not determine site-packages location: {e}")
return []
def uninstall_pip_package():
"""Attempt to uninstall via pip."""
print_header("Attempting to uninstall via pip...")
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "uninstall", "-y", "alienfx"],
capture_output=True,
text=True
)
if result.returncode == 0:
print_success("Successfully uninstalled via pip")
return True
else:
print_warning("Package not found in pip or pip uninstall failed")
return False
except Exception as e:
print_warning(f"Could not uninstall via pip: {e}")
return False
def remove_data_files():
"""Remove data files installed by the application."""
print_header("Removing data files...")
# Define all data files and directories to remove
data_files = [
"/usr/share/applications/alienfx.desktop",
"/usr/local/share/applications/alienfx.desktop",
"/usr/share/icons/hicolor/scalable/apps/alienfx.svg",
"/usr/local/share/icons/hicolor/scalable/apps/alienfx.svg",
"/usr/share/icons/hicolor/48x48/apps/alienfx.png",
"/usr/local/share/icons/hicolor/48x48/apps/alienfx.png",
"/usr/share/pixmaps/alienfx.png",
"/usr/local/share/pixmaps/alienfx.png",
"/usr/share/man/man1/alienfx.1",
"/usr/local/share/man/man1/alienfx.1",
"/usr/share/man/man1/alienfx.1.gz",
"/usr/local/share/man/man1/alienfx.1.gz",
"~/.config/alienfx",
]
removed_count = 0
for filepath in data_files:
if remove_file(filepath):
removed_count += 1
return removed_count
def remove_udev_rules():
"""Remove udev rules file."""
print_header("Removing udev rules...")
udev_file = "/etc/udev/rules.d/10-alienfx.rules"
if remove_file(udev_file):
# Reload udev rules
try:
subprocess.run(["udevadm", "control", "--reload-rules"], check=False)
subprocess.run(["udevadm", "trigger"], check=False)
print_success("Reloaded udev rules")
except Exception as e:
print_warning(f"Could not reload udev rules: {e}")
return True
return False
def remove_executables():
"""Remove executable scripts."""
print_header("Removing executable scripts...")
executables = [
"/usr/bin/alienfx",
"/usr/local/bin/alienfx",
"/usr/bin/alienfx-gtk",
"/usr/local/bin/alienfx-gtk",
]
removed_count = 0
for exe in executables:
if remove_file(exe):
removed_count += 1
return removed_count
def remove_package_files():
"""Remove Python package files."""
print_header("Removing Python package files...")
removed_count = 0
site_packages_dirs = get_python_site_packages()
# Also check common locations
site_packages_dirs.extend([
"/usr/lib/python3/dist-packages",
"/usr/local/lib/python3/dist-packages",
])
for site_dir in site_packages_dirs:
if not os.path.exists(site_dir):
continue
# Remove alienfx package directory
alienfx_dir = os.path.join(site_dir, "alienfx")
if remove_directory(alienfx_dir):
removed_count += 1
# Remove egg-info directory
for item in Path(site_dir).glob("alienfx-*.egg-info"):
if remove_directory(str(item)):
removed_count += 1
# Remove dist-info directory
for item in Path(site_dir).glob("alienfx-*.dist-info"):
if remove_directory(str(item)):
removed_count += 1
return removed_count
def update_desktop_database():
"""Update desktop database and icon cache."""
print_header("Updating system caches...")
try:
# Update desktop database
subprocess.run(
["update-desktop-database", "/usr/share/applications"],
stderr=subprocess.DEVNULL,
check=False
)
subprocess.run(
["update-desktop-database", "/usr/local/share/applications"],
stderr=subprocess.DEVNULL,
check=False
)
print_success("Updated desktop database")
except Exception as e:
print_warning(f"Could not update desktop database: {e}")
try:
# Update icon cache
subprocess.run(
["gtk-update-icon-cache", "/usr/share/icons/hicolor"],
stderr=subprocess.DEVNULL,
check=False
)
print_success("Updated icon cache")
except Exception as e:
print_warning(f"Could not update icon cache: {e}")
def check_permissions():
"""Check if script is run with sufficient permissions."""
if os.geteuid() != 0:
print_warning("This script is not running as root.")
print_info("Some files may require root privileges to remove.")
response = input("Continue anyway? [y/N]: ")
if response.lower() != 'y':
print_info("Uninstallation cancelled.")
sys.exit(0)
def main():
"""Main uninstaller function."""
print_header("═" * 60)
print_header("AlienFX Uninstaller")
print_header("═" * 60)
# Check permissions
check_permissions()
# Confirm uninstallation
print_info("\nThis will remove AlienFX and all its files from your system.")
response = input("Do you want to continue? [y/N]: ")
if response.lower() != 'y':
print_info("Uninstallation cancelled.")
sys.exit(0)
# Perform uninstallation steps
total_removed = 0
# Try pip uninstall first
if uninstall_pip_package():
total_removed += 1
# Remove package files manually
total_removed += remove_package_files()
# Remove executables
total_removed += remove_executables()
# Remove data files
total_removed += remove_data_files()
# Remove udev rules
if remove_udev_rules():
total_removed += 1
# Update system caches
update_desktop_database()
# Final summary
print_header("═" * 60)
if total_removed > 0:
print_success(f"\nUninstallation complete! Removed {total_removed} items.")
else:
print_warning("\nNo AlienFX files were found on the system.")
print_header("═" * 60)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print_error("\n\nUninstallation cancelled by user.")
sys.exit(1)
except Exception as e:
print_error(f"\n\nUnexpected error: {e}")
sys.exit(1)