2005-06-09 05:29:17 +04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This tool generates full update packages for the update system.
|
|
|
|
# Author: Darin Fisher
|
|
|
|
#
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# By default just assume that these tools exist on our path
|
|
|
|
MAR=${MAR:-mar}
|
|
|
|
BZIP2=${BZIP2:-bzip2}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
echo "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $1 = -h ]; then
|
|
|
|
print_usage
|
|
|
|
echo ""
|
|
|
|
echo "The contents of DIRECTORY will be stored in ARCHIVE."
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h show this help text"
|
|
|
|
echo ""
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
copy_perm() {
|
|
|
|
reference="$1"
|
|
|
|
target="$2"
|
|
|
|
|
|
|
|
if [ -x "$reference" ]; then
|
|
|
|
chmod 0755 "$target"
|
|
|
|
else
|
|
|
|
chmod 0644 "$target"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-07-05 21:44:09 +04:00
|
|
|
make_add_instruction() {
|
|
|
|
f="$1"
|
|
|
|
is_extension=$(echo "$f" | grep -c 'extensions/.*/')
|
|
|
|
if [ $is_extension = "1" ]; then
|
|
|
|
# Use the subdirectory of the extensions folder as the file to test
|
|
|
|
# before performing this add instruction.
|
|
|
|
testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/')
|
|
|
|
echo "add-if \"$testdir\" \"$f\""
|
|
|
|
else
|
|
|
|
echo "add \"$f\""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-09-01 22:41:11 +04:00
|
|
|
# List all files in the current directory, stripping leading "./"
|
|
|
|
# Skip the channel-prefs.js file as it should not be included in any
|
|
|
|
# generated MAR files (see bug 306077).
|
|
|
|
list_files() {
|
|
|
|
find . -type f ! -name "channel-prefs.js" | sed 's/\.\/\(.*\)/"\1"/'
|
|
|
|
}
|
|
|
|
|
2005-06-09 05:29:17 +04:00
|
|
|
archive="$1"
|
|
|
|
targetdir="$2"
|
|
|
|
workdir="$targetdir.work"
|
|
|
|
manifest="$workdir/update.manifest"
|
|
|
|
targetfiles="update.manifest"
|
|
|
|
|
|
|
|
# Generate a list of all files in the target directory.
|
2005-09-01 22:41:11 +04:00
|
|
|
list=$(cd "$targetdir" && list_files)
|
2005-06-09 05:29:17 +04:00
|
|
|
eval "files=($list)"
|
|
|
|
|
|
|
|
mkdir -p "$workdir"
|
|
|
|
> $manifest
|
|
|
|
|
|
|
|
num_files=${#files[*]}
|
|
|
|
|
|
|
|
for ((i=0; $i<$num_files; i=$i+1)); do
|
|
|
|
f=${files[$i]}
|
|
|
|
|
|
|
|
echo " processing $f"
|
|
|
|
|
2005-07-05 21:44:09 +04:00
|
|
|
make_add_instruction "$f" >> $manifest
|
2005-06-09 05:29:17 +04:00
|
|
|
|
|
|
|
dir=$(dirname "$f")
|
|
|
|
mkdir -p "$workdir/$dir"
|
|
|
|
$BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f"
|
|
|
|
copy_perm "$targetdir/$f" "$workdir/$f"
|
|
|
|
|
|
|
|
targetfiles="$targetfiles \"$f\""
|
|
|
|
done
|
|
|
|
|
|
|
|
$BZIP2 -z9 "$manifest" && mv -f "$manifest.bz2" "$manifest"
|
|
|
|
|
2005-06-22 04:32:16 +04:00
|
|
|
eval "$MAR -C \"$workdir\" -c output.mar $targetfiles"
|
2005-06-09 05:29:17 +04:00
|
|
|
mv -f "$workdir/output.mar" "$archive"
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
rm -fr "$workdir"
|