2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # This tool generates incremental update packages for the update system.
11 . $
(dirname "$0")/common.sh
13 # -----------------------------------------------------------------------------
16 notice
"Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR"
18 notice
"The differences between FROMDIR and TODIR will be stored in ARCHIVE."
21 notice
" -h show this help text"
22 notice
" -f clobber this file in the installation"
23 notice
" Must be a path to a file to clobber in the partial update."
27 check_for_forced_update
() {
33 if [ "$forced_file_chk" = "precomplete" ]; then
38 if [ "${forced_file_chk##*.}" = "chk" ]
44 for f
in $force_list; do
45 #echo comparing $forced_file_chk to $f
46 if [ "$forced_file_chk" = "$f" ]; then
51 ## 'false'... because this is bash. Oh yay!
60 requested_forced_updates
='Contents/MacOS/firefox'
62 while getopts "hf:" flag
65 h
) print_usage
; exit 0
67 f
) requested_forced_updates
="$requested_forced_updates $OPTARG"
69 ?
) print_usage
; exit 1
74 # -----------------------------------------------------------------------------
76 let arg_start
=$OPTIND-1
82 # Prevent the workdir from being inside the targetdir so it isn't included in
84 if [ $
(echo "$newdir" |
grep -c '\/$') = 1 ]; then
86 newdir
=$
(echo "$newdir" |
sed -e 's:\/$::')
88 workdir
="$newdir.work"
89 updatemanifestv1
="$workdir/update.manifest"
90 updatemanifestv2
="$workdir/updatev2.manifest"
91 archivefiles
="update.manifest updatev2.manifest"
95 # On Mac, the precomplete file added by Bug 386760 will cause OS X to reload the
96 # Info.plist so it launches the right architecture, bug 600098
98 # Generate a list of all files in the target directory.
100 if test $?
-ne 0 ; then
110 if test $?
-ne 0 ; then
114 if [ ! -f "precomplete" ]; then
115 notice
"precomplete file is missing!"
125 notice
"Adding file patch and add instructions to file 'update.manifest'"
128 num_oldfiles
=${#oldfiles[*]}
132 for ((i
=0; $i<$num_oldfiles; i
=$i+1)); do
135 # This file is created by Talkback, so we can ignore it
136 if [ "$f" = "readme.txt" ]; then
140 # removed-files is excluded by make_incremental_updates.py so it is excluded
141 # here for consistency.
142 if [ `basename $f` = "removed-files" ]; then
146 # If this file exists in the new directory as well, then check if it differs.
147 if [ -f "$newdir/$f" ]; then
149 if check_for_forced_update
"$requested_forced_updates" "$f"; then
150 # The full workdir may not exist yet, so create it if necessary.
151 mkdir
-p `dirname "$workdir/$f"`
152 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
153 copy_perm
"$newdir/$f" "$workdir/$f"
154 make_add_instruction
"$f" 1 >> $updatemanifestv1
155 archivefiles
="$archivefiles \"$f\""
159 if ! diff "$olddir/$f" "$newdir/$f" > /dev
/null
; then
160 # Compute both the compressed binary diff and the compressed file, and
161 # compare the sizes. Then choose the smaller of the two to package.
162 dir
=$
(dirname "$workdir/$f")
164 $MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
165 $BZIP2 -z9 "$workdir/$f.patch"
166 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
167 copy_perm
"$newdir/$f" "$workdir/$f"
168 patchfile
="$workdir/$f.patch.bz2"
169 patchsize
=$
(get_file_size
"$patchfile")
170 fullsize
=$
(get_file_size
"$workdir/$f")
172 if [ $patchsize -lt $fullsize ]; then
173 make_patch_instruction
"$f" >> $updatemanifestv1
174 mv -f "$patchfile" "$workdir/$f.patch"
176 archivefiles
="$archivefiles \"$f.patch\""
178 make_add_instruction
"$f" >> $updatemanifestv1
180 archivefiles
="$archivefiles \"$f\""
184 # remove instructions are added after add / patch instructions for
185 # consistency with make_incremental_updates.py
186 remove_array
[$num_removes]=$f
193 notice
"Adding file add instructions to file 'update.manifest'"
194 num_newfiles
=${#newfiles[*]}
196 for ((i
=0; $i<$num_newfiles; i
=$i+1)); do
199 # removed-files is excluded by make_incremental_updates.py so it is excluded
200 # here for consistency.
201 if [ `basename $f` = "removed-files" ]; then
205 # If we've already tested this file, then skip it
206 for ((j
=0; $j<$num_oldfiles; j
=$j+1)); do
207 if [ "$f" = "${oldfiles[j]}" ]; then
212 dir
=$
(dirname "$workdir/$f")
215 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
216 copy_perm
"$newdir/$f" "$workdir/$f"
218 make_add_instruction
"$f" >> "$updatemanifestv1"
219 archivefiles
="$archivefiles \"$f\""
223 notice
"Adding file remove instructions to file 'update.manifest'"
224 for ((i
=0; $i<$num_removes; i
=$i+1)); do
225 f
="${remove_array[$i]}"
227 echo "remove \"$f\"" >> $updatemanifestv1
230 # Add the type of update to the beginning of and cat the contents of the version
231 # 1 update manifest to the version 2 update manifest.
233 notice
"Adding type instruction to file 'updatev2.manifest'"
235 notice
" type: partial"
236 echo "type \"partial\"" >> $updatemanifestv2
239 notice
"Concatenating file 'update.manifest' to file 'updatev2.manifest'"
240 cat $updatemanifestv1 >> $updatemanifestv2
242 # Append remove instructions for any dead files.
244 notice
"Adding file and directory remove instructions from file 'removed-files'"
245 append_remove_instructions
"$newdir" "$updatemanifestv1" "$updatemanifestv2"
248 notice
"Adding directory remove instructions for directories that no longer exist"
249 num_olddirs
=${#olddirs[*]}
251 for ((i
=0; $i<$num_olddirs; i
=$i+1)); do
253 # If this dir doesn't exist in the new directory remove it.
254 if [ ! -d "$newdir/$f" ]; then
256 echo "rmdir \"$f/\"" >> $updatemanifestv2
260 $BZIP2 -z9 "$updatemanifestv1" && mv -f "$updatemanifestv1.bz2" "$updatemanifestv1"
261 $BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2"
263 eval "$MAR -C \"$workdir\" -c output.mar $archivefiles"
264 mv -f "$workdir/output.mar" "$archive"