nixpkgs/pkgs/common-updater/scripts/list-archive-two-levels-versions
José Romildo f15117a874 generic-updater: more flexible with name, pname, version and attr path
- This information is availabe from environment variables defined by
maintainers/scripts/update.nix

- Renamed the shell script to generic-update-script.sh

- Add a new optional argument (representing the package name) to the
shell script

- The version lister is called with a new optional
argument (representing the package attribute path)
2022-09-27 23:41:53 -03:00

63 lines
1.5 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# lists all available versions listed for a package in a site (http)
pname="" # package name
attr_path="" # package attribute path
url="" # directory list url
file="" # file for writing debugging information
while (( $# > 0 )); do
flag="$1"
shift 1
case "$flag" in
--pname=*)
pname="${flag#*=}"
;;
--attr-path=*)
attr_path="${flag#*=}"
;;
--url=*)
url="${flag#*=}"
;;
--file=*)
file="${flag#*=}"
;;
*)
echo "$0: unknown option ${flag}"
exit 1
;;
esac
done
if [[ -z "$pname" ]]; then
pname="$UPDATE_NIX_NAME"
fi
if [[ -z "$attr_path" ]]; then
attr_path="$UPDATE_NIX_ATTR_PATH"
fi
# by default set url to the base dir of the first url in src.urls
if [[ -z "$url" ]]; then
url="$(nix-instantiate $systemArg --eval -E \
"with import ./. {}; dirOf (dirOf (lib.head $attr_path.src.urls))" \
| tr -d '"')"
fi
# print a debugging message
if [[ -n "$file" ]]; then
echo "# Listing versions for '$pname' at $url" >> $file
fi
# list all major-minor versions from url
tags1=$(curl -sS "$url/")
tags1=$(echo "$tags1" | sed -rne 's,^<a href="([0-9]+\.[0-9]+)/">.*,\1,p')
# print available versions
for tag in $tags1; do
tags2=$(curl -sS "$url/$tag/")
tags2=$(echo "$tags2" | sed -rne "s,^<a href=\"$pname-([0-9.]+)\\.[^0-9].*\">.*,\\1,p")
echo "$tags2"
done