~sourcemage/sorcery

a6e53e505363e1e02cc33831c56c5ebd54f1cb0d — Ismael Luceno 2 months ago bd9e97e
Implement sorcery sightsee command
1 files changed, 86 insertions(+), 0 deletions(-)

A usr/lib/sorcery/cmd/sightsee
A usr/lib/sorcery/cmd/sightsee => usr/lib/sorcery/cmd/sightsee +86 -0
@@ 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