~ubuntu-branches/ubuntu/precise/libisoburn/precise

« back to all changes in this revision

Viewing changes to releng/jigdo-gen-md5-list

  • Committer: Package Import Robot
  • Author(s): George Danchev
  • Date: 2011-10-02 09:37:34 UTC
  • mfrom: (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20111002093734-auibchjeaecfhofu
Tags: 1.1.6-2
Fix funny typo in xorriso binary package description.
Thanks to Davide Prina (Closes: #643993).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
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.
 
7
 
 
8
# Create a list of MD5sums encoded in hexidecimal format and print to standard output
 
9
 
 
10
# Format Description
 
11
# A line in the emerging file is to be composed as follows:
 
12
#
 
13
# The MD5 checksum of the file content must be encoded in 32 hex digits
 
14
# [0-9afAF]
 
15
#
 
16
# Next come two blanks.
 
17
#
 
18
# The byte size of the file content must be encoded in 12 decimal digits
 
19
# or blanks.
 
20
#
 
21
# Next come two blanks.
 
22
#
 
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.
 
26
 
 
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:".
 
38
 
 
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.
 
43
 
 
44
set -e
 
45
 
 
46
SELF=jigdo-gen-md5-list
 
47
VER=0.2
 
48
 
 
49
OPT_ABSOLUTE=1
 
50
 
 
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 
 
56
then
 
57
        md5_cmd=md5sum
 
58
elif ( md5 -s test ) >/dev/null 2>&1
 
59
then
 
60
        md5_cmd=md5
 
61
else
 
62
        echo "$0 : Programs md5sum and md5 failed to work" >&2
 
63
        exit 2
 
64
fi
 
65
 
 
66
usage() {
 
67
        cat << USAGE
 
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
 
72
 -h, --help             print help
 
73
 -e, --examples         print examples
 
74
USAGE
 
75
}
 
76
 
 
77
examples() {
 
78
        cat << EXAMPLES
 
79
examples:
 
80
 $SELF datadir datafile
 
81
 $SELF --keep-literal datadir datafile
 
82
 find . -type f | xargs $SELF
 
83
 find . -exec $SELF '{}' ';'
 
84
EXAMPLES
 
85
}
 
86
 
 
87
md5list() {
 
88
        item="$1"
 
89
        if test $OPT_ABSOLUTE -eq 1; then
 
90
                dn=`dirname "$item"`  # dirname
 
91
                fn=`basename "$item"` # filename
 
92
                od=`pwd -P`           # old dir
 
93
                cd "$dn" || exit 1
 
94
                item=`pwd -P`/"$fn"   # absolute physical file path, avoiding all symlinks
 
95
                cd "$od" || exit 1
 
96
        fi
 
97
        if test "$md5_cmd" = "md5sum"
 
98
        then
 
99
                MD5=`md5sum "$item" | awk '{print $1}'`
 
100
        elif test "$md5_cmd" = "md5"
 
101
        then
 
102
                MD5=`md5 -q "$item"`
 
103
        else
 
104
                echo "$0 : No MD5 program found" >&2
 
105
                exit 2
 
106
        fi
 
107
        SIZ=`ls -ld "$item" | awk '{print $5}'`
 
108
        printf '%32s  %12s  %s\n' "$MD5" "$SIZ" "$item"
 
109
}
 
110
 
 
111
walkdir() {
 
112
        DR="$1"
 
113
        for item in `find "$DR" -type f`
 
114
        do
 
115
                md5list "$item"
 
116
        done
 
117
}
 
118
 
 
119
 
 
120
# main()
 
121
if test "$1" = "" ; then
 
122
        usage
 
123
        exit 1
 
124
fi
 
125
 
 
126
case "$1" in
 
127
        --make-absolute|-a)
 
128
                OPT_ABSOLUTE=1;
 
129
                shift;
 
130
                ;;
 
131
        --keep-literal|-l)
 
132
                OPT_ABSOLUTE=0;
 
133
                shift;
 
134
                ;;
 
135
        --version|-v)
 
136
                printf '%s %s\n' "$SELF" "$VER"
 
137
                exit 0
 
138
                ;;
 
139
        --help|-h)
 
140
                usage
 
141
                exit 0
 
142
                ;;
 
143
        --examples|-e)
 
144
                examples
 
145
                exit 0
 
146
#       *)
 
147
#               usage
 
148
#               exit 1
 
149
#               ;;
 
150
esac
 
151
 
 
152
for i in "$@"
 
153
do
 
154
 
 
155
        if test -d "$i" ; then
 
156
                DR="$i"
 
157
                if test $OPT_ABSOLUTE -eq 1; then
 
158
                        od=`pwd -P`           # old dir
 
159
                        cd "$DR" || exit 1
 
160
                        DR=`pwd -P`           # absolute physical dir path, avoiding all symlinks
 
161
                        cd "$od" || exit 1
 
162
                fi
 
163
                walkdir "$DR"
 
164
        elif test -f "$i" ; then
 
165
                FL="$i"
 
166
                md5list "$FL"
 
167
        else
 
168
                usage
 
169
                exit 1
 
170
        fi;
 
171
 
 
172
done
 
173
 
 
174
exit 0
 
175