-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpkgs.sh
executable file
·131 lines (97 loc) · 2.76 KB
/
checkpkgs.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
131
#!/bin/bash
# shellcheck disable=SC1091
. gettext.sh
export TEXTDOMAIN=checkpkgs
export TEXTDOMAINDIR=/usr/share/locale
check_version() {
local local_version pkg_version pkg_name
local_version="$1"
pkg_version="$2"
pkg_name="$3"
if [ -z "$local_version" ]; then
gather "$(gettext "Package %b%s %bnot installed%b. Its last version is %b%s%b.\n")" "$WC" "$pkg_name" "$CC" "$NC" "$GC" "$pkg_version" "$NC"
elif [ ! "$local_version" == "$pkg_version" ]; then
gather "$(gettext "Package %b%s %boutdated%b [%b%s%b -> %b%s%b].\n")" "$WC" "$pkg_name" "$CC" "$NC" "$GC" "$local_version" "$NC" "$GC" "$pkg_version" "$NC"
else
gather "$(gettext "Package %b%s %bup to date%b [%b%s%b].\n")" "$WC" "$pkg_name" "$CC" "$NC" "$GC" "$local_version" "$NC"
fi
}
get_package_version() {
local pkg pkg_info pkg_version pkg_rel
pkg="$1"
pkg_info=$(curl -s "$QUERY_URL$pkg" | jq -c '.results[0]')
pkg_version=$(jq '.pkgver' <<<"$pkg_info")
pkg_rel=$(jq '.pkgrel' <<<"$pkg_info")
echo "$pkg_version-$pkg_rel" | tr -d '"'
}
gather() {
local text
text="$1"; shift
# shellcheck disable=SC2059
printf "$text" "$@"
}
print_array() {
local IFS=,; gather "$(gettext "Checking %s ...\n\n")" "$*"
}
show_info() {
local pkg pkg_info pkg_version local_version
pkg="$1"
pkg_version=$(get_package_version "$pkg")
if [[ "$pkg_version" =~ "null" ]]; then
gather "$(gettext "Package %b%s %bnot found%b.\n")" "$WC" "$pkg" "$CC" "$NC"
else
local_version=$(pacman -Q "$pkg" 2>/dev/null | awk '{ print $2 }')
check_version "$local_version" "$pkg_version" "$pkg"
fi
}
main() {
local pkg
print_array "$@"
for pkg in "$@"; do
if [ -z "$ORDERED" ]; then
show_info "$pkg" &
else
show_info "$pkg"
fi
done
wait
}
initial_checks() {
if ! which pacman >/dev/null; then
(gettext 'pacman is not installed.'; echo;) >&2
exit 1
fi
[ ${#packages[@]} -eq 0 ] && exit 1
}
set_testing_repositories() {
[ -n "$COMMUNITY_TESTING" ] && REPO_URL+="&repo=Community-Testing"
[ -n "$MULTILIB_TESTING" ] && REPO_URL+="&repo=Multilib-Testing"
[ -n "$TESTING" ] && REPO_URL+="&repo=Testing"
}
ARCH="${ARCH:-$(uname -m)}"
BASE_URL="https://www.archlinux.org/packages/search/json/"
ARCH_URL="arch=any&arch=$ARCH"
REPO_URL="repo=Community&repo=Core&repo=Extra&repo=Multilib"
NAME_URL="name="
GC="\033[1;32m" # green
CC="\033[1;36m" # cyan
WC="\033[1;97m" # white
NC="\033[0m" # no color
set_testing_repositories
QUERY_URL="$BASE_URL?$ARCH_URL&$REPO_URL&$NAME_URL"
typeset -a packages
if [ ! -t 0 ]; then
while read -r pkg; do
packages+=( "$pkg" )
done
fi
while [ -n "$1" ]; do
case "$1" in
-o|--ordered)
ORDERED=1; shift;;
*)
packages+=( "$1" ); shift;;
esac
done
initial_checks
main "${packages[@]}"