-
Notifications
You must be signed in to change notification settings - Fork 1
/
pac.sh
executable file
·130 lines (121 loc) · 3.53 KB
/
pac.sh
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
#!/bin/sh
#
# Author: Indrek Haav
# Source: https://github.com/IndrekHaav/pac
set -eu
RESET="\033[0m"
RED="\033[1;31m"
__usage() {
cat <<EOF
Usage: $(basename "$0") command
Available commands:
search <string> Searches for packages matching <string>
show <package> Returns information about <package>
list --installed Lists all installed packages
--manual Lists all manually installed packages
--upgradable Lists all upgradable packages
--all Lists all available packages
depends <package> Shows a list of dependencies for <package>
rdepends <package> Shows a list of packages that depend on <package>
install <package> Installs <package>
download <package> Downloads <package> to current directory
cache <package> Downloads <package> to pacman cache
remove <package> Removes <package>
autoremove <package> Removes <package> and all its unneeded dependencies
autoremove Removes all unneeded dependencies
clean Removes unneeded cached packages and sync database
upgrade, dist-upgrade Performs a full system upgrade
EOF
exit
}
__error() {
printf "${RED}error:${RESET} %s\n" "$1"
}
__fatal() {
__error "$1"
exit 1
}
__require() {
command -v "$1" >/dev/null || __fatal "install ${2:-$1} to use this functionality"
}
[ "$#" -gt 0 ] || __usage
case "$1" in
search)
shift
[ "$#" -eq 1 ] || __fatal "enter a search term"
pacman -Ss "$*"
;;
show)
shift
[ "$#" -gt 0 ] || __fatal "enter a package name"
for package in "$@"; do
pacman -Qi "$package" 2>/dev/null || pacman -Si "$package" 2>/dev/null || __error "package '$package' was not found"
done
;;
list)
shift
case "${1-}" in
--installed) pacman -Q ;;
--manual) pacman -Qm ;;
--upgradable) pacman -Qu ;;
--all) pacman -Sl ;;
*) __usage ;;
esac
;;
depends)
shift
__require pactree pacman-contrib
[ "$#" -gt 0 ] || __fatal "enter a package name"
pactree -s -d1 -o1 "$@"
;;
rdepends)
shift
__require pactree pacman-contrib
[ "$#" -gt 0 ] || __fatal "enter a package name"
pactree -r -s -d1 -o1 "$@"
;;
install)
shift
[ "$#" -gt 0 ] || __fatal "enter a package name"
if [ -f "$*" ]; then pacman -U "$*"; else pacman -S "$@"; fi
;;
download)
shift
__require curl
[ "$#" -eq 1 ] || __fatal "enter a package name"
curl -O "$(pacman -Sp "$*")"
;;
cache)
shift
[ "$#" -eq 1 ] || __fatal "enter a package name"
pacman -Sw "$*"
;;
remove)
shift
[ "$#" -gt 0 ] || __fatal "enter a package name"
pacman -R "$@"
;;
autoremove)
shift
pkgs=${*:-$(pacman -Qdtq)}
# shellcheck disable=SC2086
[ -n "$pkgs" ] && pacman -Rns $pkgs
;;
update)
shift
if [ "$#" -eq 0 ]; then
__fatal "this command would execute 'pacman -Sy', but partial upgrades are not supported"
else
__fatal "this command would execute 'pacman -S $*', but partial upgrades are not supported"
fi
;;
upgrade|dist-upgrade|full-upgrade)
pacman -Syu
;;
clean)
pacman -Sc
;;
*)
__usage
;;
esac