blob: 0bc63bcc60ac2e2004342763d1b4cda2d24fded8 (
plain)
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
|
#!/bin/bash
# Copyright (C) 2018-2022 Miquel Sabaté Solà <mikisabate@gmail.com>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
set -e
if [ "$EUID" -ne 0 ]; then
echo "You must be root in order to run this command."
exit 1
fi
function uri_for() {
uri=$(zypper lr $1 | grep -E "(http://|https://)" | awk '{ print $3; }')
echo $uri
}
declare -a ary
repositories=$(zypper lr -d | grep http | awk '{ print $3; }')
for repo in $repositories; do
# Check if it's disabled.
if [[ $(zypper lr -E $repo | grep Enabled | grep No) ]]; then
uri=$(uri_for "$repo")
echo "You should remove repo $repo (disabled) with URI: $uri"
ary=("${ary[@]}" "$repo")
continue
fi
# Check if there are no packages installed from this repo.
num=$(zypper pa -ir $repo | grep $repo | wc -l)
if [[ $num -eq 0 ]]; then
uri=$(uri_for "$repo")
ary=("${ary[@]}" "$repo")
echo "You should remove repo $repo with URI: $uri"
fi
done
len=${#ary[@]}
if [ $len -eq 0 ]; then
echo "No repositories to be purged!"
exit 0
fi
echo ""
read -p "Do you want to purge these repositories? [y/N] " choice
case "$choice" in
y|Y)
for repo in ${ary[@]}; do
zypper -n rr "$repo"
done
;;
* )
;;
esac
|