"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.4/littleutils/filehash_clone.sh" (28 Mar 2021, 3424 Bytes) of package /linux/privat/littleutils-1.2.4.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "filehash_clone.sh": 1.2.3_vs_1.2.4.

    1 #! /bin/bash
    2 # vim: set filetype=bash:
    3 
    4 # filehash_clone.sh: Print various hash digests and filesizes for the specified
    5 # files or subsets of those files (just like filehash)
    6 
    7 # Copyright (C) 2020-2021 by Brian Lindholm.  This file is part of the
    8 # littleutils utility set.
    9 #
   10 # The repeats utility is free software; you can redistribute it and/or modify
   11 # it under the terms of the GNU General Public License as published by the Free
   12 # Software Foundation; either version 3, or (at your option) any later version.
   13 #
   14 # The repeats utility is distributed in the hope that it will be useful, but
   15 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   17 # more details.
   18 #
   19 # You should have received a copy of the GNU General Public License along with
   20 # the littleutils.  If not, see <https://www.gnu.org/licenses/>.
   21 
   22 # get command-line options
   23 MD5='n'
   24 SHA1='n'
   25 SHA224='n'
   26 SHA256='n'
   27 SHA384='n'
   28 SHA512='n'
   29 B2_256='n'
   30 B2_512='n'
   31 COUNT=''
   32 SKIP=''
   33 while getopts 12345678chn:o: opts
   34 do
   35   case $opts in
   36     1) MD5='y' ;;
   37     2) SHA1='y' ;;
   38     3) SHA224='y' ;;
   39     4) SHA256='y' ;;
   40     5) SHA384='y' ;;
   41     6) SHA512='y' ;;
   42     7) B2_256='y' ;;
   43     8) B2_512='y' ;;
   44     h) echo 'filehash LU_VERSION'
   45        echo 'usage: filehash [-1(MD5)] [-2(SHA1)] [-3(SHA224)] [-4(SHA256)]'
   46        echo '         [-5(SHA384)] [-6(SHA512)] [-7(BLAKE2B_256)] [-8(BLAKE2B_256)]'
   47        echo '         [-h(elp)] [-n byte_count] [-o byte_offset] file...'
   48        exit 0 ;;
   49     n) COUNT="count=$OPTARG" ;;
   50     o) SKIP="skip=$OPTARG" ;;
   51     *) echo 'filehash LU_VERSION'
   52        echo 'usage: filehash [-1(MD5)] [-2(SHA1)] [-3(SHA224)] [-4(SHA256)]'
   53        echo '         [-5(SHA384)] [-6(SHA512)] [-7(BLAKE2B_256)] [-8(BLAKE2B_256)]'
   54        echo '         [-h(elp)] [-n byte_count] [-o byte_offset] file...'
   55        exit 1 ;;
   56   esac
   57 done
   58 shift $((${OPTIND}-1))
   59 
   60 # compute hashes as requested
   61 if [ "X$COUNT" = 'X' -a "X$SKIP" = 'X' ]; then
   62   for IDX in "$@" ; do
   63     if [ "$MD5" = 'y' ]; then md5sum "$IDX" ; fi
   64     if [ "$SHA1" = 'y' ]; then sha1sum "$IDX" ; fi
   65     if [ "$SHA224" = 'y' ]; then sha224sum "$IDX" ; fi
   66     if [ "$SHA256" = 'y' ]; then sha256sum "$IDX" ; fi
   67     if [ "$SHA384" = 'y' ]; then sha384sum "$IDX" ; fi
   68     if [ "$SHA512" = 'y' ]; then sha512sum "$IDX" ; fi
   69     if [ "$B2_256" = 'y' ]; then b2sum -l 256 "$IDX" ; fi
   70     if [ "$B2_512" = 'y' ]; then b2sum -l 512 "$IDX" ; fi
   71   done
   72 else
   73   for IDX in "$@" ; do
   74     if [ "$MD5" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | md5sum | sed -e "s/-$/$IDX/" ; fi
   75     if [ "$SHA1" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | sha1sum | sed -e "s/-$/$IDX/" ; fi
   76     if [ "$SHA224" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | sha224sum | sed -e "s/-$/$IDX/" ; fi
   77     if [ "$SHA256" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | sha256sum | sed -e "s/-$/$IDX/" ; fi
   78     if [ "$SHA384" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | sha384sum | sed -e "s/-$/$IDX/" ; fi
   79     if [ "$SHA512" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | sha512sum | sed -e "s/-$/$IDX/" ; fi
   80     if [ "$B2_256" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | b2sum -l 256 | sed -e "s/-$/$IDX/" ; fi
   81     if [ "$B2_512" = 'y' ]; then dd status=none if="$IDX" bs=1 $COUNT $SKIP | b2sum -l 512 | sed -e "s/-$/$IDX/" ; fi
   82   done
   83 fi