-
Notifications
You must be signed in to change notification settings - Fork 33
/
pkgbase
executable file
·76 lines (66 loc) · 1.66 KB
/
pkgbase
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
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 ([email protected])
#
# 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 <https://www.gnu.org/licenses/>.
#
#
# script to remove all packages other than base and any user input
#
parseopt() {
while [ "$1" ]; do
case $1 in
-n) dryrun=1;;
-y) yes=$1;;
-h) printhelp; exit 0;;
*) pkg="$pkg $1"
esac
shift
done
}
printhelp() {
cat << EOF
Usage:
$(basename $0) [options] [packages]
Options:
-n dry-run
-y dont ask user confirmation
-h print this help msg
EOF
}
error=0
parseopt "$@"
echo "Calculate packages to keep..."
keep=$(scratch deplist base $pkg | awk '{print $2}')
echo "Calculate selected packages to remove..."
for pkg in $(scratch installed | awk '{print $1}'); do
echo $keep | tr ' ' '\n' | grep -qx $pkg || {
remove="$remove $pkg"
}
done
[ "$remove" ] && {
[ "$dryrun" = 1 ] && {
for i in $remove; do
echo "remove: $i..."
done
echo "This is dry-run, no real action is run!"
} || {
scratch remove $yes $remove || error=1
}
} || {
echo "Already on base, nothing to remove."
}
exit $error