summaryrefslogtreecommitdiff
path: root/client/make-updates
blob: 7f8fcfe4e9228a9ea8b4dbf811007a44928218cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash -e
# This is a tool to automatically generate and ship client updates.
# It is entirely self-contained, storing its own state in the git repo.
# It is called by running 'make updates' in server-data.
# It also supports manually calls for maintenance work.
# TODO: make auto-mode work with music too.

# local branch to keep update info on
# will be created on first run; updated thereafter
branch=update-zips
# must already exist
# must NOT be a relative path
output=~/www/updates

function apply_function()
{
    $1  misc                *.* COPYING rules/
    $1  graphics-emotes     graphics/emotes/
    $1  graphics-images     graphics/images/ graphics/guiicons/
    $1  graphics-items      graphics/items/
    $1  graphics-minimaps   graphics/minimaps/
    $1  graphics-particles  graphics/particles/
    $1  graphics-skills     graphics/skills/
    $1  graphics-sprites    graphics/sprites/
    $1  graphics-tiles      graphics/tiles/
    $1  items               items/
    $1  maps                maps/
    $1  monsters            monsters/
    $1  npcs                npcs/
    $1  sfx                 sfx/
    $1  tilesets            tilesets/
}

function add_resource()
{
    pushd $output >/dev/null
    adler32 $1 | tee -a resources2.txt | {
        read name hash
        chmod a+r $name
        sed '/<\/updates>/i    <update type="data" file="'$name'" hash="'$hash'" />' -i resources.xml
    }
    popd >/dev/null
}

function add_music()
{
    pushd $output >/dev/null
    adler32 $1 | {
        read name hash
        chmod a+r $name
        sed '/<\/updates>/i    <update type="music" required="no" file="'$name'" hash="'$hash'" />' -i resources.xml
    }
    popd >/dev/null
}

function do_initial_zip()
{
    zip=$1-$this_update.zip; shift
    git ls-files --with-tree=HEAD -- "$@" \
        | zip -q $output/$zip -@
    add_resource $zip
}
function do_initial_music()
{
    zip=music-$this_update.zip
    ( cd music/ ; git ls-files --with-tree=HEAD ) \
        | sed 's:^:music/:' \
        | zip -q $output/$zip -@
    add_music $zip
}

function git_diff_tree()
{
    git diff-tree -r --diff-filter=AM "$@"
}

function do_delta_zip()
{
    zip=$1-$last_update..$this_update.zip; shift
    if git_diff_tree  --quiet $last_update $this_update -- "$@"
    then
        return
    fi
    git_diff_tree --name-only $last_update $this_update -- "$@" \
        | zip -q $output/$zip -@
    add_resource $zip
}
function do_delta_music()
{
    zip=music-$last_update..$this_update.zip
    if (cd music; git_diff_tree  --quiet $last_update $this_update )
    then
        return
    fi
    (cd music; git_diff_tree --name-only $last_update $this_update ) \
        | sed 's:^:music/:' \
        | zip -q $output/$zip -@
    add_music $zip
}

function do_initial_zips()
{
    apply_function do_initial_zip
}

function do_delta_zips()
{
    apply_function do_delta_zip
}

function main()
{
    if ! test -d $output
    then
        echo 'Fatal error: output directory does not exist'
        echo "$output"
        return 1
    fi
    if ! test -f $output/resources.xml
    then
        (
            echo '<?xml version="1.0"?>'
            echo '<updates>'
            echo '</updates>'
        ) > $output/resources.xml
    fi

    this_update=$(git rev-parse --short HEAD)
    if ! last_update=$(git rev-parse --short $branch 2>/dev/null)
    then
        echo 'Doing initial updates'
        do_initial_zips
    elif test "$this_update" = "$last_update"
    then
        echo 'No commits since last update generation ...'
    else
        echo 'Doing incremental updates'
        do_delta_zips
    fi
    git branch -f $branch

    this_update=$(cd music; git rev-parse --short HEAD)
    if ! last_update=$(cd music; git rev-parse --short $branch 2>/dev/null)
    then
        echo 'Doing initial music updates'
        do_initial_music
    elif test "$this_update" = "$last_update"
    then
        echo 'No commits since last music update generation ...'
    else
        echo 'Doing incremental music updates'
        do_delta_music
    fi
    ( cd music; git branch -f $branch )
}

if test "$0" = "$BASH_SOURCE"
then
    echo 'Generating updates automatically'
    main
else
    echo 'sourcing detected - you can do manual updates'
fi