michael@0: #!/bin/bash michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # michael@0: # This tool generates full update packages for the update system. michael@0: # Author: Darin Fisher michael@0: # michael@0: michael@0: . $(dirname "$0")/common.sh michael@0: michael@0: # TODO: it would be better to pass this as a command line option. michael@0: directories_to_remove='TorBrowser/Data/Browser/profile.default/extensions/https-everywhere@eff.org' michael@0: michael@0: # ----------------------------------------------------------------------------- michael@0: michael@0: print_usage() { michael@0: notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" michael@0: } michael@0: michael@0: if [ $# = 0 ]; then michael@0: print_usage michael@0: exit 1 michael@0: fi michael@0: michael@0: if [ $1 = -h ]; then michael@0: print_usage michael@0: notice "" michael@0: notice "The contents of DIRECTORY will be stored in ARCHIVE." michael@0: notice "" michael@0: notice "Options:" michael@0: notice " -h show this help text" michael@0: notice " -q be less verbose" michael@0: notice "" michael@0: exit 1 michael@0: fi michael@0: michael@0: if [ $1 = -q ]; then michael@0: QUIET=1 michael@0: shift michael@0: fi michael@0: michael@0: # ----------------------------------------------------------------------------- michael@0: michael@0: archive="$1" michael@0: targetdir="$2" michael@0: # Prevent the workdir from being inside the targetdir so it isn't included in michael@0: # the update mar. michael@0: if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then michael@0: # Remove the / michael@0: targetdir=$(echo "$targetdir" | sed -e 's:\/$::') michael@0: fi michael@0: workdir="$targetdir.work" michael@0: updatemanifestv2="$workdir/updatev2.manifest" michael@0: updatemanifestv3="$workdir/updatev3.manifest" michael@0: targetfiles="updatev2.manifest updatev3.manifest" michael@0: michael@0: mkdir -p "$workdir" michael@0: michael@0: # On Mac, the precomplete file added by Bug 386760 will cause OS X to reload the michael@0: # Info.plist so it launches the right architecture, bug 600098 michael@0: michael@0: # Generate a list of all files in the target directory. michael@0: pushd "$targetdir" michael@0: if test $? -ne 0 ; then michael@0: exit 1 michael@0: fi michael@0: michael@0: if [ ! -f "precomplete" ]; then michael@0: notice "precomplete file is missing!" michael@0: exit 1 michael@0: fi michael@0: michael@0: list_files files michael@0: list_symlinks symlinks symlink_targets michael@0: michael@0: popd michael@0: michael@0: # Add the type of update to the beginning of the update manifests. michael@0: > "$updatemanifestv2" michael@0: > "$updatemanifestv3" michael@0: notice "" michael@0: notice "Adding type instruction to update manifests" michael@0: notice " type complete" michael@0: echo "type \"complete\"" >> "$updatemanifestv2" michael@0: echo "type \"complete\"" >> "$updatemanifestv3" michael@0: michael@0: # If removal of any old, existing directories is desired, emit the appropriate michael@0: # rmrfdir commands. michael@0: notice "" michael@0: notice "Adding directory removal instructions to update manifests" michael@0: for dir_to_remove in $directories_to_remove; do michael@0: # rmrfdir requires a trailing slash; if slash is missing, add one. michael@0: if ! [[ "$dir_to_remove" =~ /$ ]]; then michael@0: dir_to_remove="${dir_to_remove}/" michael@0: fi michael@0: echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv2" michael@0: echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv3" michael@0: done michael@0: michael@0: notice "" michael@0: notice "Adding file add instructions to update manifests" michael@0: num_files=${#files[*]} michael@0: michael@0: for ((i=0; $i<$num_files; i=$i+1)); do michael@0: f="${files[$i]}" michael@0: michael@0: if check_for_add_if_not_update "$f"; then michael@0: make_add_if_not_instruction "$f" "$updatemanifestv3" michael@0: if check_for_add_to_manifestv2 "$f"; then michael@0: make_add_instruction "$f" "$updatemanifestv2" "" 1 michael@0: fi michael@0: else michael@0: make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" michael@0: fi michael@0: michael@0: dir=$(dirname "$f") michael@0: mkdir -p "$workdir/$dir" michael@0: $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" michael@0: copy_perm "$targetdir/$f" "$workdir/$f" michael@0: michael@0: targetfiles="$targetfiles \"$f\"" michael@0: done michael@0: michael@0: notice "" michael@0: notice "Adding symlink add instructions to update manifests" michael@0: num_symlinks=${#symlinks[*]} michael@0: for ((i=0; $i<$num_symlinks; i=$i+1)); do michael@0: link="${symlinks[$i]}" michael@0: target="${symlink_targets[$i]}" michael@0: make_addsymlink_instruction "$link" "$target" "$updatemanifestv2" "$updatemanifestv3" michael@0: done michael@0: michael@0: # Append remove instructions for any dead files. michael@0: notice "" michael@0: notice "Adding file and directory remove instructions from file 'removed-files'" michael@0: append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" michael@0: michael@0: $BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" michael@0: $BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" michael@0: michael@0: eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" michael@0: mv -f "$workdir/output.mar" "$archive" michael@0: michael@0: # cleanup michael@0: rm -fr "$workdir" michael@0: michael@0: notice "" michael@0: notice "Finished" michael@0: notice ""