-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean_dnf
60 lines (55 loc) · 2.2 KB
/
clean_dnf
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
#! /bin/bash
#----------------------------------------------------------------------
# Description: script for rpm uninstallation within all installed rpms
#
# Author: Artem S. Tashkinov
# Created at:
# Mon Nov 21 20:12:04 2016 - dnf, show deps, no clear
# Wed Dec 13 19:43:00 2017 - remove by mask, skip already deleted, skip protected
# Fri May 11 18:52:51 2018 - skip packages with errors instead of waithing for the user input
# stop background dependancy checking
# set env var SKIP to skip up to a certain package
#
# Copyright (c) 2004 Artem S. Tashkinov. All rights reserved.
#----------------------------------------------------------------------
#set -x
dont_remove="|AdobeReader_enu|Thunar|icewm|hexchat|xterm|xfce4|qbittorrent|mkvtoolnix|rpm-build|wireshark|samba|libxml2-devel|libvorbis|libogg|alsa|lxdm|xfdesktop|openssh|vpx|google-chrome|mesa-lib|libxslt|openssl|pulseaudio-libs|electrum|firewall"
clear
resolve()
{
name=`rpm -q --queryformat "%{NAME}" "$1"`
result=`dnf -C --setopt=clean_requirements_on_remove=False --assumeno remove "$1" 2>&1` # | grep -v "Operation aborted."`
protect=`echo "$result" | egrep "protected packages$dont_remove"`
if [ -z "$protect" ]; then
myself=`echo "$result" | grep -vw "$name" | awk '/@/{print $1"-"$3"."$2}'` # awk: don't print the package itself as a dependancy: if (index("'"$1"'",$1)) next;
if [ -z "$myself" ]; then
echo "[OK]: no dependencies found."
else
echo -n "[WARN]: Dependent on $1: "
echo "$result" | grep -vw "$name" | awk 'BEGIN{ORS=", "}/@/{print $1}' | sed 's/, $/\n/'
fi
echo -n "Remove (n)? "
else
echo -e "[ERROR]:\n$protect"
return 1
fi
}
some="."
test -n "$1" && some="$1"
for i in `rpm -qa | sort | grep "$some"`; do
[[ "$i" < "$SKIP" ]] && continue
# clear
if rpm -qi "$i"; then
if resolve "$i"; then # &
read answer
if [ "$answer" == "Y" -o "$answer" == "y" ]; then
dnf -C remove "$i"
fi
else
echo "[ERROR]: skipping a protected package"
fi
else
echo "[WARNING]: Package "$i" has already been removed"
fi
echo "________________________________________________________________"
done