forked from Bumblebee-Project/Bumblebee-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup
executable file
·151 lines (134 loc) · 5.16 KB
/
cleanup
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
#!/bin/bash
# Copyright (C) 2011 Bumblebee Project
#
# This file is part of Bumblebee.
#
# Bumblebee 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 3 of the License, or
# (at your option) any later version.
#
# Bumblebee 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 Bumblebee. If not, see <http://www.gnu.org/licenses/>.
if (( UID != 0 )); then
echo "You must run this cleanup program as root."
if which sudo &>/dev/null; then
echo "That can be done by running:"
echo " sudo $0"
fi
exit 2
fi
# Do not show * if there is no matching file
shopt -s nullglob
# ok, the old uninstaller is horrible, do not even use it
[ -x /etc/init.d/bumblebee ] && /etc/init.d/bumblebee disable
[ -x /usr/local/bin/bumblebee-enablecard ] && /usr/local/bin/bumblebee-enablecard
# just to be sure...
pcibusid="$(lspci -nn -d10de: | grep '030[02]' | cut -d' ' -f1)"
if lspci -vv -s "$pcibusid" | grep -q '!!!'; then
echo "WARNING: Your nvidia card is still disabled. I will not continue to"
echo "prevent damage. Try rebooting the machine and try again."
echo "If this problem persists, create a new issue at the project page"
echo "https://github.com/Bumblebee-Project/Bumblebee/issues"
echo
echo "Technical details:"
lspci -vvnn -s "$pcibusid"
exit 3
fi
# Test if a debian package is installed
dpkg_installed() {
[[ $(dpkg-query -W -f '${Status}' "$1" 2>/dev/null) == install* ]]
}
# Distro-specific cleanups
if grep -iqE 'ubuntu|linux mint|backtrack linux 5' /etc/issue; then
echo "Detected distributon: Ubuntu-based"
if dpkg_installed bumblebee; then
echo "Old Bumblebee package installation detected, removing..."
if ! apt-get purge -y bumblebee; then
echo "The old Bumblebee package could not be removed."
echo "Installation aborted."
exit 1
fi
fi
# Bumblebee fails to clean up /etc/rc?.d, we'll do it if necessary
update-rc.d -f bumblebee remove
echo "Removing conflicting PPAs if any..."
# Remove PPA if found to avoid conflicts
for ppalist in /etc/apt/sources.list.d/mj-casalogic-bumblebee-*.list; do
rm -vf "$ppalist"
done
# On versions before Oneiric with no mesa installation using Multiarch
if dpkg --compare-versions "$(lsb_release -rs)" le 11.04 &&
grep -q 'install /etc/ld.so.conf.d/GL.conf' /var/lib/dpkg/info/libgl1-mesa-glx.postinst; then
echo "Fixing alternatives links if any"
update-alternatives --remove x86_64-linux-gnu_gl_conf /usr/lib/nvidia-current/ld.so.conf
update-alternatives --remove i386-linux-gnu_gl_conf /usr/lib/nvidia-current/alt_ld.so.conf
update-alternatives --remove i386-linux-gnu_gl_conf /usr/lib/nvidia-current/ld.so.conf
# fix alternatives links and restore /usr/lib/mesa/ld.so.conf
apt-get install --reinstall -y libgl1-mesa-glx
fi
for package in acpi-call-dkms bumblebee-ui nvidia-current virtualgl; do
if dpkg_installed "$package"; then
# Rather uninstall than some clean here, we used custom versions not really clean
apt-get purge -y "$package"
fi
done
echo "Removing junkfiles if any..."
for junk in \
/etc/alternatives/xorg_extra_modules-bumblebee \
/usr/lib/xorg/x11-extra-modules/xorg \
/usr/lib/nvidia-current/xorg/xorg \
/etc/alternatives/_xorg_extra_modules \
/etc/bash_completion.d/optirun*
do
[ -L "$junk" -o -f "$junk" ] && rm -vf "$junk"
done
elif grep -iq fedora /etc/issue; then
echo "Detected distribution: Fedora-based"
elif grep -iq opensuse /etc/issue; then
echo "Detected distribution: OpenSUSE-based"
elif grep -iq 'arch linux' /etc/issue; then
echo "Detected distribution: Arch Linux-based"
elif grep -iq debian /etc/issue; then
echo "Detected distribution: Debian-based"
elif grep -iq gentoo /etc/issue; then
echo "Detected distribution: Gentoo-based"
else
echo "The distribution could not be determined or is unsupported."
exit 3
fi
# Distro-independent cleanup
echo "Restoring backed up files if any..."
# restore backed up files
for file in \
/etc/bashrc /etc/bash.bashrc \
/etc/modprobe.d/blacklist.conf \
/etc/modules \
/etc/X11/xorg.conf \
; do
[ -f "${file}.optiorig" ] && mv -v "${file}.optiorig" "$file"
done
echo "Remove distro-independent files if any..."
for junk in \
/etc/X11/xorg.conf.nvidia \
/etc/init.d/bumblebee \
/usr/local/bin/*optirun* \
/usr/local/bin/bumblebee* \
/etc/default/bumblebee*
do
[ -f "$junk" ] && rm -vf "$junk"
done
echo "Remove distro-independent directories if any..."
for junk_dirs in \
/usr/share/doc/bumblebee \
/usr/share/doc/packages/bumblebee
do
[ -d "$junk_dirs" ] && rm -rvf "$junk_dirs"
done
rm -f /etc/bumblebee
echo "Done"