This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxm-uninstall
executable file
·152 lines (130 loc) · 5.12 KB
/
xm-uninstall
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
# -----------------------------------------------------------------------
# Uninstall kernel.
# Author: Mario Roy - http://github.com/marioroy
#
# 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, version 2 or later of the License.
#
# 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, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
if [[ "$1" == "all" ]]; then
# deprecated
#bash "$0" "clear-default" || exit $?
#bash "$0" "clear-preempt" || exit $?
#bash "$0" "edge-default" || exit $?
#bash "$0" "edge-preempt" || exit $?
#bash "$0" "main-default" || exit $?
#bash "$0" "main-preempt" || exit $?
#bash "$0" "lts-default" || exit $?
#bash "$0" "lts-preempt" || exit $?
#bash "$0" "rt-preempt" || exit $?
bash "$0" "clear-rt" || exit $?
bash "$0" "clear" || exit $?
bash "$0" "echo-rt" || exit $?
bash "$0" "echo" || exit $?
# since September 2024
bash "$0" "bore-rt" || exit $?
bash "$0" "bore" || exit $?
exit 0
fi
# shellcheck disable=SC2012,SC2046
# Capture the live kernel release, for safety to not remove self.
kversion="$(uname -r)" # e.g 6.1.54-100.xmbore
kvariant="${kversion}"
kvariant="${kvariant##*.}" # xmbore
kversion="${kversion%.*}" # 6.1.54-100
function xm_uninstall {
local variant="$1"; local release="$2"; local pkgs=""
if [[ -n "$release" ]]; then
# Uninstall given variant release (e.g. 100), skipping live kernel.
for kernel in $(sudo clr-boot-manager list-kernels | sed "s/\*//"); do
if [[ "${kernel}z" =~ org\.clearlinux\.${variant}\..*-${release}z ]]; then
if [[ "$kernel" == "org.clearlinux.${kvariant}.${kversion}" ]]; then
echo "Skipping live kernel ${kernel}"
else
echo "Removing ${kernel} from boot-manager"
sudo clr-boot-manager remove-kernel "$kernel" || exit 2
fi
fi
done
pkgs=$( rpm -qa | grep "^linux-${variant}-.*-${release}\.x86_64" )
else
# Uninstall variant (all releases), skipping live kernel.
for kernel in $(sudo clr-boot-manager list-kernels | sed "s/\*//"); do
if [[ "${kernel}" =~ org\.clearlinux\.${variant}\. ]]; then
if [[ "$kernel" == "org.clearlinux.${kvariant}.${kversion}" ]]; then
echo "Skipping live kernel ${kernel}"
else
echo "Removing ${kernel} from boot-manager"
sudo clr-boot-manager remove-kernel "$kernel" || exit 2
fi
fi
done
pkgs=$( rpm -qa | grep "^linux-${variant}-" )
fi
# Exclude the live kernel from the package list.
if [[ "$variant" == *"-rt"* ]]; then
pkgs=$( echo "$pkgs" |\
grep -Ev "^linux-${kvariant}-(license|extra|dev|cpio)-${kversion}.x86_64$" |\
grep -Ev "^linux-${kvariant}-${kversion}.x86_64$" )
else
pkgs=$( echo "$pkgs" | grep -v -- "-rt-" |\
grep -Ev "^linux-${kvariant}-(license|extra|dev|cpio)-${kversion}.x86_64$" |\
grep -Ev "^linux-${kvariant}-${kversion}.x86_64$" )
fi
if [[ -n "$pkgs" ]]; then
echo "Uninstalling packages:" && echo "$pkgs"
sudo rpm -e $pkgs 2>/dev/null
fi
# Create default symbolic link if another release exists on the system.
cd "/usr/lib/kernel" || exit 1
sudo rm -f "default-${variant}"
other_kernel=$(ls -1t "org.clearlinux.${variant}".* 2>/dev/null | head -1)
if [[ -n "$other_kernel" ]]; then
sudo ln -sf "$other_kernel" "default-${variant}"
fi
}
case "$1" in
bore | bore-rt )
xm_uninstall "xm${1}" "$2"
;;
# deprecated
clear | clear-rt | echo | echo-rt )
xm_uninstall "xm${1}" "$2"
;;
clear-default | clear-preempt )
xm_uninstall "xm${1}" "$2"
;;
edge-default | edge-preempt )
xm_uninstall "xm${1}" "$2"
;;
main-default | main-preempt )
xm_uninstall "xm${1}" "$2"
;;
lts-default | lts-preempt )
xm_uninstall "xm${1}" "$2"
;;
rt-preempt )
xm_uninstall "xm${1}" "$2"
;;
* ) echo "synopsis"
echo " $0 bore | bore-rt [<rel>]"
echo " $0 all"
echo ""
echo "deprecated"
echo " $0 clear | clear-rt | echo | echo-rt [<rel>]"
echo " $0 clear-default | clear-preempt [<rel>]"
echo " $0 edge-default | edge-preempt [<rel>]"
echo " $0 main-default | main-preempt [<rel>]"
echo " $0 lts-default | lts-preempt [<rel>]"
echo " $0 rt-preempt [<rel>]"
echo ""
esac