summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2012-04-16 00:39:15 +0200
committerJustin Davis <jrcd83@gmail.com>2012-04-16 00:39:15 +0200
commitf5cff74bb9665b4de3eb7cf16ed0504da0ee599e (patch)
tree115fbc8b7bac9bf1693377992409ba4d800deb12
parent52d178a3bff39f62e6e6607610ad90444779af50 (diff)
downloadgenpkg-f5cff74bb9665b4de3eb7cf16ed0504da0ee599e.tar.gz
genpkg-f5cff74bb9665b4de3eb7cf16ed0504da0ee599e.tar.xz
New injectdigs script.
This takes PKGDATA on standard input printing it to standard output. Digests for each file entry in the source array are printed along with the other PKGDATA fields.
-rwxr-xr-xbin/injectdigs59
-rwxr-xr-xsetup2
2 files changed, 60 insertions, 1 deletions
diff --git a/bin/injectdigs b/bin/injectdigs
new file mode 100755
index 0000000..2414acd
--- /dev/null
+++ b/bin/injectdigs
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+PROG=injectdigs
+
+if [ $# -eq 0 ]
+then
+ digstr="md5 sha512"
+else
+ digstr=$*
+fi
+
+if ! which openssl > /dev/null
+then
+ echo "$PROG: openssl needs to be installed to calculate digests"
+ exit 2
+fi
+
+awk -v digstr="$digstr" -v prog="$PROG" '
+BEGIN {
+ diglen = split(digstr, digalgs)
+ FS = "\n"; RS = ""; ORS = "\n\n"
+}
+
+function calcdigs(alg, files)
+{
+ cmd = "openssl " alg " " files
+ digests = ""
+ while(cmd | getline > 0){
+ digests = digests $2 "\n"
+ }
+ close(cmd)
+ return digests
+}
+
+1
+
+$1 == "source" {
+ for(i = 2; i <= NF; i++){
+ file = $i
+ sub(/.*\//, "", file)
+ if(system("test -f " file) != 0){
+ print prog ": source file " file " is missing!" | "cat 1>&2"
+ exit 1
+ }
+ files = files file " "
+ filelen++
+ }
+}
+
+END {
+ FS = " "; RS = "\n"
+ OFS = ORS = "\n"
+ if(!filelen) exit 0
+ for(i = 1; i <= diglen; i++){
+ alg = digalgs[i]
+ print alg "sums", calcdigs(alg, files)
+ }
+}
+'
diff --git a/setup b/setup
index ef1fad7..7ed11f4 100755
--- a/setup
+++ b/setup
@@ -3,7 +3,7 @@
set -e
umask 022
prog=setup
-binfiles='genpkg mkpkgmeta modpkg pbfields putpkgtree getpkgtree'
+binfiles='genpkg mkpkgmeta modpkg pbfields putpkgtree getpkgtree injectdigs'
metas='perl perl.d/
perl.d/fetchcpan perl.d/perl-dist perl.d/perl-pkgbuild
perl.d/scrapecore'