"Fossies" - the Fresh Open Source Software Archive 
Member "libisoburn-1.5.4/releng/jigdo-gen-md5-list" (8 Jul 2020, 5343 Bytes) of package /linux/misc/libisoburn-1.5.4.tar.gz:
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.
1 #!/bin/sh
2
3 # Copyright (c) 2010, 2011 George Danchev <danchev@spnet.net>
4 # Copyright (c) 2010, 2011, 2019 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 checksums encoded in hexadecimal format and print to
9 # standard output. Checksum may be MD5 or SHA256.
10
11 # Format Description
12 # A line in the emerging file is to be composed as follows:
13 #
14 # The checksum of the file content must be encoded in the aprropriate number
15 # of hex digits.
16 # [0-9afAF]
17 #
18 # Next come two blanks.
19 #
20 # The byte size of the file content must be encoded in 12 decimal digits
21 # or blanks.
22 #
23 # Next come two blanks.
24 #
25 # The rest of the line up to the newline character is a semi-literal file
26 # address. Its basename has to be the same as the basename of the data file
27 # when it is used as one of the input files for the jigdo file generator.
28
29 # The semi-literal address and the address mapping define what will be
30 # listed as file address in the jigdo file.
31 # The address may bear at its start a literal text that shall be recognized by
32 # the address mapping (e.g. -jigdo-map) of the jigdo file generator.
33 # The rest of the address must be usable as file address in both situations:
34 # When the jigdo file gets generated, and when the jigdo file gets read
35 # to inflate the template file into the original payload image.
36 # The address mappings at both occasions can be used to adapt to a change
37 # of the absolute location of the listed files.
38 # Between both mappings, the parent directory is represented by a symbolic
39 # text, like "Debian:".
40
41 # A simple strategy to cope with this is to write absolute paths into the
42 # checksum file, and to use matching absolute paths in the -jigdo-map
43 # directives. Keep in mind that mapping is purely literal. Symbolic links
44 # are neither resolved nor can they confuse the mapping.
45
46 set -e
47
48 SELF=jigdo-gen-md5-list
49 VER=0.3
50
51 OPT_ABSOLUTE=1
52
53 # The checksum type to produce: md5 , sha256
54 checksum_type=md5
55 hex_length=32
56 md5_cmd=
57
58
59 # On FreeBSD there is "md5" rather than "md5sum".
60 # Furthermore, the FreeBSD shell reports missing commands to inherited stderr,
61 # regardless that the attempt itself has redirected stderr. Thus a sub shell
62 # is needed to hide the protest.
63 choose_checksum_cmd() {
64 if test "$checksum_type" = "md5"
65 then
66 if ( md5sum --help ) >/dev/null 2>&1
67 then
68 md5_cmd=md5sum
69 elif ( md5 -s test ) >/dev/null 2>&1
70 then
71 md5_cmd=md5
72 else
73 echo "$0 : Programs md5sum and md5 failed to work" >&2
74 exit 2
75 fi
76 elif test "$checksum_type" = "sha256"
77 then
78 if ( sha256sum --help ) >/dev/null 2>&1
79 then
80 md5_cmd=sha256sum
81 elif ( sha256 -s test ) >/dev/null 2>&1
82 then
83 md5_cmd=sha256
84 else
85 echo "$0 : Programs sha256sum and sha256 failed to work" >&2
86 exit 2
87 fi
88 fi
89 }
90
91 usage() {
92 cat << USAGE
93 usage: $SELF [option] DIR FILE ...
94 Print a Jigdo checksum file to stdout. One line per FILE and per file in DIR.
95 -m, --md5 produce MD5 checksums (default)
96 -s, --sha256 produce SHA256 checksums
97 -a, --make-absolute make absolute paths, avoiding any symlinks (default)
98 -l, --keep-literal leave paths untouched, literally as supplied
99 -v, --version print version
100 -h, --help print help
101 -e, --examples print examples
102 USAGE
103 }
104
105 examples() {
106 cat << EXAMPLES
107 examples:
108 $SELF datadir datafile
109 $SELF --keep-literal datadir datafile
110 find . -type f | xargs $SELF
111 find . -exec $SELF '{}' ';'
112 EXAMPLES
113 }
114
115 md5list() {
116 item="$1"
117 if test $OPT_ABSOLUTE -eq 1; then
118 dn=`dirname "$item"` # dirname
119 fn=`basename "$item"` # filename
120 od=`pwd -P` # old dir
121 cd "$dn" || exit 1
122 item=`pwd -P`/"$fn" # absolute physical file path, avoiding all symlinks
123 cd "$od" || exit 1
124 fi
125 if test "$md5_cmd" = "md5sum"
126 then
127 MD5=`md5sum "$item" | awk '{print $1}'`
128 elif test "$md5_cmd" = "md5"
129 then
130 MD5=`md5 -q "$item"`
131 elif test "$md5_cmd" = "sha256sum"
132 then
133 MD5=`sha256sum "$item" | awk '{print $1}'`
134 elif test "$md5_cmd" = "sha256"
135 then
136 MD5=`sha256 -q "$item"`
137 else
138 echo "$0 : Internal error : Checksum mode unknown : $md5_cmd" >&2
139 exit 2
140 fi
141 SIZ=`ls -ld "$item" | awk '{print $5}'`
142 printf '%'"$hex_length"'s %12s %s\n' "$MD5" "$SIZ" "$item"
143 }
144
145 walkdir() {
146 DR="$1"
147 for item in `find "$DR" -type f`
148 do
149 md5list "$item"
150 done
151 }
152
153
154 # main()
155 if test "$1" = "" ; then
156 usage
157 exit 1
158 fi
159
160 for i in "$@"
161 do
162 case "$i" in
163 --md5|-m)
164 checksum_type=md5
165 hex_length=32
166 ;;
167 --sha256|-s)
168 checksum_type=sha256
169 hex_length=64
170 ;;
171 --make-absolute|-a)
172 OPT_ABSOLUTE=1;
173 shift;
174 ;;
175 --keep-literal|-l)
176 OPT_ABSOLUTE=0;
177 shift;
178 ;;
179 --version|-v)
180 printf '%s %s\n' "$SELF" "$VER"
181 exit 0
182 ;;
183 --help|-h)
184 usage
185 exit 0
186 ;;
187 --examples|-e)
188 examples
189 exit 0
190 # *)
191 # usage
192 # exit 1
193 # ;;
194 esac
195 done
196 choose_checksum_cmd
197
198 for i in "$@"
199 do
200 if echo "$i" | grep '^-' >/dev/null ; then
201 dummy=dummy
202 elif test -d "$i" ; then
203 DR="$i"
204 if test $OPT_ABSOLUTE -eq 1; then
205 od=`pwd -P` # old dir
206 cd "$DR" || exit 1
207 DR=`pwd -P` # absolute physical dir path, avoiding all symlinks
208 cd "$od" || exit 1
209 fi
210 walkdir "$DR"
211 elif test -f "$i" ; then
212 FL="$i"
213 md5list "$FL"
214 else
215 usage
216 exit 1
217 fi;
218
219 done
220
221 exit 0
222