]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/xzipdiff
add a comment
[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         Xonotic/data/font-nimbussansl-*.pk3
19         Xonotic/data/font-xolonium-*.pk3
20 "
21
22 makepatchname()
23 {
24         wildcard=$1
25         fromname=$2
26         toname=$3
27         prefix=${wildcard%%\**}
28         suffix=${wildcard#*\*}
29         fromversion=${fromname#$prefix}
30         fromversion=${fromversion%$suffix}
31         toversion=${toname#$prefix}
32         toversion=${toversion%$suffix}
33         echo "$prefix$fromversion"patch"$toversion$suffix"
34 }
35
36 zipdiff -f "$from" -t "$to" -o "$output" -x "$excludes"
37 # or maybe just include ALL not excluded files from $to in $output?
38
39 tempdir=`mktemp -d -t zipdiff.XXXXXX`
40 cd "$tempdir"
41
42 for x in $excludes; do
43         mkdir a b c
44         (cd a && unzip "$from" "$x")
45         fromname=`find a/ -type f`; fromname=${fromname#a/}
46         (cd b && unzip "$to" "$x")
47         toname=`find b/ -type f`; toname=${toname#b/}
48         patchname=`makepatchname "$x" "$fromname" "$toname"`
49         patchdir="c/$patchname"; patchdir=${patchdir%/*}
50         mkdir -p "$patchdir"
51         zipdiff -f a/"$fromname" -t b/"$toname" -o c/"$patchname"
52         if [ -f c/"$patchname" ]; then
53                 (cd c && zip -0r "$output" "$patchname")
54         fi
55         rm -rf a b c
56 done
57
58 rm -rf "$tempdir"