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