2005-06-09 05:29:17 +04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This tool generates incremental update packages for the update system.
|
|
|
|
# Author: Darin Fisher
|
|
|
|
#
|
|
|
|
|
2005-09-22 22:18:27 +04:00
|
|
|
. $(dirname "$0")/common.sh
|
2005-06-09 05:29:17 +04:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
print_usage() {
|
2005-09-22 22:18:27 +04:00
|
|
|
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"
|
2006-02-13 09:55:47 +03:00
|
|
|
notice " -f clobber this file in the installation"
|
|
|
|
notice " Must be a path to a file to clobber in the partial update."
|
2005-09-22 22:18:27 +04:00
|
|
|
notice ""
|
2006-02-13 09:55:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
check_for_forced_update() {
|
|
|
|
force_list="$1"
|
|
|
|
forced_file_chk="$2"
|
|
|
|
|
|
|
|
## 'false'... because this is bash. Oh yay!
|
|
|
|
local do_force=1
|
|
|
|
local f
|
|
|
|
|
|
|
|
for f in $force_list; do
|
|
|
|
#echo comparing $forced_file_chk to $f
|
|
|
|
if [ "$forced_file_chk" = "$f" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
do_force=0
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return $do_force;
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
print_usage
|
2005-06-09 05:29:17 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-02-13 09:55:47 +03:00
|
|
|
requested_forced_updates=''
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-02-13 09:55:47 +03:00
|
|
|
let arg_start=$OPTIND-1
|
|
|
|
shift $arg_start
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
archive="$1"
|
|
|
|
olddir="$2"
|
|
|
|
newdir="$3"
|
|
|
|
workdir="$newdir.work"
|
|
|
|
manifest="$workdir/update.manifest"
|
|
|
|
archivefiles="update.manifest"
|
|
|
|
|
2007-03-29 18:11:40 +04:00
|
|
|
mkdir -p "$workdir"
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
# Generate a list of all files in the target directory.
|
2006-02-24 21:16:33 +03:00
|
|
|
pushd "$olddir"
|
|
|
|
if test $? -ne 0 ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-03-29 18:11:40 +04:00
|
|
|
list_files oldfiles
|
2006-02-24 21:16:33 +03:00
|
|
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd "$newdir"
|
|
|
|
if test $? -ne 0 ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-03-29 18:11:40 +04:00
|
|
|
list_files newfiles
|
2005-06-09 05:29:17 +04:00
|
|
|
|
2006-02-24 21:16:33 +03:00
|
|
|
popd
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
> $manifest
|
|
|
|
|
|
|
|
num_oldfiles=${#oldfiles[*]}
|
|
|
|
|
|
|
|
for ((i=0; $i<$num_oldfiles; i=$i+1)); do
|
2007-03-29 18:11:40 +04:00
|
|
|
f="${oldfiles[$i]}"
|
2006-02-13 09:55:47 +03:00
|
|
|
|
|
|
|
# This file is created by Talkback, so we can ignore it
|
|
|
|
if [ "$f" = "readme.txt" ]; then
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
# If this file exists in the new directory as well, then check if it differs.
|
|
|
|
if [ -f "$newdir/$f" ]; then
|
|
|
|
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.
|
|
|
|
echo " diffing $f"
|
|
|
|
dir=$(dirname "$workdir/$f")
|
|
|
|
mkdir -p "$dir"
|
|
|
|
$MBSDIFF "$olddir/$f" "$newdir/$f" "$workdir/$f.patch"
|
|
|
|
$BZIP2 -z9 "$workdir/$f.patch"
|
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
|
|
|
patchfile="$workdir/$f.patch.bz2"
|
|
|
|
patchsize=$(get_file_size "$patchfile")
|
|
|
|
fullsize=$(get_file_size "$workdir/$f")
|
2006-02-13 09:55:47 +03:00
|
|
|
|
|
|
|
if check_for_forced_update "$requested_forced_updates" "$f"; then
|
|
|
|
echo 1>&2 " FORCING UPDATE for file '$f'..."
|
|
|
|
make_add_instruction "$f" >> $manifest
|
|
|
|
rm -f "$patchfile"
|
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
2005-10-04 03:13:01 +04:00
|
|
|
if [ $patchsize -lt $fullsize -a "$f" != "removed-files" ]; then
|
2005-07-05 21:44:09 +04:00
|
|
|
make_patch_instruction "$f" >> $manifest
|
2005-06-09 05:29:17 +04:00
|
|
|
mv -f "$patchfile" "$workdir/$f.patch"
|
|
|
|
rm -f "$workdir/$f"
|
|
|
|
archivefiles="$archivefiles \"$f.patch\""
|
|
|
|
else
|
2005-07-05 21:44:09 +04:00
|
|
|
make_add_instruction "$f" >> $manifest
|
2005-06-09 05:29:17 +04:00
|
|
|
rm -f "$patchfile"
|
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "remove \"$f\"" >> $manifest
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Now, we just need to worry about newly added files
|
|
|
|
num_newfiles=${#newfiles[*]}
|
|
|
|
|
|
|
|
for ((i=0; $i<$num_newfiles; i=$i+1)); do
|
2007-03-29 18:11:40 +04:00
|
|
|
f="${newfiles[$i]}"
|
2005-06-09 05:29:17 +04:00
|
|
|
|
|
|
|
# If we've already tested this file, then skip it
|
|
|
|
for ((j=0; $j<$num_oldfiles; j=$j+1)); do
|
2008-01-10 23:59:47 +03:00
|
|
|
if [ "$f" = "${oldfiles[j]}" ]; then
|
2005-06-09 05:29:17 +04:00
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
dir=$(dirname "$workdir/$f")
|
|
|
|
mkdir -p "$dir"
|
|
|
|
|
|
|
|
$BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
|
|
|
|
|
2005-07-05 21:44:09 +04:00
|
|
|
make_add_instruction "$f" >> "$manifest"
|
2005-06-09 05:29:17 +04:00
|
|
|
archivefiles="$archivefiles \"$f\""
|
|
|
|
done
|
|
|
|
|
2005-09-22 22:18:27 +04:00
|
|
|
# Append remove instructions for any dead files.
|
2005-10-17 19:26:50 +04:00
|
|
|
append_remove_instructions "$newdir" >> $manifest
|
2005-09-22 22:18:27 +04:00
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
$BZIP2 -z9 "$manifest" && mv -f "$manifest.bz2" "$manifest"
|
|
|
|
|
2005-06-22 04:32:16 +04:00
|
|
|
eval "$MAR -C \"$workdir\" -c output.mar $archivefiles"
|
2005-06-09 05:29:17 +04:00
|
|
|
mv -f "$workdir/output.mar" "$archive"
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
rm -fr "$workdir"
|