about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn <johnz@posteo.net>2018-03-04 13:50:23 +0100
committerLeah Neukirchen <leah@vuxu.org>2018-05-01 17:19:48 +0200
commit30de6ac857a3e1bb6f1f2e6c876629cd27b6993b (patch)
tree524fdf46d36afad9abe20198fe9c644da14da40a
parent570ae507196bf615c8f9d05bbb3bd53cf674c874 (diff)
downloadxtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.tar.gz
xtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.tar.xz
xtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.zip
xgensum: add -c switch for generating content checksums
Closes: #90 [via git-merge-pr]
-rw-r--r--README3
-rw-r--r--_xtools1
-rwxr-xr-xxgensum59
-rw-r--r--xtools.13
4 files changed, 63 insertions, 3 deletions
diff --git a/README b/README
index b0ab8ba..1af3e16 100644
--- a/README
+++ b/README
@@ -35,8 +35,9 @@ COMMANDS
 
      xetcchanges – show diff of /etc against binary packages
 
-     xgensum [-f] [-i] template – update SHA256 sum in templates
+     xgensum [-f] [-c] [-i] template – update SHA256 sum in templates
        -f  force (re-)download of distfiles
+       -c  use content checksum
        -i  replace checksum in-place
 
      xgrep pattern pkgs ... – search files limited to XBPS package contents
diff --git a/_xtools b/_xtools
index ce3ba4b..17c1f7a 100644
--- a/_xtools
+++ b/_xtools
@@ -48,6 +48,7 @@ _xdowngrade() {
 _xgensum() {
 	_arguments : \
 		'-f[force downloading of files]' \
+		'-c[use content checksum]' \
 		'-i[substitute in-place]' \
 		':available templates:_path_files -g "*(/)|template(N)"'
 }
diff --git a/xgensum b/xgensum
index 2b24bf1..f31fbd2 100755
--- a/xgensum
+++ b/xgensum
@@ -6,6 +6,10 @@ case "$1" in
 esac
 
 case "$1" in
+	-c) FLAG_c=$1; shift
+esac
+
+case "$1" in
 	-i*) FLAG_i=$1; shift
 esac
 
@@ -14,7 +18,7 @@ if [ -f "$1" ]; then
 elif [ -f "$1/template" ]; then
 	template="$1/template"
 else
-	echo 'Usage: xgensum [-f] [-i] TEMPLATE' 1>&2
+	echo 'Usage: xgensum [-f] [-c] [-i] TEMPLATE' 1>&2
 	exit 1
 fi
 
@@ -39,7 +43,58 @@ sums=""
 for f in $distfiles; do
 	curfile=$(basename "${f#*>}")
 	distfile="$srcdir/$curfile"
-	sum=$(sha256sum $distfile)
+	if [ "$FLAG_c" = -c ];then
+		sum="@"
+		case ${distfile} in
+		*tar.lzma|*.tar|*.txz|*.tar.xz|*.tbz|*.tar.gz)
+			sum+=$(tar xf "$distfile" --to-stdout | sha256sum | awk '{print $1}')
+			;;
+		*.gz)
+			sum+=$(gunzip -c "$distfile" | sha256sum | awk '{print $1}')
+			;;
+		*.tar.bz2|*.bz2)
+			sum+=$(bunzip2 -c "$distfile" | sha256sum | awk '{print $1}')
+			;;
+		*.zip)
+			if command -v unzip &>/dev/null; then
+				sum+=$(unzip -p "$distfile" | sha256sum | awk '{print $1}')
+				if [ $? -ne 0 ]; then
+					echo "$pkgver: extracting $curfile to pipe.\n"
+				fi
+			else
+				echo "$pkgver: cannot find unzip bin for extraction.\n"
+			fi
+			;;
+		*.rpm)
+			if command -v rpmextract &>/dev/null; then
+				sum+=$(rpm2cpio "$distfile" | bsdtar xf - --to-stdout | sha256sum | awk '{print $1}')
+				if [ $? -ne 0 ]; then
+					echo "$pkgver: extracting $curfile to pipe.\n"
+				fi
+			else
+				echo "$pkgver: cannot find rpmextract for extraction.\n"
+			fi
+			;;
+		*.7z)
+			if command -v 7z &>/dev/null; then
+				sum+=$(7z x -o "$distfile" | sha256sum | awk '{print $1}')
+				if [ $? -ne 0 ]; then
+					echo "$pkgver: extracting $curfile to pipe.\n"
+				fi
+			else
+				echo "$pkgver: cannot find 7z bin for extraction.\n"
+			fi
+			;;
+		*.txt|*.patch|*.diff)
+			sum+=$(cat "$distfile" | sha256sum | awk '{print $1}')
+			;;
+		*)
+			sum=$(sha256sum $distfile)
+
+		esac
+	else
+		sum=$(sha256sum $distfile)
+	fi
 	sums+="${sum%  *}\n "
 done
 
diff --git a/xtools.1 b/xtools.1
index ac0c2ca..e3570b1 100644
--- a/xtools.1
+++ b/xtools.1
@@ -72,12 +72,15 @@ print unified diffs
 .Pp
 .Nm xgensum
 .Op Fl f
+.Op Fl c
 .Op Fl i
 .Ar template
 .Nd update SHA256 sum in templates
 .Bl -tag -offset 2n -width 2n -compact
 .It Fl f
 force (re-)download of distfiles
+.It Fl c
+use content checksum
 .It Fl i
 replace checksum in-place
 .El