1#!/bin/bash 2# This Source Code Form is subject to the terms of the Mozilla Public 3# License, v. 2.0. If a copy of the MPL was not distributed with this 4# file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6# 7# This tool generates full update packages for the update system. 8# Author: Darin Fisher 9# 10 11. $(dirname "$0")/common.sh 12 13# ----------------------------------------------------------------------------- 14 15print_usage() { 16 notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" 17} 18 19if [ $# = 0 ]; then 20 print_usage 21 exit 1 22fi 23 24if [ $1 = -h ]; then 25 print_usage 26 notice "" 27 notice "The contents of DIRECTORY will be stored in ARCHIVE." 28 notice "" 29 notice "Options:" 30 notice " -h show this help text" 31 notice "" 32 exit 1 33fi 34 35# ----------------------------------------------------------------------------- 36 37archive="$1" 38targetdir="$2" 39# Prevent the workdir from being inside the targetdir so it isn't included in 40# the update mar. 41if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then 42 # Remove the / 43 targetdir=$(echo "$targetdir" | sed -e 's:\/$::') 44fi 45workdir="$targetdir.work" 46updatemanifestv2="$workdir/updatev2.manifest" 47updatemanifestv3="$workdir/updatev3.manifest" 48targetfiles="updatev2.manifest updatev3.manifest" 49 50mkdir -p "$workdir" 51 52# Generate a list of all files in the target directory. 53pushd "$targetdir" 54if test $? -ne 0 ; then 55 exit 1 56fi 57 58if [ ! -f "precomplete" ]; then 59 if [ ! -f "Contents/Resources/precomplete" ]; then 60 notice "precomplete file is missing!" 61 exit 1 62 fi 63fi 64 65list_files files 66 67popd 68 69# Add the type of update to the beginning of the update manifests. 70> $updatemanifestv2 71> $updatemanifestv3 72notice "" 73notice "Adding type instruction to update manifests" 74notice " type complete" 75echo "type \"complete\"" >> $updatemanifestv2 76echo "type \"complete\"" >> $updatemanifestv3 77 78notice "" 79notice "Adding file add instructions to update manifests" 80num_files=${#files[*]} 81 82for ((i=0; $i<$num_files; i=$i+1)); do 83 f="${files[$i]}" 84 85 if check_for_add_if_not_update "$f"; then 86 make_add_if_not_instruction "$f" "$updatemanifestv3" 87 if check_for_add_to_manifestv2 "$f"; then 88 make_add_instruction "$f" "$updatemanifestv2" "" 1 89 fi 90 else 91 make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" 92 fi 93 94 dir=$(dirname "$f") 95 mkdir -p "$workdir/$dir" 96 $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" 97 copy_perm "$targetdir/$f" "$workdir/$f" 98 99 targetfiles="$targetfiles \"$f\"" 100done 101 102# Append remove instructions for any dead files. 103notice "" 104notice "Adding file and directory remove instructions from file 'removed-files'" 105append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" 106 107$BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" 108$BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" 109 110eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" 111mv -f "$workdir/output.mar" "$archive" 112 113# cleanup 114rm -fr "$workdir" 115 116notice "" 117notice "Finished" 118notice "" 119