2007-03-22 10:30:00 -07:00
|
|
|
#!/bin/bash
|
2012-05-21 04:12:37 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#
|
|
|
|
# This tool generates incremental update packages for the update system.
|
|
|
|
# Author: Darin Fisher
|
|
|
|
#
|
|
|
|
|
|
|
|
. $(dirname "$0")/common.sh
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
notice "Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR"
|
|
|
|
notice ""
|
|
|
|
notice "The differences between FROMDIR and TODIR will be stored in ARCHIVE."
|
|
|
|
notice ""
|
|
|
|
notice "Options:"
|
|
|
|
notice " -h show this help text"
|
|
|
|
notice " -f clobber this file in the installation"
|
|
|
|
notice " Must be a path to a file to clobber in the partial update."
|
|
|
|
notice ""
|
|
|
|
}
|
|
|
|
|
|
|
|
check_for_forced_update() {
|
|
|
|
force_list="$1"
|
|
|
|
forced_file_chk="$2"
|
|
|
|
|
|
|
|
local f
|
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
if [ "$forced_file_chk" = "precomplete" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
2014-09-29 11:51:55 -07:00
|
|
|
if [ "$forced_file_chk" = "Contents/Resources/precomplete" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
2014-09-29 11:53:15 -07:00
|
|
|
if [ "$forced_file_chk" = "removed-files" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$forced_file_chk" = "Contents/Resources/removed-files" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${forced_file_chk##*.}" = "chk" ]; then
|
2009-01-19 14:12:21 -08:00
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for f in $force_list; do
|
|
|
|
#echo comparing $forced_file_chk to $f
|
|
|
|
if [ "$forced_file_chk" = "$f" ]; then
|
|
|
|
## "true" *giggle*
|
2009-01-19 14:12:21 -08:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
fi
|
|
|
|
done
|
2009-01-19 14:12:21 -08:00
|
|
|
## 'false'... because this is bash. Oh yay!
|
|
|
|
return 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-09-06 16:57:28 -07:00
|
|
|
requested_forced_updates='Contents/MacOS/firefox'
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while getopts "hf:" flag
|
|
|
|
do
|
|
|
|
case "$flag" in
|
|
|
|
h) print_usage; exit 0
|
|
|
|
;;
|
|
|
|
f) requested_forced_updates="$requested_forced_updates $OPTARG"
|
|
|
|
;;
|
|
|
|
?) print_usage; exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
let arg_start=$OPTIND-1
|
|
|
|
shift $arg_start
|
|
|
|
|
|
|
|
archive="$1"
|
|
|
|
olddir="$2"
|
|
|
|
newdir="$3"
|
2011-04-11 21:23:18 -07:00
|
|
|
# Prevent the workdir from being inside the targetdir so it isn't included in
|
|
|
|
# the update mar.
|
|
|
|
if [ $(echo "$newdir" | grep -c '\/$') = 1 ]; then
|
|
|
|
# Remove the /
|
|
|
|
newdir=$(echo "$newdir" | sed -e 's:\/$::')
|
|
|
|
fi
|
2007-03-22 10:30:00 -07:00
|
|
|
workdir="$newdir.work"
|
2011-04-11 21:23:18 -07:00
|
|
|
updatemanifestv2="$workdir/updatev2.manifest"
|
2014-03-05 11:42:56 -08:00
|
|
|
updatemanifestv3="$workdir/updatev3.manifest"
|
|
|
|
archivefiles="updatev2.manifest updatev3.manifest"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-29 07:11:40 -07:00
|
|
|
mkdir -p "$workdir"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
# Generate a list of all files in the target directory.
|
|
|
|
pushd "$olddir"
|
|
|
|
if test $? -ne 0 ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-03-29 07:11:40 -07:00
|
|
|
list_files oldfiles
|
2011-04-11 21:23:18 -07:00
|
|
|
list_dirs olddirs
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd "$newdir"
|
|
|
|
if test $? -ne 0 ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
if [ ! -f "precomplete" ]; then
|
2014-09-29 11:51:55 -07:00
|
|
|
if [ ! -f "Contents/Resources/precomplete" ]; then
|
|
|
|
notice "precomplete file is missing!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-04-11 21:23:18 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
list_dirs newdirs
|
2007-03-29 07:11:40 -07:00
|
|
|
list_files newfiles
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
popd
|
|
|
|
|
2014-03-05 11:42:56 -08:00
|
|
|
# Add the type of update to the beginning of the update manifests.
|
2011-04-11 21:23:18 -07:00
|
|
|
notice ""
|
2014-03-05 11:42:56 -08:00
|
|
|
notice "Adding type instruction to update manifests"
|
2014-03-05 11:42:48 -08:00
|
|
|
> $updatemanifestv2
|
2014-03-05 11:42:56 -08:00
|
|
|
> $updatemanifestv3
|
|
|
|
notice " type partial"
|
2014-03-05 11:42:48 -08:00
|
|
|
echo "type \"partial\"" >> $updatemanifestv2
|
2014-03-05 11:42:56 -08:00
|
|
|
echo "type \"partial\"" >> $updatemanifestv3
|
2014-03-05 11:42:48 -08:00
|
|
|
|
|
|
|
notice ""
|
2014-03-05 11:42:56 -08:00
|
|
|
notice "Adding file patch and add instructions to update manifests"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
num_oldfiles=${#oldfiles[*]}
|
2011-04-11 21:23:18 -07:00
|
|
|
remove_array=
|
|
|
|
num_removes=0
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for ((i=0; $i<$num_oldfiles; i=$i+1)); do
|
2007-03-29 07:11:40 -07:00
|
|
|
f="${oldfiles[$i]}"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
# If this file exists in the new directory as well, then check if it differs.
|
|
|
|
if [ -f "$newdir/$f" ]; then
|
2009-11-20 00:55:25 -08:00
|
|
|
|
2014-03-05 11:42:56 -08:00
|
|
|
if check_for_add_if_not_update "$f"; then
|
|
|
|
# The full workdir may not exist yet, so create it if necessary.
|
|
|
|
mkdir -p `dirname "$workdir/$f"`
|
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
|
|
|
copy_perm "$newdir/$f" "$workdir/$f"
|
|
|
|
make_add_if_not_instruction "$f" "$updatemanifestv3"
|
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
2009-11-20 00:55:25 -08:00
|
|
|
if check_for_forced_update "$requested_forced_updates" "$f"; then
|
2011-04-11 21:23:18 -07:00
|
|
|
# The full workdir may not exist yet, so create it if necessary.
|
2009-11-23 13:38:31 -08:00
|
|
|
mkdir -p `dirname "$workdir/$f"`
|
2009-11-20 00:55:25 -08:00
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
2010-02-04 19:30:34 -08:00
|
|
|
copy_perm "$newdir/$f" "$workdir/$f"
|
2014-03-05 11:42:56 -08:00
|
|
|
make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" 1
|
2009-11-20 00:55:25 -08:00
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ! diff "$olddir/$f" "$newdir/$f" > /dev/null; then
|
|
|
|
# Compute both the compressed binary diff and the compressed file, and
|
|
|
|
# compare the sizes. Then choose the smaller of the two to package.
|
|
|
|
dir=$(dirname "$workdir/$f")
|
|
|
|
mkdir -p "$dir"
|
2014-03-05 11:42:56 -08:00
|
|
|
notice "diffing \"$f\""
|
2014-10-22 13:52:25 -07:00
|
|
|
# MBSDIFF_HOOK represents the communication interface with funsize and,
|
|
|
|
# if enabled, caches the intermediate patches for future use and
|
|
|
|
# compute avoidance
|
|
|
|
#
|
|
|
|
# An example of MBSDIFF_HOOK env variable could look like this:
|
|
|
|
# export MBSDIFF_HOOK="myscript.sh -A https://funsize/api -c /home/user"
|
|
|
|
# where myscript.sh has the following usage:
|
|
|
|
# myscript.sh -A SERVER-URL [-c LOCAL-CACHE-DIR-PATH] [-g] [-u] \
|
|
|
|
# PATH-FROM-URL PATH-TO-URL PATH-PATCH SERVER-URL
|
|
|
|
#
|
|
|
|
# Note: patches are bzipped stashed in funsize to gain more speed
|
|
|
|
|
|
|
|
# if service is not enabled then default to old behavior
|
|
|
|
if [ -z "$MBSDIFF_HOOK" ]; then
|
|
|
|
$MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
|
|
|
|
$BZIP2 -z9 "$workdir/$f.patch"
|
|
|
|
else
|
|
|
|
# if service enabled then check patch existence for retrieval
|
|
|
|
if $MBSDIFF_HOOK -g "$olddir/$f" "$newdir/$f" "$workdir/$f.patch.bz2"; then
|
|
|
|
notice "file \"$f\" found in funsize, diffing skipped"
|
|
|
|
else
|
|
|
|
# if not found already - compute it and cache it for future use
|
|
|
|
$MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
|
|
|
|
$BZIP2 -z9 "$workdir/$f.patch"
|
|
|
|
$MBSDIFF_HOOK -u "$olddir/$f" "$newdir/$f" "$workdir/$f.patch.bz2"
|
|
|
|
fi
|
|
|
|
fi
|
2007-03-22 10:30:00 -07:00
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
2010-02-04 19:30:34 -08:00
|
|
|
copy_perm "$newdir/$f" "$workdir/$f"
|
2007-03-22 10:30:00 -07:00
|
|
|
patchfile="$workdir/$f.patch.bz2"
|
|
|
|
patchsize=$(get_file_size "$patchfile")
|
|
|
|
fullsize=$(get_file_size "$workdir/$f")
|
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
if [ $patchsize -lt $fullsize ]; then
|
2014-03-05 11:42:56 -08:00
|
|
|
make_patch_instruction "$f" "$updatemanifestv2" "$updatemanifestv3"
|
2007-03-22 10:30:00 -07:00
|
|
|
mv -f "$patchfile" "$workdir/$f.patch"
|
|
|
|
rm -f "$workdir/$f"
|
|
|
|
archivefiles="$archivefiles \"$f.patch\""
|
|
|
|
else
|
2014-03-05 11:42:56 -08:00
|
|
|
make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3"
|
2007-03-22 10:30:00 -07:00
|
|
|
rm -f "$patchfile"
|
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
2011-04-11 21:23:18 -07:00
|
|
|
# remove instructions are added after add / patch instructions for
|
|
|
|
# consistency with make_incremental_updates.py
|
|
|
|
remove_array[$num_removes]=$f
|
|
|
|
(( num_removes++ ))
|
2007-03-22 10:30:00 -07:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
# Newly added files
|
|
|
|
notice ""
|
2014-03-05 11:42:56 -08:00
|
|
|
notice "Adding file add instructions to update manifests"
|
2007-03-22 10:30:00 -07:00
|
|
|
num_newfiles=${#newfiles[*]}
|
|
|
|
|
|
|
|
for ((i=0; $i<$num_newfiles; i=$i+1)); do
|
2007-03-29 07:11:40 -07:00
|
|
|
f="${newfiles[$i]}"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
# If we've already tested this file, then skip it
|
|
|
|
for ((j=0; $j<$num_oldfiles; j=$j+1)); do
|
2008-01-10 12:59:46 -08:00
|
|
|
if [ "$f" = "${oldfiles[j]}" ]; then
|
2007-03-22 10:30:00 -07:00
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
2011-04-11 21:23:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
dir=$(dirname "$workdir/$f")
|
|
|
|
mkdir -p "$dir"
|
|
|
|
|
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
2010-02-04 19:30:34 -08:00
|
|
|
copy_perm "$newdir/$f" "$workdir/$f"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-05 11:42:56 -08:00
|
|
|
if check_for_add_if_not_update "$f"; then
|
|
|
|
make_add_if_not_instruction "$f" "$updatemanifestv3"
|
|
|
|
else
|
|
|
|
make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
done
|
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
notice ""
|
2014-03-05 11:42:56 -08:00
|
|
|
notice "Adding file remove instructions to update manifests"
|
2011-04-11 21:23:18 -07:00
|
|
|
for ((i=0; $i<$num_removes; i=$i+1)); do
|
|
|
|
f="${remove_array[$i]}"
|
2014-03-05 11:42:56 -08:00
|
|
|
notice " remove \"$f\""
|
2014-03-05 11:42:48 -08:00
|
|
|
echo "remove \"$f\"" >> $updatemanifestv2
|
2014-03-05 11:42:56 -08:00
|
|
|
echo "remove \"$f\"" >> $updatemanifestv3
|
2011-04-11 21:23:18 -07:00
|
|
|
done
|
|
|
|
|
2014-03-05 11:42:48 -08:00
|
|
|
# Add remove instructions for any dead files.
|
2011-04-11 21:23:18 -07:00
|
|
|
notice ""
|
|
|
|
notice "Adding file and directory remove instructions from file 'removed-files'"
|
2014-03-05 11:42:56 -08:00
|
|
|
append_remove_instructions "$newdir" "$updatemanifestv2" "$updatemanifestv3"
|
2011-04-11 21:23:18 -07:00
|
|
|
|
|
|
|
notice ""
|
|
|
|
notice "Adding directory remove instructions for directories that no longer exist"
|
|
|
|
num_olddirs=${#olddirs[*]}
|
|
|
|
|
|
|
|
for ((i=0; $i<$num_olddirs; i=$i+1)); do
|
|
|
|
f="${olddirs[$i]}"
|
|
|
|
# If this dir doesn't exist in the new directory remove it.
|
|
|
|
if [ ! -d "$newdir/$f" ]; then
|
2014-03-05 11:42:56 -08:00
|
|
|
notice " rmdir $f/"
|
2011-04-11 21:23:18 -07:00
|
|
|
echo "rmdir \"$f/\"" >> $updatemanifestv2
|
2014-03-05 11:42:56 -08:00
|
|
|
echo "rmdir \"$f/\"" >> $updatemanifestv3
|
2011-04-11 21:23:18 -07:00
|
|
|
fi
|
|
|
|
done
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-11 21:23:18 -07:00
|
|
|
$BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2"
|
2014-03-05 11:42:56 -08:00
|
|
|
$BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-30 16:24:56 -07:00
|
|
|
mar_command="$MAR"
|
|
|
|
if [[ -n $MOZ_PRODUCT_VERSION ]]
|
|
|
|
then
|
|
|
|
mar_command="$mar_command -V $MOZ_PRODUCT_VERSION"
|
|
|
|
fi
|
|
|
|
if [[ -n $MOZ_CHANNEL_ID ]]
|
|
|
|
then
|
|
|
|
mar_command="$mar_command -H $MOZ_CHANNEL_ID"
|
|
|
|
fi
|
|
|
|
mar_command="$mar_command -C \"$workdir\" -c output.mar"
|
|
|
|
eval "$mar_command $archivefiles"
|
2007-03-22 10:30:00 -07:00
|
|
|
mv -f "$workdir/output.mar" "$archive"
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
rm -fr "$workdir"
|
2011-04-11 21:23:18 -07:00
|
|
|
|
|
|
|
notice ""
|
|
|
|
notice "Finished"
|
2014-03-05 11:42:56 -08:00
|
|
|
notice ""
|