3
# Copyright (c) 2010, 2011 George Danchev <danchev@spnet.net>
4
# Copyright (c) 2010, 2011 Thomas Schmitt <scdbackup@gmx.net>
5
# This script is distributed according to the terms of the GNU GPL v2.
6
# This should be better rewritten in C at some future point. Ref: pwd code.
8
# Create a list of MD5sums encoded in hexidecimal format and print to standard output
11
# A line in the emerging file is to be composed as follows:
13
# The MD5 checksum of the file content must be encoded in 32 hex digits
16
# Next come two blanks.
18
# The byte size of the file content must be encoded in 12 decimal digits
21
# Next come two blanks.
23
# The rest of the line up to the newline character is a semi-literal file
24
# address. Its basename has to be the same as the basename of the data file
25
# when it is used as one of the input files for the jigdo file generator.
27
# The semi-literal address and the address mapping define what will be
28
# listed as file address in the jigdo file.
29
# The address may bear at its start a literal text that shall be recognized by
30
# the address mapping (e.g. -jigdo-map) of the jigdo file generator.
31
# The rest of the address must be usable as file address in both situations:
32
# When the jigdo file gets generated, and when the jigdo file gets read
33
# to inflate the template file into the original payload image.
34
# The address mappings at both occasions can be used to adapt to a change
35
# of the absolute location of the listed files.
36
# Between both mappings, the parent directory is represented by a symbolic
37
# text, like "Debian:".
39
# A simple strategy to cope with this is to write absolute paths into the
40
# .md5 file, and to use matching absolute paths in the -jigdo-map
41
# directives. Keep in mind that mapping is purely literal. Symbolic links
42
# are neither resolved nor can they confuse the mapping.
46
SELF=jigdo-gen-md5-list
51
# On FreeBSD there is "md5" rather than "md5sum".
52
# Furthermore, the FreeBSD shell reports missing commands to inherited stderr,
53
# regardless that the attempt itself has redirected stderr. Thus a sub shell
54
# is needed to hide the protest.
55
if ( md5sum --help ) >/dev/null 2>&1
58
elif ( md5 -s test ) >/dev/null 2>&1
62
echo "$0 : Programs md5sum and md5 failed to work" >&2
68
usage: $SELF [option] DIR FILE ...
69
-a, --make-absolute make absolute paths, avoiding any symlinks (default)
70
-l, --keep-literal leave paths untouched, literally as supplied
71
-v, --version print version
73
-e, --examples print examples
80
$SELF datadir datafile
81
$SELF --keep-literal datadir datafile
82
find . -type f | xargs $SELF
83
find . -exec $SELF '{}' ';'
89
if test $OPT_ABSOLUTE -eq 1; then
90
dn=`dirname "$item"` # dirname
91
fn=`basename "$item"` # filename
94
item=`pwd -P`/"$fn" # absolute physical file path, avoiding all symlinks
97
if test "$md5_cmd" = "md5sum"
99
MD5=`md5sum "$item" | awk '{print $1}'`
100
elif test "$md5_cmd" = "md5"
104
echo "$0 : No MD5 program found" >&2
107
SIZ=`ls -ld "$item" | awk '{print $5}'`
108
printf '%32s %12s %s\n' "$MD5" "$SIZ" "$item"
113
for item in `find "$DR" -type f`
121
if test "$1" = "" ; then
136
printf '%s %s\n' "$SELF" "$VER"
155
if test -d "$i" ; then
157
if test $OPT_ABSOLUTE -eq 1; then
158
od=`pwd -P` # old dir
160
DR=`pwd -P` # absolute physical dir path, avoiding all symlinks
164
elif test -f "$i" ; then