]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/xzipdiff
564fa413e79d211f755c3c00dbf575d6c3562076
[xonotic/xonotic.git] / misc / tools / xzipdiff
1 #!/bin/sh
2
3 set -e
4
5 from=$1
6 to=$2
7 output=$3
8 case "$from" in /*) ;; *) from=`pwd`/$from ;; esac
9 case "$to" in /*) ;; *) to=`pwd`/$to ;; esac
10 case "$output" in /*) ;; *) output=`pwd`/$output ;; esac
11
12 excludes="
13         Xonotic/data/xonotic-*-data.pk3
14         Xonotic/data/xonotic-*-maps.pk3
15         Xonotic/data/xonotic-*-music.pk3
16         Xonotic/data/xonotic-*-nexcompat.pk3
17         Xonotic/data/xonotic-*-data-low.pk3
18         Xonotic/data/xonotic-*-maps-low.pk3
19         Xonotic/data/xonotic-*-music-low.pk3
20         Xonotic/data/font-nimbussansl-*.pk3
21         Xonotic/data/font-xolonium-*.pk3
22 "
23
24 makepatchname()
25 {
26         wildcard=$1
27         fromname=$2
28         toname=$3
29         prefix=${wildcard%%\**}
30         suffix=${wildcard#*\*}
31         fromversion=${fromname#$prefix}
32         fromversion=${fromversion%$suffix}
33         toversion=${toname#$prefix}
34         toversion=${toversion%$suffix}
35         echo "$prefix$fromversion"patch"$toversion$suffix"
36 }
37
38 zipdiff -f "$from" -t "$to" -o "$output" -x "$excludes"
39 # or maybe just include ALL not excluded files from $to in $output?
40
41 tempdir=`mktemp -d -t zipdiff.XXXXXX`
42 cd "$tempdir"
43
44 for x in $excludes; do
45         mkdir a b c
46         (cd a && unzip "$from" "$x")
47         fromname=`find a/ -type f`; fromname=${fromname#a/}
48         (cd b && unzip "$to" "$x")
49         toname=`find b/ -type f`; toname=${toname#b/}
50         patchname=`makepatchname "$x" "$fromname" "$toname"`
51         patchdir="c/$patchname"; patchdir=${patchdir%/*}
52         mkdir -p "$patchdir"
53         zipdiff -f a/"$fromname" -t b/"$toname" -o c/"$patchname"
54         if [ -f c/"$patchname" ]; then
55                 (cd c && zip -0r "$output" "$patchname")
56         fi
57         rm -rf a b c
58 done
59
60 rm -rf "$tempdir"