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 35check_externals 36# ----------------------------------------------------------------------------- 37 38archive="$1" 39targetdir="$2" 40# Prevent the workdir from being inside the targetdir so it isn't included in 41# the update mar. 42if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then 43 # Remove the / 44 targetdir=$(echo "$targetdir" | sed -e 's:\/$::') 45fi 46workdir="$targetdir.work" 47updatemanifestv2="$workdir/updatev2.manifest" 48updatemanifestv3="$workdir/updatev3.manifest" 49targetfiles="updatev2.manifest updatev3.manifest" 50 51mkdir -p "$workdir" 52echo "updatev2.manifest" >> $workdir/files.txt 53echo "updatev3.manifest" >> $workdir/files.txt 54 55# Generate a list of all files in the target directory. 56pushd "$targetdir" 57if test $? -ne 0 ; then 58 exit 1 59fi 60 61# if [ ! -f "precomplete" ]; then 62# if [ ! -f "Contents/Resources/precomplete" ]; then 63# notice "precomplete file is missing!" 64# exit 1 65# fi 66# fi 67 68list_files files 69 70popd 71 72# Add the type of update to the beginning of the update manifests. 73> $updatemanifestv2 74> $updatemanifestv3 75notice "" 76notice "Adding type instruction to update manifests" 77notice " type complete" 78echo "type \"complete\"" >> $updatemanifestv2 79echo "type \"complete\"" >> $updatemanifestv3 80 81notice "" 82notice "Adding file add instructions to update manifests" 83num_files=${#files[*]} 84 85for ((i=0; $i<$num_files; i=$i+1)); do 86 f="${files[$i]}" 87 88 if check_for_add_if_not_update "$f"; then 89 make_add_if_not_instruction "$f" "$updatemanifestv3" 90 if check_for_add_to_manifestv2 "$f"; then 91 make_add_instruction "$f" "$updatemanifestv2" "" 1 92 fi 93 else 94 make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" 95 fi 96 97 dir=$(dirname "$f") 98 mkdir -p "$workdir/$dir" 99 $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" 100 copy_perm "$targetdir/$f" "$workdir/$f" 101 102 targetfiles="$targetfiles \"$f\"" 103 echo $f >> $workdir/files.txt 104done 105 106# Append remove instructions for any dead files. 107notice "" 108notice "Adding file and directory remove instructions from file 'removed-files'" 109append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" 110 111$BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" 112$BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" 113 114eval "$MAR -C \"$workdir\" -c output.mar -f $workdir/files.txt" 115mv -f "$workdir/output.mar" "$archive" 116 117# cleanup 118rm -fr "$workdir" 119 120notice "" 121notice "Finished" 122notice "" 123