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