3 # This tool generates incremental update packages for the update system.
7 . $
(dirname "$0")/common.sh
9 # -----------------------------------------------------------------------------
12 notice
"Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR"
14 notice
"The differences between FROMDIR and TODIR will be stored in ARCHIVE."
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."
23 check_for_forced_update
() {
27 ## 'false'... because this is bash. Oh yay!
31 for f
in $force_list; do
32 #echo comparing $forced_file_chk to $f
33 if [ "$forced_file_chk" = "$f" ]; then
47 requested_forced_updates
=''
49 while getopts "hf:" flag
52 h
) print_usage
; exit 0
54 f
) requested_forced_updates
="$requested_forced_updates $OPTARG"
56 ?
) print_usage
; exit 1
61 # -----------------------------------------------------------------------------
63 let arg_start
=$OPTIND-1
69 workdir
="$newdir.work"
70 manifest
="$workdir/update.manifest"
71 archivefiles
="update.manifest"
75 # Generate a list of all files in the target directory.
77 if test $?
-ne 0 ; then
86 if test $?
-ne 0 ; then
96 num_oldfiles
=${#oldfiles[*]}
98 for ((i
=0; $i<$num_oldfiles; i
=$i+1)); do
101 # This file is created by Talkback, so we can ignore it
102 if [ "$f" = "readme.txt" ]; then
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.
112 dir
=$
(dirname "$workdir/$f")
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
125 archivefiles
="$archivefiles \"$f\""
129 if [ $patchsize -lt $fullsize -a "$f" != "removed-files" ]; then
130 make_patch_instruction
"$f" >> $manifest
131 mv -f "$patchfile" "$workdir/$f.patch"
133 archivefiles
="$archivefiles \"$f.patch\""
135 make_add_instruction
"$f" >> $manifest
137 archivefiles
="$archivefiles \"$f\""
141 echo "remove \"$f\"" >> $manifest
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
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
158 dir
=$
(dirname "$workdir/$f")
161 $BZIP2 -cz9 "$newdir/$f" > "$workdir/$f"
163 make_add_instruction
"$f" >> "$manifest"
164 archivefiles
="$archivefiles \"$f\""
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"