* updated maddy (0.7.1 -> 0.8.1), untested
[t2sde.git] / scripts / Create-CkSumPatch
bloba7303a303eadb0bfe64a1d58860e35dae43210ee
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Create-CkSumPatch
5 # Copyright (C) 2004 - 2023 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # This Copyright note is generated by scripts/Create-CopyPatch,
9 # more information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 . scripts/functions.in
16 override=0
17 files=''
19 usage() {
20 echo "Usage:"
21 echo "scripts/Create-CkSumPatch [options] <package-name>"
22 echo "scripts/Create-CkSumPatch [options] <target-name>"
23 echo "scripts/Create-CkSumPatch [options] <file-path>"
24 echo " "
25 echo "Options:"
26 echo " -override Create new cksum if old one should be valid."
27 echo " -help This."
30 while [ "$1" ]; do
31 case "$1" in
32 -override) override=1; shift ;;
33 -repository) files="$files `echo package/$2/*/*.desc`"; shift; shift ;;
34 -*|-help) usage; exit ;;
35 *.desc|target/*) files="$files $1"; shift ;;
36 *) files="$files `echo package/*/$1/$1.desc`"; shift ;;
37 esac
38 done
40 # cksum_file path-to-desc-or-target-file
41 cksum_file() {
42 case "$1" in
43 target/*)
44 has_D='cat'
45 sedscript='s,^[^ ]* *$file,$newcksum $file,'
47 *.desc)
48 has_D='fgrep "[D]" | sed "s/[[]D[^ ]*//"'
49 sedscript='s@\[D\] *[^ ]* *$file@[D] $newcksum $file@'
52 echo "!!! File type not recognized" >&2
53 return -1
54 esac
56 if [ ! -f "$1" ]; then
57 echo "!!! File not found: $1" >&2
58 return -1
61 cp $1 /tmp/$$
62 eval "egrep -v '^#' $1 | $has_D" | while read cksum file url args; do
63 [ "$cksum" = 'X' ] && continue
64 [ "$cksum" != '0' -a "$override" = '0' ] && continue
66 gzfile=`source_file cksum $file $url $flags`
67 if [ ! -f "$gzfile" ]; then
68 echo "!!! File not present: $gzfile" >&2
69 continue
72 local ck="sha224"
73 local cksum2=${ck}sum
74 if ! type -p $cksum2 > /dev/null; then
75 cksum2=${cksum2#sha} cksum2=${cksum2%sum}
76 cksum2="shasum -a $cksum2"
79 local compressor="$(get_compressor "$gzfile")"
80 if [ "$compressor" ]; then
81 echo -n "$gzfile (${compressor%% *}): " >&2
82 newcksum="`$compressor < $gzfile | $cksum2 | cut -f1 -d' '`"
83 else
84 echo -n "$gzfile (raw): " >&2
85 newcksum="`$cksum2 $gzfile | cut -f1 -d' '`"
87 newcksum="$newcksum" # also support explict {$ck}
88 echo "$newcksum" >&2
90 if [ "$cksum" != 0 -a "$cksum" != "$newcksum" ]; then
91 echo "!!! Checksum of $file changed (was $cksum)." >&2
94 eval "sed \"$sedscript\" -i /tmp/$$"
95 done
97 diff -u ./$1 /tmp/$$
98 rm -f /tmp/$$
101 echo "Creating cksum.patch ..." >&2
103 for f in $files; do
104 cksum_file $f
105 done