xoutdated.sh
· 4.1 KiB · Bash
Raw
#!/usr/bin/env bash
set -euo pipefail
# Prerequisite:
# 1. presumably Void Linux
# 2. install xtools, perl (base-devel)
# 3. set XBPS_DISTDIR to your local copy of void-packages
# VERSION="3.2.2"
# List available updates of void packages installed locally for a specific contributor
# Usage: outdated_who email author
outdated_who(){
# local EXCLUDE_REGEX="apache-"
local email="$1"
local author="$2"
# URL encode email
local encoded_email
# encoded_email=$(echo -n "$email" | jq -sRr @uri)
encoded_email=$(echo -n "$email" | perl -MURI::Escape -ne 'print uri_escape($_)')
# encoded_email=$(echo -n "$email" | python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read()))")
local DISTURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_${encoded_email}.txt"
local DISTFILE="updates_${author}.txt"
CONNECTION_TIMEOUT=5000 xbps-fetch -o "${DISTFILE}" "${DISTURL}"
# wcurl --curl-options="--progress-bar" --output "${DISTFILE}" "${DISTURL}"
# wget --hsts-file="$XDG_CACHE_HOME/wget-hsts" --output-document "${DISTFILE}" --quiet "${DISTURL}"
# filter out uninterested packages
# opinionated, `lib` could be a bit overkill
# TODO: pass regex as variable to grep
grep -vE 'apache-|avr-|brltty|cargo-|cinnamon|dkms|gnome-|gst-|jenkins|lib|linux|nemo-|pantheon-|perl-|ruby-|R-cran-|webkit2gtk' "${DISTFILE}" | sponge "${DISTFILE}"
# dedup, leave only the highest available version
# side effect: order is slightly different
awk '!seen[$1]++ {line[$1] = $0} {line[$1] = $0} END {for (pkg in line) print line[pkg]}' "${DISTFILE}" | sort | sponge "${DISTFILE}"
# dedup again, leave only installed packages
awk 'NR==FNR{installed[$1]; next} $1 in installed' installed.txt "${DISTFILE}" | sort | sponge "${DISTFILE}"
}
# List my outdated packages w/o xcheckmypkgs
# only work in local void-packages copy if XBPS_DISTDIR is not set
outdated_mypkg(){
local MYURL
XDISTDIR="$(xdistdir)" || exit 1
MYURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_$(git -C "${XDISTDIR}" config user.email | sed 's/@/%40/').txt"
local MYFILE="updates_me.txt"
CONNECTION_TIMEOUT=5000 xbps-fetch -o "${MYFILE}" "${MYURL}"
}
LOG_FILE="updates_nover.txt"
# List packages that have error checking updates
outdated_error(){
local LOG_URL="https://repo-default.voidlinux.org/void-updates/void-updates/_log.txt"
CONNECTION_TIMEOUT=5000 xbps-fetch -o "${LOG_FILE}" "${LOG_URL}"
# leave only (manually) installed packages
grep -v 'No such file' < ${LOG_FILE} | awk 'BEGIN {
while ((getline < "installed.txt") > 0) {
installed[$1]
}
}
{
package = $5;
if (package in installed) print $0
}' | sponge ${LOG_FILE}
}
# strip updated packages
# TODO: add version comparison logic/walk through commit history to wisely include when newer updates are available
strip_updated(){
# local UPDATED_PKGS=(colord-gtk lvm2 python3-usb)
echo "Stripping..."
# NOTE: assume you follow "$PKG-update" scheme in branch names (and "$PKG" is indeed latest)
git branch | grep "update" | sed 's/-update//g' | awk '{ print $1 }' > branches.txt
shopt -s nullglob
for file in updates_*.txt
do
# skip no ver
if [[ "${file}" == "${LOG_FILE}" ]] ; then
true
else
# strip updated packages in branches with mixed commits
grep -vE "colord-gtk|lvm2|python3-usb" "${file}" | sponge "${file}"
# strip updated branch
awk 'NR==FNR{branches[$1]; next} {for (b in branches) if ($1 ~ b) next} {print}' branches.txt "${file}" | sponge "${file}"
fi
done
rm branches.txt
}
cd "$XBPS_DISTDIR" || exit 1
# list only manually installed packages
xpkg -m > installed.txt
# query all installed packages (including core packages, more complete, but MUCH slower)
# xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname > installed.txt
# functions here
outdated_who "[email protected]" "orphan"
outdated_mypkg
outdated_error
strip_updated
# garbage clean
rm installed.txt
1 | #!/usr/bin/env bash |
2 | set -euo pipefail |
3 | |
4 | # Prerequisite: |
5 | # 1. presumably Void Linux |
6 | # 2. install xtools, perl (base-devel) |
7 | # 3. set XBPS_DISTDIR to your local copy of void-packages |
8 | |
9 | # VERSION="3.2.2" |
10 | |
11 | # List available updates of void packages installed locally for a specific contributor |
12 | # Usage: outdated_who email author |
13 | outdated_who(){ |
14 | # local EXCLUDE_REGEX="apache-" |
15 | local email="$1" |
16 | local author="$2" |
17 | |
18 | # URL encode email |
19 | local encoded_email |
20 | # encoded_email=$(echo -n "$email" | jq -sRr @uri) |
21 | encoded_email=$(echo -n "$email" | perl -MURI::Escape -ne 'print uri_escape($_)') |
22 | # encoded_email=$(echo -n "$email" | python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read()))") |
23 | local DISTURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_${encoded_email}.txt" |
24 | local DISTFILE="updates_${author}.txt" |
25 | |
26 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${DISTFILE}" "${DISTURL}" |
27 | # wcurl --curl-options="--progress-bar" --output "${DISTFILE}" "${DISTURL}" |
28 | # wget --hsts-file="$XDG_CACHE_HOME/wget-hsts" --output-document "${DISTFILE}" --quiet "${DISTURL}" |
29 | |
30 | # filter out uninterested packages |
31 | # opinionated, `lib` could be a bit overkill |
32 | # TODO: pass regex as variable to grep |
33 | grep -vE 'apache-|avr-|brltty|cargo-|cinnamon|dkms|gnome-|gst-|jenkins|lib|linux|nemo-|pantheon-|perl-|ruby-|R-cran-|webkit2gtk' "${DISTFILE}" | sponge "${DISTFILE}" |
34 | |
35 | # dedup, leave only the highest available version |
36 | # side effect: order is slightly different |
37 | awk '!seen[$1]++ {line[$1] = $0} {line[$1] = $0} END {for (pkg in line) print line[pkg]}' "${DISTFILE}" | sort | sponge "${DISTFILE}" |
38 | |
39 | # dedup again, leave only installed packages |
40 | awk 'NR==FNR{installed[$1]; next} $1 in installed' installed.txt "${DISTFILE}" | sort | sponge "${DISTFILE}" |
41 | } |
42 | |
43 | # List my outdated packages w/o xcheckmypkgs |
44 | # only work in local void-packages copy if XBPS_DISTDIR is not set |
45 | outdated_mypkg(){ |
46 | local MYURL |
47 | XDISTDIR="$(xdistdir)" || exit 1 |
48 | MYURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_$(git -C "${XDISTDIR}" config user.email | sed 's/@/%40/').txt" |
49 | local MYFILE="updates_me.txt" |
50 | |
51 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${MYFILE}" "${MYURL}" |
52 | } |
53 | |
54 | LOG_FILE="updates_nover.txt" |
55 | # List packages that have error checking updates |
56 | outdated_error(){ |
57 | local LOG_URL="https://repo-default.voidlinux.org/void-updates/void-updates/_log.txt" |
58 | |
59 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${LOG_FILE}" "${LOG_URL}" |
60 | |
61 | # leave only (manually) installed packages |
62 | grep -v 'No such file' < ${LOG_FILE} | awk 'BEGIN { |
63 | while ((getline < "installed.txt") > 0) { |
64 | installed[$1] |
65 | } |
66 | } |
67 | { |
68 | package = $5; |
69 | if (package in installed) print $0 |
70 | }' | sponge ${LOG_FILE} |
71 | } |
72 | |
73 | # strip updated packages |
74 | # TODO: add version comparison logic/walk through commit history to wisely include when newer updates are available |
75 | strip_updated(){ |
76 | # local UPDATED_PKGS=(colord-gtk lvm2 python3-usb) |
77 | |
78 | echo "Stripping..." |
79 | # NOTE: assume you follow "$PKG-update" scheme in branch names (and "$PKG" is indeed latest) |
80 | git branch | grep "update" | sed 's/-update//g' | awk '{ print $1 }' > branches.txt |
81 | |
82 | shopt -s nullglob |
83 | for file in updates_*.txt |
84 | do |
85 | # skip no ver |
86 | if [[ "${file}" == "${LOG_FILE}" ]] ; then |
87 | true |
88 | else |
89 | # strip updated packages in branches with mixed commits |
90 | grep -vE "colord-gtk|lvm2|python3-usb" "${file}" | sponge "${file}" |
91 | # strip updated branch |
92 | awk 'NR==FNR{branches[$1]; next} {for (b in branches) if ($1 ~ b) next} {print}' branches.txt "${file}" | sponge "${file}" |
93 | fi |
94 | done |
95 | |
96 | rm branches.txt |
97 | } |
98 | |
99 | cd "$XBPS_DISTDIR" || exit 1 |
100 | |
101 | # list only manually installed packages |
102 | xpkg -m > installed.txt |
103 | # query all installed packages (including core packages, more complete, but MUCH slower) |
104 | # xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname > installed.txt |
105 | |
106 | # functions here |
107 | outdated_who "[email protected]" "orphan" |
108 | outdated_mypkg |
109 | outdated_error |
110 | strip_updated |
111 | |
112 | # garbage clean |
113 | rm installed.txt |
114 |