Last active 1740366766

List of available updates for void (anyone/mypkg/no version) packages installed locally.

xoutdated.sh Raw
1#!/usr/bin/env bash
2set -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
13outdated_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
45outdated_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
54LOG_FILE="updates_nover.txt"
55# List packages that have error checking updates
56outdated_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
75strip_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
99cd "$XBPS_DISTDIR" || exit 1
100
101# list only manually installed packages
102xpkg -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
107outdated_who "[email protected]" "orphan"
108outdated_mypkg
109outdated_error
110strip_updated
111
112# garbage clean
113rm installed.txt
114