Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | |
michael@0 | 11 | . $(dirname "$0")/common.sh |
michael@0 | 12 | |
michael@0 | 13 | # TODO: it would be better to pass this as a command line option. |
michael@0 | 14 | directories_to_remove='TorBrowser/Data/Browser/profile.default/extensions/https-everywhere@eff.org' |
michael@0 | 15 | |
michael@0 | 16 | # ----------------------------------------------------------------------------- |
michael@0 | 17 | |
michael@0 | 18 | print_usage() { |
michael@0 | 19 | notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | if [ $# = 0 ]; then |
michael@0 | 23 | print_usage |
michael@0 | 24 | exit 1 |
michael@0 | 25 | fi |
michael@0 | 26 | |
michael@0 | 27 | if [ $1 = -h ]; then |
michael@0 | 28 | print_usage |
michael@0 | 29 | notice "" |
michael@0 | 30 | notice "The contents of DIRECTORY will be stored in ARCHIVE." |
michael@0 | 31 | notice "" |
michael@0 | 32 | notice "Options:" |
michael@0 | 33 | notice " -h show this help text" |
michael@0 | 34 | notice " -q be less verbose" |
michael@0 | 35 | notice "" |
michael@0 | 36 | exit 1 |
michael@0 | 37 | fi |
michael@0 | 38 | |
michael@0 | 39 | if [ $1 = -q ]; then |
michael@0 | 40 | QUIET=1 |
michael@0 | 41 | shift |
michael@0 | 42 | fi |
michael@0 | 43 | |
michael@0 | 44 | # ----------------------------------------------------------------------------- |
michael@0 | 45 | |
michael@0 | 46 | archive="$1" |
michael@0 | 47 | targetdir="$2" |
michael@0 | 48 | # Prevent the workdir from being inside the targetdir so it isn't included in |
michael@0 | 49 | # the update mar. |
michael@0 | 50 | if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then |
michael@0 | 51 | # Remove the / |
michael@0 | 52 | targetdir=$(echo "$targetdir" | sed -e 's:\/$::') |
michael@0 | 53 | fi |
michael@0 | 54 | workdir="$targetdir.work" |
michael@0 | 55 | updatemanifestv2="$workdir/updatev2.manifest" |
michael@0 | 56 | updatemanifestv3="$workdir/updatev3.manifest" |
michael@0 | 57 | targetfiles="updatev2.manifest updatev3.manifest" |
michael@0 | 58 | |
michael@0 | 59 | mkdir -p "$workdir" |
michael@0 | 60 | |
michael@0 | 61 | # On Mac, the precomplete file added by Bug 386760 will cause OS X to reload the |
michael@0 | 62 | # Info.plist so it launches the right architecture, bug 600098 |
michael@0 | 63 | |
michael@0 | 64 | # Generate a list of all files in the target directory. |
michael@0 | 65 | pushd "$targetdir" |
michael@0 | 66 | if test $? -ne 0 ; then |
michael@0 | 67 | exit 1 |
michael@0 | 68 | fi |
michael@0 | 69 | |
michael@0 | 70 | if [ ! -f "precomplete" ]; then |
michael@0 | 71 | notice "precomplete file is missing!" |
michael@0 | 72 | exit 1 |
michael@0 | 73 | fi |
michael@0 | 74 | |
michael@0 | 75 | list_files files |
michael@0 | 76 | list_symlinks symlinks symlink_targets |
michael@0 | 77 | |
michael@0 | 78 | popd |
michael@0 | 79 | |
michael@0 | 80 | # Add the type of update to the beginning of the update manifests. |
michael@0 | 81 | > "$updatemanifestv2" |
michael@0 | 82 | > "$updatemanifestv3" |
michael@0 | 83 | notice "" |
michael@0 | 84 | notice "Adding type instruction to update manifests" |
michael@0 | 85 | notice " type complete" |
michael@0 | 86 | echo "type \"complete\"" >> "$updatemanifestv2" |
michael@0 | 87 | echo "type \"complete\"" >> "$updatemanifestv3" |
michael@0 | 88 | |
michael@0 | 89 | # If removal of any old, existing directories is desired, emit the appropriate |
michael@0 | 90 | # rmrfdir commands. |
michael@0 | 91 | notice "" |
michael@0 | 92 | notice "Adding directory removal instructions to update manifests" |
michael@0 | 93 | for dir_to_remove in $directories_to_remove; do |
michael@0 | 94 | # rmrfdir requires a trailing slash; if slash is missing, add one. |
michael@0 | 95 | if ! [[ "$dir_to_remove" =~ /$ ]]; then |
michael@0 | 96 | dir_to_remove="${dir_to_remove}/" |
michael@0 | 97 | fi |
michael@0 | 98 | echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv2" |
michael@0 | 99 | echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv3" |
michael@0 | 100 | done |
michael@0 | 101 | |
michael@0 | 102 | notice "" |
michael@0 | 103 | notice "Adding file add instructions to update manifests" |
michael@0 | 104 | num_files=${#files[*]} |
michael@0 | 105 | |
michael@0 | 106 | for ((i=0; $i<$num_files; i=$i+1)); do |
michael@0 | 107 | f="${files[$i]}" |
michael@0 | 108 | |
michael@0 | 109 | if check_for_add_if_not_update "$f"; then |
michael@0 | 110 | make_add_if_not_instruction "$f" "$updatemanifestv3" |
michael@0 | 111 | if check_for_add_to_manifestv2 "$f"; then |
michael@0 | 112 | make_add_instruction "$f" "$updatemanifestv2" "" 1 |
michael@0 | 113 | fi |
michael@0 | 114 | else |
michael@0 | 115 | make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" |
michael@0 | 116 | fi |
michael@0 | 117 | |
michael@0 | 118 | dir=$(dirname "$f") |
michael@0 | 119 | mkdir -p "$workdir/$dir" |
michael@0 | 120 | $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" |
michael@0 | 121 | copy_perm "$targetdir/$f" "$workdir/$f" |
michael@0 | 122 | |
michael@0 | 123 | targetfiles="$targetfiles \"$f\"" |
michael@0 | 124 | done |
michael@0 | 125 | |
michael@0 | 126 | notice "" |
michael@0 | 127 | notice "Adding symlink add instructions to update manifests" |
michael@0 | 128 | num_symlinks=${#symlinks[*]} |
michael@0 | 129 | for ((i=0; $i<$num_symlinks; i=$i+1)); do |
michael@0 | 130 | link="${symlinks[$i]}" |
michael@0 | 131 | target="${symlink_targets[$i]}" |
michael@0 | 132 | make_addsymlink_instruction "$link" "$target" "$updatemanifestv2" "$updatemanifestv3" |
michael@0 | 133 | done |
michael@0 | 134 | |
michael@0 | 135 | # Append remove instructions for any dead files. |
michael@0 | 136 | notice "" |
michael@0 | 137 | notice "Adding file and directory remove instructions from file 'removed-files'" |
michael@0 | 138 | append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" |
michael@0 | 139 | |
michael@0 | 140 | $BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" |
michael@0 | 141 | $BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" |
michael@0 | 142 | |
michael@0 | 143 | eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" |
michael@0 | 144 | mv -f "$workdir/output.mar" "$archive" |
michael@0 | 145 | |
michael@0 | 146 | # cleanup |
michael@0 | 147 | rm -fr "$workdir" |
michael@0 | 148 | |
michael@0 | 149 | notice "" |
michael@0 | 150 | notice "Finished" |
michael@0 | 151 | notice "" |