diff options
author | John <johnz@posteo.net> | 2018-03-04 13:50:23 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-05-01 17:19:48 +0200 |
commit | 30de6ac857a3e1bb6f1f2e6c876629cd27b6993b (patch) | |
tree | 524fdf46d36afad9abe20198fe9c644da14da40a /xgensum | |
parent | 570ae507196bf615c8f9d05bbb3bd53cf674c874 (diff) | |
download | xtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.tar.gz xtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.tar.xz xtools-30de6ac857a3e1bb6f1f2e6c876629cd27b6993b.zip |
xgensum: add -c switch for generating content checksums
Closes: #90 [via git-merge-pr]
Diffstat (limited to 'xgensum')
-rwxr-xr-x | xgensum | 59 |
1 files changed, 57 insertions, 2 deletions
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 |