|
|
|
@ -1,16 +1,18 @@
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Copyright (c) 2010, 2011 George Danchev <danchev@spnet.net>
|
|
|
|
|
# Copyright (c) 2010, 2011 Thomas Schmitt <scdbackup@gmx.net>
|
|
|
|
|
# Copyright (c) 2010, 2011, 2019 Thomas Schmitt <scdbackup@gmx.net>
|
|
|
|
|
# This script is distributed according to the terms of the GNU GPL v2.
|
|
|
|
|
# This should be better rewritten in C at some future point. Ref: pwd code.
|
|
|
|
|
|
|
|
|
|
# Create a list of MD5sums encoded in hexadecimal format and print to standard output
|
|
|
|
|
# Create a list of checksums encoded in hexadecimal format and print to
|
|
|
|
|
# standard output. Checksum may be MD5 or SHA256.
|
|
|
|
|
|
|
|
|
|
# Format Description
|
|
|
|
|
# A line in the emerging file is to be composed as follows:
|
|
|
|
|
#
|
|
|
|
|
# The MD5 checksum of the file content must be encoded in 32 hex digits
|
|
|
|
|
# The checksum of the file content must be encoded in the aprropriate number
|
|
|
|
|
# of hex digits.
|
|
|
|
|
# [0-9afAF]
|
|
|
|
|
#
|
|
|
|
|
# Next come two blanks.
|
|
|
|
@ -37,35 +39,61 @@
|
|
|
|
|
# text, like "Debian:".
|
|
|
|
|
|
|
|
|
|
# A simple strategy to cope with this is to write absolute paths into the
|
|
|
|
|
# .md5 file, and to use matching absolute paths in the -jigdo-map
|
|
|
|
|
# checksum file, and to use matching absolute paths in the -jigdo-map
|
|
|
|
|
# directives. Keep in mind that mapping is purely literal. Symbolic links
|
|
|
|
|
# are neither resolved nor can they confuse the mapping.
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
SELF=jigdo-gen-md5-list
|
|
|
|
|
VER=0.2
|
|
|
|
|
VER=0.3
|
|
|
|
|
|
|
|
|
|
OPT_ABSOLUTE=1
|
|
|
|
|
|
|
|
|
|
# The checksum type to produce: md5 , sha256
|
|
|
|
|
checksum_type=md5
|
|
|
|
|
hex_length=32
|
|
|
|
|
md5_cmd=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# On FreeBSD there is "md5" rather than "md5sum".
|
|
|
|
|
# Furthermore, the FreeBSD shell reports missing commands to inherited stderr,
|
|
|
|
|
# regardless that the attempt itself has redirected stderr. Thus a sub shell
|
|
|
|
|
# is needed to hide the protest.
|
|
|
|
|
if ( md5sum --help ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=md5sum
|
|
|
|
|
elif ( md5 -s test ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=md5
|
|
|
|
|
else
|
|
|
|
|
echo "$0 : Programs md5sum and md5 failed to work" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
choose_checksum_cmd() {
|
|
|
|
|
if test "$checksum_type" = "md5"
|
|
|
|
|
then
|
|
|
|
|
if ( md5sum --help ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=md5sum
|
|
|
|
|
elif ( md5 -s test ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=md5
|
|
|
|
|
else
|
|
|
|
|
echo "$0 : Programs md5sum and md5 failed to work" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
elif test "$checksum_type" = "sha256"
|
|
|
|
|
then
|
|
|
|
|
if ( sha256sum --help ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=sha256sum
|
|
|
|
|
elif ( sha256 -s test ) >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
md5_cmd=sha256
|
|
|
|
|
else
|
|
|
|
|
echo "$0 : Programs sha256sum and sha256 failed to work" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
|
cat << USAGE
|
|
|
|
|
usage: $SELF [option] DIR FILE ...
|
|
|
|
|
Print a Jigdo checksum file to stdout. One line per FILE and per file in DIR.
|
|
|
|
|
-m, --md5 produce MD5 checksums (default)
|
|
|
|
|
-s, --sha256 produce SHA256 checksums
|
|
|
|
|
-a, --make-absolute make absolute paths, avoiding any symlinks (default)
|
|
|
|
|
-l, --keep-literal leave paths untouched, literally as supplied
|
|
|
|
|
-v, --version print version
|
|
|
|
@ -100,12 +128,18 @@ md5list() {
|
|
|
|
|
elif test "$md5_cmd" = "md5"
|
|
|
|
|
then
|
|
|
|
|
MD5=`md5 -q "$item"`
|
|
|
|
|
elif test "$md5_cmd" = "sha256sum"
|
|
|
|
|
then
|
|
|
|
|
MD5=`sha256sum "$item" | awk '{print $1}'`
|
|
|
|
|
elif test "$md5_cmd" = "sha256"
|
|
|
|
|
then
|
|
|
|
|
MD5=`sha256 -q "$item"`
|
|
|
|
|
else
|
|
|
|
|
echo "$0 : No MD5 program found" >&2
|
|
|
|
|
echo "$0 : Internal error : Checksum mode unknown : $md5_cmd" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
SIZ=`ls -ld "$item" | awk '{print $5}'`
|
|
|
|
|
printf '%32s %12s %s\n' "$MD5" "$SIZ" "$item"
|
|
|
|
|
printf '%'"$hex_length"'s %12s %s\n' "$MD5" "$SIZ" "$item"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
walkdir() {
|
|
|
|
@ -123,7 +157,17 @@ if test "$1" = "" ; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
for i in "$@"
|
|
|
|
|
do
|
|
|
|
|
case "$i" in
|
|
|
|
|
--md5|-m)
|
|
|
|
|
checksum_type=md5
|
|
|
|
|
hex_length=32
|
|
|
|
|
;;
|
|
|
|
|
--sha256|-s)
|
|
|
|
|
checksum_type=sha256
|
|
|
|
|
hex_length=64
|
|
|
|
|
;;
|
|
|
|
|
--make-absolute|-a)
|
|
|
|
|
OPT_ABSOLUTE=1;
|
|
|
|
|
shift;
|
|
|
|
@ -147,12 +191,15 @@ case "$1" in
|
|
|
|
|
# usage
|
|
|
|
|
# exit 1
|
|
|
|
|
# ;;
|
|
|
|
|
esac
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
choose_checksum_cmd
|
|
|
|
|
|
|
|
|
|
for i in "$@"
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
if test -d "$i" ; then
|
|
|
|
|
if echo "$i" | grep '^-' >/dev/null ; then
|
|
|
|
|
dummy=dummy
|
|
|
|
|
elif test -d "$i" ; then
|
|
|
|
|
DR="$i"
|
|
|
|
|
if test $OPT_ABSOLUTE -eq 1; then
|
|
|
|
|
od=`pwd -P` # old dir
|
|
|
|
|