xoutdated.sh
· 3.2 KiB · Bash
Raw
#!/bin/bash
# Prerequisite (presumably Void Linux with base-system installed): xtools, perl (base-devel)
# List available updates of void packages installed locally for a specific contributor
# Usage: outdated_who email author
outdated_who(){
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
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}"
# TODO: filter out existing update branches
# git branch --list |awk '{print $1}' > branches.txt
# awk 'NR==FNR{branches[$1]; next} {for (b in branches) if ($1 ~ b) next} {print}' branches.txt "${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}"
}
# List packages that have error checking updates
outdated_error(){
local LOG_URL="https://repo-default.voidlinux.org/void-updates/void-updates/_log.txt"
local LOG_FILE="updates_nover.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}
}
# 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
# garbage clean
rm installed.txt
1 | #!/bin/bash |
2 | # Prerequisite (presumably Void Linux with base-system installed): xtools, perl (base-devel) |
3 | |
4 | # List available updates of void packages installed locally for a specific contributor |
5 | # Usage: outdated_who email author |
6 | outdated_who(){ |
7 | local email="$1" |
8 | local author="$2" |
9 | |
10 | # URL encode email |
11 | local encoded_email |
12 | # encoded_email=$(echo -n "$email" | jq -sRr @uri) |
13 | encoded_email=$(echo -n "$email" | perl -MURI::Escape -ne 'print uri_escape($_)') |
14 | # encoded_email=$(echo -n "$email" | python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read()))") |
15 | local DISTURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_${encoded_email}.txt" |
16 | local DISTFILE="updates_${author}.txt" |
17 | |
18 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${DISTFILE}" "${DISTURL}" |
19 | # wcurl --curl-options="--progress-bar" --output "${DISTFILE}" "${DISTURL}" |
20 | # wget --hsts-file="$XDG_CACHE_HOME/wget-hsts" --output-document "${DISTFILE}" --quiet "${DISTURL}" |
21 | |
22 | # filter out uninterested packages |
23 | # opinionated, `lib` could be a bit overkill |
24 | grep -vE 'apache-|avr-|brltty|cargo-|cinnamon|dkms|gnome-|gst-|jenkins|lib|linux|nemo-|pantheon-|perl-|ruby-|R-cran-|webkit2gtk' "${DISTFILE}" | sponge "${DISTFILE}" |
25 | |
26 | # dedup, leave only the highest available version |
27 | # side effect: order is slightly different |
28 | awk '!seen[$1]++ {line[$1] = $0} {line[$1] = $0} END {for (pkg in line) print line[pkg]}' "${DISTFILE}" | sort | sponge "${DISTFILE}" |
29 | |
30 | # dedup again, leave only installed packages |
31 | awk 'NR==FNR{installed[$1]; next} $1 in installed' installed.txt "${DISTFILE}" | sort | sponge "${DISTFILE}" |
32 | |
33 | # TODO: filter out existing update branches |
34 | # git branch --list |awk '{print $1}' > branches.txt |
35 | # awk 'NR==FNR{branches[$1]; next} {for (b in branches) if ($1 ~ b) next} {print}' branches.txt "${DISTFILE}" |
36 | } |
37 | |
38 | # List my outdated packages w/o xcheckmypkgs |
39 | # only work in local void-packages copy if XBPS_DISTDIR is not set |
40 | outdated_mypkg(){ |
41 | local MYURL |
42 | XDISTDIR="$(xdistdir)" || exit 1 |
43 | MYURL="https://repo-default.voidlinux.org/void-updates/void-updates/updates_$(git -C "${XDISTDIR}" config user.email | sed 's/@/%40/').txt" |
44 | local MYFILE="updates_me.txt" |
45 | |
46 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${MYFILE}" "${MYURL}" |
47 | } |
48 | |
49 | # List packages that have error checking updates |
50 | outdated_error(){ |
51 | local LOG_URL="https://repo-default.voidlinux.org/void-updates/void-updates/_log.txt" |
52 | local LOG_FILE="updates_nover.txt" |
53 | |
54 | CONNECTION_TIMEOUT=5000 xbps-fetch -o "${LOG_FILE}" "${LOG_URL}" |
55 | |
56 | # leave only (manually) installed packages |
57 | grep -v 'No such file' < ${LOG_FILE} | awk 'BEGIN { |
58 | while ((getline < "installed.txt") > 0) { |
59 | installed[$1] |
60 | } |
61 | } |
62 | { |
63 | package = $5; |
64 | if (package in installed) print $0 |
65 | }' | sponge ${LOG_FILE} |
66 | } |
67 | |
68 | # list only manually installed packages |
69 | xpkg -m > installed.txt |
70 | # query all installed packages (including core packages, more complete, but MUCH slower) |
71 | # xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname > installed.txt |
72 | |
73 | # functions here |
74 | outdated_who "[email protected]" "orphan" |
75 | outdated_mypkg |
76 | outdated_error |
77 | |
78 | # garbage clean |
79 | rm installed.txt |
80 |