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."
24 notice
" -q be less verbose"
28 check_for_forced_update
() {
34 if [ "$forced_file_chk" = "precomplete" ]; then
39 if [ "$forced_file_chk" = "Contents/Resources/precomplete" ]; then
44 if [ "$forced_file_chk" = "removed-files" ]; then
49 if [ "$forced_file_chk" = "Contents/Resources/removed-files" ]; then
55 if [ "$forced_file_chk" = "Contents/CodeResources" ]; then
60 if [ "${forced_file_chk##*.}" = "chk" ]; then
65 for f
in $force_list; do
66 #echo comparing $forced_file_chk to $f
67 if [ "$forced_file_chk" = "$f" ]; then
72 ## 'false'... because this is bash. Oh yay!
81 requested_forced_updates
='Contents/MacOS/firefox'
83 while getopts "hqf:" flag
86 h
) print_usage
; exit 0
90 f
) requested_forced_updates
="$requested_forced_updates $OPTARG"
92 ?
) print_usage
; exit 1
97 # -----------------------------------------------------------------------------
99 mar_command
="$MAR -V ${MOZ_PRODUCT_VERSION:?} -H ${MAR_CHANNEL_ID:?}"
101 let arg_start
=$OPTIND-1
107 # Prevent the workdir from being inside the targetdir so it isn't included in
109 if [ $
(echo "$newdir" |
grep -c '\/$') = 1 ]; then
111 newdir
=$
(echo "$newdir" |
sed -e 's:\/$::')
113 workdir
="$(mktemp -d)"
114 updatemanifestv3
="$workdir/updatev3.manifest"
115 archivefiles
="updatev3.manifest"
119 # Generate a list of all files in the target directory.
121 if test $?
-ne 0 ; then
131 if test $?
-ne 0 ; then
135 if [ ! -f "precomplete" ]; then
136 if [ ! -f "Contents/Resources/precomplete" ]; then
137 notice
"precomplete file is missing!"
147 # Add the type of update to the beginning of the update manifests.
149 notice
"Adding type instruction to update manifests"
151 notice
" type partial"
152 echo "type \"partial\"" >> $updatemanifestv3
155 notice
"Adding file patch and add instructions to update manifests"
157 num_oldfiles
=${#oldfiles[*]}
161 for ((i
=0; $i<$num_oldfiles; i
=$i+1)); do
164 # If this file exists in the new directory as well, then check if it differs.
165 if [ -f "$newdir/$f" ]; then
167 if check_for_add_if_not_update
"$f"; then
168 # The full workdir may not exist yet, so create it if necessary.
169 mkdir
-p `dirname "$workdir/$f"`
170 $XZ $XZ_OPT --compress $BCJ_OPTIONS --lzma2 --format=xz
--check=crc64
--force --stdout "$newdir/$f" > "$workdir/$f"
171 copy_perm
"$newdir/$f" "$workdir/$f"
172 make_add_if_not_instruction
"$f" "$updatemanifestv3"
173 archivefiles
="$archivefiles \"$f\""
177 if check_for_forced_update
"$requested_forced_updates" "$f"; then
178 # The full workdir may not exist yet, so create it if necessary.
179 mkdir
-p `dirname "$workdir/$f"`
180 $XZ $XZ_OPT --compress $BCJ_OPTIONS --lzma2 --format=xz
--check=crc64
--force --stdout "$newdir/$f" > "$workdir/$f"
181 copy_perm
"$newdir/$f" "$workdir/$f"
182 make_add_instruction
"$f" "$updatemanifestv3" 1
183 archivefiles
="$archivefiles \"$f\""
187 if ! diff "$olddir/$f" "$newdir/$f" > /dev
/null
; then
188 # Compute both the compressed binary diff and the compressed file, and
189 # compare the sizes. Then choose the smaller of the two to package.
190 dir
=$
(dirname "$workdir/$f")
192 verbose_notice
"diffing \"$f\""
193 # MBSDIFF_HOOK represents the communication interface with funsize and,
194 # if enabled, caches the intermediate patches for future use and
197 # An example of MBSDIFF_HOOK env variable could look like this:
198 # export MBSDIFF_HOOK="myscript.sh -A https://funsize/api -c /home/user"
199 # where myscript.sh has the following usage:
200 # myscript.sh -A SERVER-URL [-c LOCAL-CACHE-DIR-PATH] [-g] [-u] \
201 # PATH-FROM-URL PATH-TO-URL PATH-PATCH SERVER-URL
203 # Note: patches are bzipped or xz stashed in funsize to gain more speed
205 # if service is not enabled then default to old behavior
206 if [ -z "$MBSDIFF_HOOK" ]; then
207 $MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
208 $XZ $XZ_OPT --compress --lzma2 --format=xz
--check=crc64
--force "$workdir/$f.patch"
210 # if service enabled then check patch existence for retrieval
211 if $MBSDIFF_HOOK -g "$olddir/$f" "$newdir/$f" "$workdir/$f.patch.xz"; then
212 verbose_notice
"file \"$f\" found in funsize, diffing skipped"
214 # if not found already - compute it and cache it for future use
215 $MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
216 $XZ $XZ_OPT --compress --lzma2 --format=xz
--check=crc64
--force "$workdir/$f.patch"
217 $MBSDIFF_HOOK -u "$olddir/$f" "$newdir/$f" "$workdir/$f.patch.xz"
220 $XZ $XZ_OPT --compress $BCJ_OPTIONS --lzma2 --format=xz
--check=crc64
--force --stdout "$newdir/$f" > "$workdir/$f"
221 copy_perm
"$newdir/$f" "$workdir/$f"
222 patchfile
="$workdir/$f.patch.xz"
223 patchsize
=$
(get_file_size
"$patchfile")
224 fullsize
=$
(get_file_size
"$workdir/$f")
226 if [ $patchsize -lt $fullsize ]; then
227 make_patch_instruction
"$f" "$updatemanifestv3"
228 mv -f "$patchfile" "$workdir/$f.patch"
230 archivefiles
="$archivefiles \"$f.patch\""
232 make_add_instruction
"$f" "$updatemanifestv3"
234 archivefiles
="$archivefiles \"$f\""
238 # remove instructions are added after add / patch instructions for
239 # consistency with make_incremental_updates.py
240 remove_array
[$num_removes]=$f
247 notice
"Adding file add instructions to update manifests"
248 num_newfiles
=${#newfiles[*]}
250 for ((i
=0; $i<$num_newfiles; i
=$i+1)); do
253 # If we've already tested this file, then skip it
254 for ((j
=0; $j<$num_oldfiles; j
=$j+1)); do
255 if [ "$f" = "${oldfiles[j]}" ]; then
260 dir
=$
(dirname "$workdir/$f")
263 $XZ $XZ_OPT --compress $BCJ_OPTIONS --lzma2 --format=xz
--check=crc64
--force --stdout "$newdir/$f" > "$workdir/$f"
264 copy_perm
"$newdir/$f" "$workdir/$f"
266 if check_for_add_if_not_update
"$f"; then
267 make_add_if_not_instruction
"$f" "$updatemanifestv3"
269 make_add_instruction
"$f" "$updatemanifestv3"
273 archivefiles
="$archivefiles \"$f\""
277 notice
"Adding file remove instructions to update manifests"
278 for ((i
=0; $i<$num_removes; i
=$i+1)); do
279 f
="${remove_array[$i]}"
280 verbose_notice
" remove \"$f\""
281 echo "remove \"$f\"" >> $updatemanifestv3
284 # Add remove instructions for any dead files.
286 notice
"Adding file and directory remove instructions from file 'removed-files'"
287 append_remove_instructions
"$newdir" "$updatemanifestv3"
290 notice
"Adding directory remove instructions for directories that no longer exist"
291 num_olddirs
=${#olddirs[*]}
293 for ((i
=0; $i<$num_olddirs; i
=$i+1)); do
295 # If this dir doesn't exist in the new directory remove it.
296 if [ ! -d "$newdir/$f" ]; then
297 verbose_notice
" rmdir $f/"
298 echo "rmdir \"$f/\"" >> $updatemanifestv3
302 $XZ $XZ_OPT --compress $BCJ_OPTIONS --lzma2 --format=xz
--check=crc64
--force "$updatemanifestv3" && mv -f "$updatemanifestv3.xz" "$updatemanifestv3"
304 mar_command
="$mar_command -C \"$workdir\" -c output.mar"
305 eval "$mar_command $archivefiles"
306 mv -f "$workdir/output.mar" "$archive"