summaryrefslogtreecommitdiffstats
path: root/bin/mkpkgdata
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mkpkgdata')
-rwxr-xr-xbin/mkpkgdata86
1 files changed, 86 insertions, 0 deletions
diff --git a/bin/mkpkgdata b/bin/mkpkgdata
new file mode 100755
index 0000000..ced31db
--- /dev/null
+++ b/bin/mkpkgdata
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+prog=mkpkgdata
+
+lazysource()
+{
+ awk -v prog="$prog" '
+BEGIN { FS = "\n"; RS = ""; OFS = ORS = "\n\n" }
+$1 == "pkgver" { ver = $2 }
+$1 == "source" {
+ len = NF - 1
+ for(i = 2; i <= NF; i++) sources[i - 1] = $i
+ next
+}
+1 # print everything but sources
+
+END {
+ # remember that metas emit no output when they cant match
+ # a package.
+ if(NR == 0 || !ver) exit 2
+
+ ORS="\n"
+
+ # Replace any version strings in the source file with ${pkgver}.
+ gsub(/[.]/, "\\\\&", ver)
+
+ print "source"
+ for(i = 1; i <= len; i++){
+ gsub(ver, "${pkgver}", sources[i])
+ print sources[i]
+ }
+ print ""
+}'
+ return $?
+} # end of lazysource()
+
+basicmeta()
+{
+ printf "pkgname\n%s\n\n" "$1"
+ printf "pkgrel\n%d\n\n" "${PKGREL:-1}"
+ printf "packager\n%s\n\n" "${PACKAGER:-Anonymous}"
+
+ if [ "$MAINTAINER" ]
+ then
+ printf "maintainer\n%s\n\n" "$MAINTAINER"
+ fi
+}
+
+case $# in
+0) echo "usage: $prog [package name]" 1>&2
+ exit 1
+esac
+
+case "$METABIN" in
+'') echo "$prog: set METABIN before calling $prog" 1>&2
+ exit 1
+esac
+
+tmp="/tmp/$prog.$$"
+for flav in "$METABIN"/*
+do
+ [ -f "$flav" -a -x "$flav" ] || continue
+ PATH="$PATH:$flav.d" "$flav" "$1" > "$tmp"
+ trap 'rm "$tmp"' 1 2 15
+ metaret=$?
+ if [ "$metaret" -eq 0 ]
+ then
+ basicmeta "$1"
+ lazysource < "$tmp"
+ rm "$tmp"
+ exit 0
+ fi
+
+ rm "$tmp"
+ trap '' 1 2 5
+ case $metaret in
+ 1) echo "$prog: $flav encountered an error" 1>&2
+ exit 1 ;;
+ 2) ;; # loop
+ *) echo "$prog: $flav returned error code $metaret" 1>&2
+ exit 1 ;;
+ esac
+done
+
+echo "$prog: no matching meta generator found for '$1'" 1>&2
+exit 1