Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / tools / update-packaging / make_incremental_update.sh
blob2a20b64e8782ddca084912a7b7cfe4d0b1182583
1 #!/bin/bash
3 # This tool generates incremental update packages for the update system.
4 # Author: Darin Fisher
7 . $(dirname "$0")/common.sh
9 # -----------------------------------------------------------------------------
11 print_usage() {
12 notice "Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR"
13 notice ""
14 notice "The differences between FROMDIR and TODIR will be stored in ARCHIVE."
15 notice ""
16 notice "Options:"
17 notice " -h show this help text"
18 notice " -f clobber this file in the installation"
19 notice " Must be a path to a file to clobber in the partial update."
20 notice ""
23 check_for_forced_update() {
24 force_list="$1"
25 forced_file_chk="$2"
27 ## 'false'... because this is bash. Oh yay!
28 local do_force=1
29 local f
31 for f in $force_list; do
32 #echo comparing $forced_file_chk to $f
33 if [ "$forced_file_chk" = "$f" ]; then
34 ## "true" *giggle*
35 do_force=0
36 break
38 done
39 return $do_force;
42 if [ $# = 0 ]; then
43 print_usage
44 exit 1
47 requested_forced_updates=''
49 while getopts "hf:" flag
51 case "$flag" in
52 h) print_usage; exit 0
54 f) requested_forced_updates="$requested_forced_updates $OPTARG"
56 ?) print_usage; exit 1
58 esac
59 done
61 # -----------------------------------------------------------------------------
63 let arg_start=$OPTIND-1
64 shift $arg_start
66 archive="$1"
67 olddir="$2"
68 newdir="$3"
69 workdir="$newdir.work"
70 manifest="$workdir/update.manifest"
71 archivefiles="update.manifest"
73 mkdir -p "$workdir"
75 # Generate a list of all files in the target directory.
76 pushd "$olddir"
77 if test $? -ne 0 ; then
78 exit 1
81 list_files oldfiles
83 popd
85 pushd "$newdir"
86 if test $? -ne 0 ; then
87 exit 1
90 list_files newfiles
92 popd
94 > $manifest
96 num_oldfiles=${#oldfiles[*]}
98 for ((i=0; $i<$num_oldfiles; i=$i+1)); do
99 f="${oldfiles[$i]}"
101 # This file is created by Talkback, so we can ignore it
102 if [ "$f" = "readme.txt" ]; then
103 continue 1
106 # If this file exists in the new directory as well, then check if it differs.
107 if [ -f "$newdir/$f" ]; then
108 if ! diff "$olddir/$f" "$newdir/$f" > /dev/null; then
109 # Compute both the compressed binary diff and the compressed file, and
110 # compare the sizes. Then choose the smaller of the two to package.
111 echo " diffing $f"
112 dir=$(dirname "$workdir/$f")
113 mkdir -p "$dir"
114 $MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
115 $BZIP2 -z9 "$workdir/$f.patch"
116 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
117 patchfile="$workdir/$f.patch.bz2"
118 patchsize=$(get_file_size "$patchfile")
119 fullsize=$(get_file_size "$workdir/$f")
121 if check_for_forced_update "$requested_forced_updates" "$f"; then
122 echo 1>&2 " FORCING UPDATE for file '$f'..."
123 make_add_instruction "$f" >> $manifest
124 rm -f "$patchfile"
125 archivefiles="$archivefiles \"$f\""
126 continue 1
129 if [ $patchsize -lt $fullsize -a "$f" != "removed-files" ]; then
130 make_patch_instruction "$f" >> $manifest
131 mv -f "$patchfile" "$workdir/$f.patch"
132 rm -f "$workdir/$f"
133 archivefiles="$archivefiles \"$f.patch\""
134 else
135 make_add_instruction "$f" >> $manifest
136 rm -f "$patchfile"
137 archivefiles="$archivefiles \"$f\""
140 else
141 echo "remove \"$f\"" >> $manifest
143 done
145 # Now, we just need to worry about newly added files
146 num_newfiles=${#newfiles[*]}
148 for ((i=0; $i<$num_newfiles; i=$i+1)); do
149 f="${newfiles[$i]}"
151 # If we've already tested this file, then skip it
152 for ((j=0; $j<$num_oldfiles; j=$j+1)); do
153 if [ "$f" = "${oldfiles[j]}" ]; then
154 continue 2
156 done
158 dir=$(dirname "$workdir/$f")
159 mkdir -p "$dir"
161 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
163 make_add_instruction "$f" >> "$manifest"
164 archivefiles="$archivefiles \"$f\""
165 done
167 # Append remove instructions for any dead files.
168 append_remove_instructions "$newdir" >> $manifest
170 $BZIP2 -z9 "$manifest" && mv -f "$manifest.bz2" "$manifest"
172 eval "$MAR -C \"$workdir\" -c output.mar $archivefiles"
173 mv -f "$workdir/output.mar" "$archive"
175 # cleanup
176 rm -fr "$workdir"