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