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)
This commit is contained in:
José Romildo 2022-09-27 17:49:23 -03:00
parent 6910e5840f
commit f15117a874
5 changed files with 71 additions and 48 deletions

View File

@ -1,8 +1,9 @@
{ stdenv, writeScript, coreutils, gnugrep, gnused, common-updater-scripts, nix }: { stdenv, writeScript, coreutils, gnugrep, gnused, common-updater-scripts, nix }:
{ pname { name ? null
, version , pname ? null
, attrPath ? pname , version ? null
, attrPath ? null
, versionLister , versionLister
, ignoredVersions ? "" , ignoredVersions ? ""
, rev-prefix ? "" , rev-prefix ? ""
@ -15,22 +16,28 @@ let
fileForGitCommands = "update-git-commits.txt"; fileForGitCommands = "update-git-commits.txt";
# shell script to update package # shell script to update package
updateScript = writeScript "update-script.sh" '' updateScript = writeScript "generic-update-script.sh" ''
#! ${stdenv.shell} #! ${stdenv.shell}
set -o errexit set -o errexit
set -x set -x
pname="$1" name="$1"
version="$2" pname="$2"
attr_path="$3" version="$3"
version_lister="$4" attr_path="$4"
ignored_versions="$5" version_lister="$5"
rev_prefix="$6" ignored_versions="$6"
odd_unstable="$7" rev_prefix="$7"
patchlevel_unstable="$8" odd_unstable="$8"
patchlevel_unstable="$9"
[[ -n "$name" ]] || name="$UPDATE_NIX_NAME"
[[ -n "$pname" ]] || pname="$UPDATE_NIX_PNAME"
[[ -n "$version" ]] || version="$UPDATE_NIX_OLD_VERSION"
[[ -n "$attr_path" ]] || attr_path="$UPDATE_NIX_ATTR_PATH"
# print header # print header
echo "# $pname-$version" >> ${fileForGitCommands} echo "# $name" >> ${fileForGitCommands}
function version_is_ignored() { function version_is_ignored() {
local tag="$1" local tag="$1"
@ -55,7 +62,7 @@ let
return 1 return 1
} }
tags=$($version_lister --pname=${pname} --file="${fileForGitCommands}") || exit 1 tags=$($version_lister --pname=$pname --attr-path=$attr_path --file="${fileForGitCommands}") || exit 1
# print available tags # print available tags
for tag in $tags; do for tag in $tags; do
@ -104,5 +111,7 @@ let
echo "" >> ${fileForGitCommands} echo "" >> ${fileForGitCommands}
''; '';
in in {
[ updateScript pname version attrPath versionLister ignoredVersions rev-prefix odd-unstable patchlevel-unstable ] name = "generic-update-script";
command = [ updateScript name pname version attrPath versionLister ignoredVersions rev-prefix odd-unstable patchlevel-unstable ];
}

View File

@ -3,9 +3,9 @@
, common-updater-scripts , common-updater-scripts
}: }:
{ pname { pname ? null
, version , version ? null
, attrPath ? pname , attrPath ? null
, ignoredVersions ? "" , ignoredVersions ? ""
, rev-prefix ? "" , rev-prefix ? ""
, odd-unstable ? false , odd-unstable ? false

View File

@ -3,9 +3,9 @@
, common-updater-scripts , common-updater-scripts
}: }:
{ pname { pname ? null
, version , version ? null
, attrPath ? pname , attrPath ? null
, ignoredVersions ? "" , ignoredVersions ? ""
, rev-prefix ? "" , rev-prefix ? ""
, odd-unstable ? false , odd-unstable ? false

View File

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

View File

@ -2,22 +2,24 @@
# lists all available tags from a git repository # lists all available tags from a git repository
echo "# pname=$UPDATE_NIX_ATTR_PATH" > /tmp/test.txt pname="" # package name
attr_path="" # package attribute path
url="" # git repository url url="" # git repository url
pname="" # package name
file="" # file for writing debugging information file="" # file for writing debugging information
while (( $# > 0 )); do while (( $# > 0 )); do
flag="$1" flag="$1"
shift 1 shift 1
case "$flag" in case "$flag" in
--url=*)
url="${flag#*=}"
;;
--pname=*) --pname=*)
pname="${flag#*=}" pname="${flag#*=}"
;; ;;
--attr-path=*)
attr_path="${flag#*=}"
;;
--url=*)
url="${flag#*=}"
;;
--file=*) --file=*)
file="${flag#*=}" file="${flag#*=}"
;; ;;
@ -28,17 +30,21 @@ while (( $# > 0 )); do
esac esac
done done
if [[ -z "$pname" ]]; then
pname="$UPDATE_NIX_NAME"
fi
if [[ -z "$attr_path" ]]; then
attr_path="$UPDATE_NIX_ATTR_PATH"
fi
# By default we set url to src.url or src.meta.homepage # By default we set url to src.url or src.meta.homepage
if [[ -z "$url" ]]; then if [[ -z "$url" ]]; then
url="$(nix-instantiate $systemArg --eval -E \ url="$(nix-instantiate $systemArg --eval -E \
"with import ./. {}; $UPDATE_NIX_ATTR_PATH.src.meta.homepage or $UPDATE_NIX_ATTR_PATH.src.url" \ "with import ./. {}; $attr_path.src.meta.homepage or $attr_path.src.url" \
| tr -d '"')" | tr -d '"')"
fi fi
if [[ -z "$pname" ]]; then
pname="$UPDATE_NIX_ATTR_PATH"
fi
# print a debugging message # print a debugging message
if [[ -n "$file" ]]; then if [[ -n "$file" ]]; then
echo "# Listing tags for '$pname' at $url" >> $file echo "# Listing tags for '$pname' at $url" >> $file