* updated lskat (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / Create-PkgUpdPatch
blobcf653dd2ce922688f3592188463c1e296b0d6af4
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Create-PkgUpdPatch
5 # Copyright (C) 2004 - 2021 The T2 SDE Project
6 #
7 # This Copyright note is generated by scripts/Create-CopyPatch,
8 # more information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License version 2.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 pkg="$1"; shift
15 ver="$1"; shift
17 if [ -z "$ver" ]; then
18 ver=${pkg/*-/}
19 pkg=${pkg%-$ver}
22 if [ -z "$pkg" -o -z "$ver" ]; then
23 echo "Usage: $0 pkg ver"
24 echo " or: $0 pkg-ver"
25 exit
28 pkg=`echo $pkg | tr A-Z a-z`
30 echo "[ $pkg ]" >&2
31 pkgdir=`echo package/*/$pkg`
33 if [ ! -d "$pkgdir" ]; then
34 echo "Can't find package for '$x'!" >&2
35 else
36 oldver="`egrep "^\[(V|VER|VERSION)\] " $pkgdir/$pkg.desc |
37 sed 's, ,\t,g; s,\t\t*,\t,g' | cut -f2`"
38 tmpfile=`mktemp`; tmpfile2=`mktemp`
39 echo "Update patch for $pkg ($pkgdir): $oldver -> $ver"
41 # [V]
42 expression="-e 's@^\[\(V\|VER\|VERSION\)\].*@[\1] $ver@'"
43 # file at [D]
44 expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s@${oldver//./\\.}@$ver@g;'"
46 # detect download location structure
47 sed -n -e 's,^\[\(D\|DOWN\|DOWNLOAD\)\].*[ \t]\([^ \t]*\)[ \t]*$,\2,p' $pkgdir/$pkg.desc > $tmpfile
49 if grep -q "/$oldver/$" $tmpfile; then
50 # $ver -> /$ver/
51 oldver="${oldver//./\\.}"
52 expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s@/$oldver/[^ \t]*\$@/$ver/@g;'"
53 elif [ "$oldver" != "${oldver//-/}" ] && grep -q "/${oldver//-/}/\$" $tmpfile; then
54 # $ver-$extra -> /$ver/
55 oldver="${oldver%%-*}"; oldver="${oldver//./\\.}"
56 ver="${ver%%-*}"
57 expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s@/$oldver/[^ \t]*\$@/$ver/@g;'"
58 else
59 # $ver.$extra -> /$ver/
60 oldver="${oldver%%-*}"
61 ver="${ver%%-*}"
63 oldauxver=
64 auxver=
65 pattern="[^\.]*"
66 while [ "${oldver#$oldauxver}" ]; do
67 eval $( echo "$oldver $ver" | sed -e "s,\($pattern\).* \($pattern\).*,oldauxver=\1 auxver=\2," )
68 if grep -q "/$oldauxver/\$" $tmpfile; then
69 oldver="${oldauxver%%-*}"; oldauxver="${oldauxver//./\\.}"
70 ver="${auxver%%-*}"
71 expression="$expression -e '/^\[\(D\|DOWN\|DOWNLOAD\)\]/ s@/$oldver/[^ \t]*\$@/$ver/@g;'"
72 break
74 pattern="$pattern\.\?[^\.]*"
75 done
78 # checksum at [D]
79 expression="$expression -e 's,^\[\(D\|DOWN\|DOWNLOAD\)\] [^ ]\+,[\1] 0,'"
81 eval "sed $expression $pkgdir/$pkg.desc" > $tmpfile
82 diff -u ./$pkgdir/$pkg.desc $tmpfile | tee $tmpfile2
83 [ -s $tmpfile2 ] || echo "Patch for '$x' is empty!" >&2
84 rm -f $tmpfile $tmpfile2
86 echo