-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpurgerc
105 lines (86 loc) · 2.78 KB
/
purgerc
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
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - miscellaneous/purgerc
# Started On - Fri 18 May 23:07:54 BST 2018
# Last Change - Fri 15 Jun 10:38:16 BST 2018
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
_VERSION_="2018-06-15"
XERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; exit 1; }
ERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; }
DOM="https://github.com"
USAGE(){
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
PURGERC ($_VERSION_)
Written by terminalforlife ([email protected])
Very simple and light shell command to remove 'rc' packages.
SYNTAX: purgerc [OPTS]
OPTS: --help|-h|-? - Displays this help information.
--version|-v - Output only the version datestamp.
--quiet|-q - Runs in quiet mode. Errors still output.
--update|-U - Check for updates to simplify-ubuntu.
SITE: $DOM
EOF
}
while [ "$1" ]; do
case "$1" in
--help|-h|-\?)
USAGE; exit 0 ;;
--version|-v)
printf "%s\n" "$_VERSION_"
exit 0 ;;
--quiet|-q)
BEQUIET="true" ;;
--update|-U)
UPDATE="true" ;;
*)
XERR "$LINENO" "Incorrect argument(s) specified." ;;
esac
shift
done
declare -i DEPCOUNT=0
for DEP in /usr/bin/{wget,dpkg,apt-get}; {
if ! [ -x "$DEP" ]; then
ERR "$LINENO" "Dependency '$DEP' not met."
DEPCOUNT+=1
fi
}
[ $DEPCOUNT -eq 0 ] || exit 1
read -a WGET_VER_LINE <<< "$(/usr/bin/wget --version)"
WGET_VERSION=0${WGET_VER_LINE[2]//[!0-9]}
if [ $WGET_VERSION -ge 01192 -a $WGET_VERSION -lt 01194 ]; then
NOWARC="--no-warc-compression"
fi
if [ "$UPDATE" == "true" ]; then
VERSION_URL="$DOM/terminalforlife/miscellaneous/raw/master/purgerc-version"
LATEST=`/usr/bin/wget $NOWARC -q "$VERSION_URL" -O -`
if [[ "${LATEST//-}" =~ ^[0-9]{8}$ ]]; then
if [ ${LATEST//-} -gt ${_VERSION_//-} ]; then
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
New version available: $LATEST
Current version: $_VERSION_
EOF
fi
else
XERR "$LINENO" "Failed to check for available updates."
fi
exit 0
fi
[ $UID -eq 0 ] || XERR "$LINENO" "Root access is required to purge 'rc' packages."
[ "$BEQUIET" == "true" ] && exec 1> /dev/null
[ "$DEBUGME" == "true" ] && set -x
while read -a X; do
[ "${X[0]}" == "rc" ] && LIST+=" ${X[1]}"
done <<< "$(/usr/bin/dpkg -l)"
if [ "$LIST" ]; then
/usr/bin/apt-get -q -o Dpkg::Progress=true -o Dpkg::Progress-Fancy=true\
-o APT::Get::AutomaticRemove=true remove --purge $LIST
else
printf "No 'rc' packages detected by APT.\n" 1>&2
exit 1
fi