Skip to content

Instantly share code, notes, and snippets.

@sineemore
Last active November 13, 2021 02:25
Show Gist options
  • Save sineemore/5261eb0c50e148c783edd24eb8630bc0 to your computer and use it in GitHub Desktop.
Save sineemore/5261eb0c50e148c783edd24eb8630bc0 to your computer and use it in GitHub Desktop.
Script to list updated packages without root
#!/bin/sh
set -eu
argv0="$0"
usage() {
printf 'usage: %s [-s] [-m] [-h] [package...]\n' "$argv0"
}
mode=a
while [ $# -gt 0 ]
do
arg="$1"
if [ "$(printf %.1s "$1")" != - -o "$1" = -- ]
then
break
fi
shift 1
case "$arg" in
-s) mode=s ;; # show selected packages updates
-m) mode=m ;; # show selected and manually installed packages updates
-h) usage
exit 0
;;
-*) usage >&2
exit 1
;;
esac
done
all="$(mktemp)"
selected="$(mktemp)"
manuall="$(mktemp)"
cleanup() {
rm -f -- "$all" "$selected" "$manuall"
}
trap cleanup EXIT INT HUP
strip_version() {
sed -E 's/(.+)-[^-]+/\1/'
}
xbps-install -Mun | cut -d' ' -f1 | strip_version > "$all"
printf '%s\n' "$@" | sort | comm -12 "$all" - > "$selected"
xbps-query -mp pkgname | strip_version | comm -12 "$all" - > "$manuall"
case "$mode" in
s)
cat "$selected"
;;
m)
cat "$selected"
comm -13 "$selected" "$manuall"
;;
a)
cat "$selected"
comm -13 "$selected" "$manuall"
sort "$selected" "$manuall" | comm -23 "$all" -
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment