From a6e53e505363e1e02cc33831c56c5ebd54f1cb0d Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Sat, 25 Mar 2023 22:43:29 +0100 Subject: [PATCH] Implement sorcery sightsee command --- usr/lib/sorcery/cmd/sightsee | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 usr/lib/sorcery/cmd/sightsee diff --git a/usr/lib/sorcery/cmd/sightsee b/usr/lib/sorcery/cmd/sightsee new file mode 100755 index 00000000..69371d9f --- /dev/null +++ b/usr/lib/sorcery/cmd/sightsee @@ -0,0 +1,86 @@ +#!/bin/sh +codex=/var/lib/sorcery/codex +unset verbose paths + +upstream_rel_get() { + wget -q -O- "$1" | gawk -vfname="$2" ' + match($0, fname, V) { + $0 = substr($0, RSTART, RLENGTH) + print V[1 in V] + } + ' | sort -rV | sed q +} + +# Process options +while + case "$1" in + (--codex) + codex="$2" + shift 2 + ;; + (-v|--verbose) + verbose=1 + shift + ;; + (-h|--help) + cat <<"!" + +sightsee [spell...] Find upstream software releases. Takes paths or spell + names. +! + exit 0 + ;; + (*) false ;; + esac +do : +done + +if [ $# = 0 ]; then + paths="$codex" +else + for i in "$@"; do + case "$i" in + (*/*) ;; + (*) + if ! [ -d "$i" ]; then + j=$(find "$codex" -maxdepth 3 -name "$i" -type d -print -quit) + [ -d "$j" ] && i="$j" + fi + ;; + esac + paths+=("$i") + done +fi + +find "${paths[@]}" -name DETAILS -exec awk ' + function check_missing() { + if (spell != "") + printf "E: %s: Upstream releases page not specified\n", \ + spell >"/dev/stderr" + } + END { check_missing() } + FNR==1 { + check_missing() + spell = FILENAME + sub(/\/DETAILS$/, "", spell) + sub(/.*\//, "", spell) + } + /^ *VERSION=/ { + version = $0 + sub(/.*=/, "", version) + } + /^#Watch:/ { + # TODO check syntax + print spell, version, $2, $3 + spell = "" + nextfile + } + ' {} + | +while read spell cur_rel url regex; do + latest_rel=$(upstream_rel_get "$url" "$regex") && + if [ "x$latest_rel" != "x$cur_rel" ]; then + echo "$spell $latest_rel" + elif [ -n "$verbose" ]; then + >&2 echo "I: $spell is up to date" + fi +done -- 2.38.5