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