tools/update-packaging/common.sh

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

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 # Code shared by update packaging scripts.
michael@0 8 # Author: Darin Fisher
michael@0 9 #
michael@0 10
michael@0 11 # -----------------------------------------------------------------------------
michael@0 12 QUIET=0
michael@0 13
michael@0 14 # By default just assume that these tools exist on our path
michael@0 15 MAR=${MAR:-mar}
michael@0 16 BZIP2=${BZIP2:-bzip2}
michael@0 17 MBSDIFF=${MBSDIFF:-mbsdiff}
michael@0 18
michael@0 19 # -----------------------------------------------------------------------------
michael@0 20 # Helper routines
michael@0 21
michael@0 22 notice() {
michael@0 23 echo "$*" 1>&2
michael@0 24 }
michael@0 25
michael@0 26 verbose_notice() {
michael@0 27 if [ $QUIET -eq 0 ]; then
michael@0 28 notice "$*"
michael@0 29 fi
michael@0 30 }
michael@0 31
michael@0 32 get_file_size() {
michael@0 33 info=($(ls -ln "$1"))
michael@0 34 echo ${info[4]}
michael@0 35 }
michael@0 36
michael@0 37 copy_perm() {
michael@0 38 reference="$1"
michael@0 39 target="$2"
michael@0 40
michael@0 41 if [ -x "$reference" ]; then
michael@0 42 chmod 0755 "$target"
michael@0 43 else
michael@0 44 chmod 0644 "$target"
michael@0 45 fi
michael@0 46 }
michael@0 47
michael@0 48 make_add_instruction() {
michael@0 49 f="$1"
michael@0 50 filev2="$2"
michael@0 51 # The third param will be an empty string when a file add instruction is only
michael@0 52 # needed in the version 2 manifest. This only happens when the file has an
michael@0 53 # add-if-not instruction in the version 3 manifest. This is due to the
michael@0 54 # precomplete file prior to the version 3 manifest having a remove instruction
michael@0 55 # for this file so the file is removed before applying a complete update.
michael@0 56 filev3="$3"
michael@0 57
michael@0 58 # Used to log to the console
michael@0 59 if [ $4 ]; then
michael@0 60 forced=" (forced)"
michael@0 61 else
michael@0 62 forced=
michael@0 63 fi
michael@0 64
michael@0 65 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
michael@0 66 if [ $is_extension = "1" ]; then
michael@0 67 # Use the subdirectory of the extensions folder as the file to test
michael@0 68 # before performing this add instruction.
michael@0 69 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
michael@0 70 verbose_notice " add-if \"$testdir\" \"$f\""
michael@0 71 echo "add-if \"$testdir\" \"$f\"" >> "$filev2"
michael@0 72 if [ ! "$filev3" = "" ]; then
michael@0 73 echo "add-if \"$testdir\" \"$f\"" >> "$filev3"
michael@0 74 fi
michael@0 75 else
michael@0 76 verbose_notice " add \"$f\"$forced"
michael@0 77 echo "add \"$f\"" >> "$filev2"
michael@0 78 if [ ! "$filev3" = "" ]; then
michael@0 79 echo "add \"$f\"" >> "$filev3"
michael@0 80 fi
michael@0 81 fi
michael@0 82 }
michael@0 83
michael@0 84 check_for_add_if_not_update() {
michael@0 85 add_if_not_file_chk="$1"
michael@0 86
michael@0 87 if [ `basename $add_if_not_file_chk` = "channel-prefs.js" -o \
michael@0 88 `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
michael@0 89 ## "true" *giggle*
michael@0 90 return 0;
michael@0 91 fi
michael@0 92 ## 'false'... because this is bash. Oh yay!
michael@0 93 return 1;
michael@0 94 }
michael@0 95
michael@0 96 check_for_add_to_manifestv2() {
michael@0 97 add_if_not_file_chk="$1"
michael@0 98
michael@0 99 if [ `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
michael@0 100 ## "true" *giggle*
michael@0 101 return 0;
michael@0 102 fi
michael@0 103 ## 'false'... because this is bash. Oh yay!
michael@0 104 return 1;
michael@0 105 }
michael@0 106
michael@0 107 make_add_if_not_instruction() {
michael@0 108 f="$1"
michael@0 109 filev3="$2"
michael@0 110
michael@0 111 verbose_notice " add-if-not \"$f\" \"$f\""
michael@0 112 echo "add-if-not \"$f\" \"$f\"" >> "$filev3"
michael@0 113 }
michael@0 114
michael@0 115 make_addsymlink_instruction() {
michael@0 116 link="$1"
michael@0 117 target="$2"
michael@0 118 filev2="$3"
michael@0 119 filev3="$4"
michael@0 120
michael@0 121 verbose_notice " addsymlink: $link -> $target"
michael@0 122 echo "addsymlink \"$link\" \"$target\"" >> "$filev2"
michael@0 123 echo "addsymlink \"$link\" \"$target\"" >> "$filev3"
michael@0 124 }
michael@0 125
michael@0 126 make_patch_instruction() {
michael@0 127 f="$1"
michael@0 128 filev2="$2"
michael@0 129 filev3="$3"
michael@0 130
michael@0 131 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
michael@0 132 if [ $is_extension = "1" ]; then
michael@0 133 # Use the subdirectory of the extensions folder as the file to test
michael@0 134 # before performing this add instruction.
michael@0 135 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
michael@0 136 verbose_notice " patch-if \"$testdir\" \"$f.patch\" \"$f\""
michael@0 137 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> "$filev2"
michael@0 138 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> "$filev3"
michael@0 139 else
michael@0 140 verbose_notice " patch \"$f.patch\" \"$f\""
michael@0 141 echo "patch \"$f.patch\" \"$f\"" >> "$filev2"
michael@0 142 echo "patch \"$f.patch\" \"$f\"" >> "$filev3"
michael@0 143 fi
michael@0 144 }
michael@0 145
michael@0 146 append_remove_instructions() {
michael@0 147 dir="$1"
michael@0 148 filev2="$2"
michael@0 149 filev3="$3"
michael@0 150
michael@0 151 if [ -f "$dir/removed-files" ]; then
michael@0 152 prefix=
michael@0 153 listfile="$dir/removed-files"
michael@0 154 elif [ -f "$dir/Contents/MacOS/removed-files" ]; then
michael@0 155 prefix=Contents/MacOS/
michael@0 156 listfile="$dir/Contents/MacOS/removed-files"
michael@0 157 fi
michael@0 158 if [ -n "$listfile" ]; then
michael@0 159 # Map spaces to pipes so that we correctly handle filenames with spaces.
michael@0 160 files=($(cat "$listfile" | tr " " "|" | sort -r))
michael@0 161 num_files=${#files[*]}
michael@0 162 for ((i=0; $i<$num_files; i=$i+1)); do
michael@0 163 # Map pipes back to whitespace and remove carriage returns
michael@0 164 f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
michael@0 165 # Trim whitespace
michael@0 166 f=$(echo $f)
michael@0 167 # Exclude blank lines.
michael@0 168 if [ -n "$f" ]; then
michael@0 169 # Exclude comments
michael@0 170 if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
michael@0 171 # Normalize the path to the root of the Mac OS X bundle if necessary
michael@0 172 fixedprefix="$prefix"
michael@0 173 if [ $prefix ]; then
michael@0 174 if [ $(echo "$f" | grep -c '^\.\./') = 1 ]; then
michael@0 175 if [ $(echo "$f" | grep -c '^\.\./\.\./') = 1 ]; then
michael@0 176 f=$(echo $f | sed -e 's:^\.\.\/\.\.\/::')
michael@0 177 fixedprefix=""
michael@0 178 else
michael@0 179 f=$(echo $f | sed -e 's:^\.\.\/::')
michael@0 180 fixedprefix=$(echo "$prefix" | sed -e 's:[^\/]*\/$::')
michael@0 181 fi
michael@0 182 fi
michael@0 183 fi
michael@0 184 if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
michael@0 185 verbose_notice " rmdir \"$fixedprefix$f\""
michael@0 186 echo "rmdir \"$fixedprefix$f\"" >> "$filev2"
michael@0 187 echo "rmdir \"$fixedprefix$f\"" >> "$filev3"
michael@0 188 elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
michael@0 189 # Remove the *
michael@0 190 f=$(echo "$f" | sed -e 's:\*$::')
michael@0 191 verbose_notice " rmrfdir \"$fixedprefix$f\""
michael@0 192 echo "rmrfdir \"$fixedprefix$f\"" >> "$filev2"
michael@0 193 echo "rmrfdir \"$fixedprefix$f\"" >> "$filev3"
michael@0 194 else
michael@0 195 verbose_notice " remove \"$fixedprefix$f\""
michael@0 196 echo "remove \"$fixedprefix$f\"" >> "$filev2"
michael@0 197 echo "remove \"$fixedprefix$f\"" >> "$filev3"
michael@0 198 fi
michael@0 199 fi
michael@0 200 fi
michael@0 201 done
michael@0 202 fi
michael@0 203 }
michael@0 204
michael@0 205 # List all files in the current directory, stripping leading "./"
michael@0 206 # Pass a variable name and it will be filled as an array.
michael@0 207 # To support Tor Browser updates, skip the following files:
michael@0 208 # TorBrowser/Data/Browser/profiles.ini
michael@0 209 # TorBrowser/Data/Browser/profile.default/bookmarks.html
michael@0 210 # TorBrowser/Data/Tor/torrc
michael@0 211 list_files() {
michael@0 212 count=0
michael@0 213
michael@0 214 find . -type f \
michael@0 215 ! -name "update.manifest" \
michael@0 216 ! -name "updatev2.manifest" \
michael@0 217 ! -name "updatev3.manifest" \
michael@0 218 ! -name "temp-dirlist" \
michael@0 219 ! -name "temp-filelist" \
michael@0 220 | sed 's/\.\/\(.*\)/\1/' \
michael@0 221 | sort -r > "temp-filelist"
michael@0 222 while read file; do
michael@0 223 if [ "$file" = "TorBrowser/Data/Browser/profiles.ini" -o \
michael@0 224 "$file" = "TorBrowser/Data/Browser/profile.default/bookmarks.html" -o \
michael@0 225 "$file" = "TorBrowser/Data/Tor/torrc" ]; then
michael@0 226 continue;
michael@0 227 fi
michael@0 228 eval "${1}[$count]=\"$file\""
michael@0 229 (( count++ ))
michael@0 230 done < "temp-filelist"
michael@0 231 rm "temp-filelist"
michael@0 232 }
michael@0 233
michael@0 234 # List all directories in the current directory, stripping leading "./"
michael@0 235 list_dirs() {
michael@0 236 count=0
michael@0 237
michael@0 238 find . -type d \
michael@0 239 ! -name "." \
michael@0 240 ! -name ".." \
michael@0 241 | sed 's/\.\/\(.*\)/\1/' \
michael@0 242 | sort -r > "temp-dirlist"
michael@0 243 while read dir; do
michael@0 244 eval "${1}[$count]=\"$dir\""
michael@0 245 (( count++ ))
michael@0 246 done < "temp-dirlist"
michael@0 247 rm "temp-dirlist"
michael@0 248 }
michael@0 249
michael@0 250 # List all symbolic links in the current directory, stripping leading "./"
michael@0 251 list_symlinks() {
michael@0 252 count=0
michael@0 253
michael@0 254 find . -type l \
michael@0 255 | sed 's/\.\/\(.*\)/\1/' \
michael@0 256 | sort -r > "temp-symlinklist"
michael@0 257 while read symlink; do
michael@0 258 target=$(readlink "$symlink")
michael@0 259 eval "${1}[$count]=\"$symlink\""
michael@0 260 eval "${2}[$count]=\"$target\""
michael@0 261 (( count++ ))
michael@0 262 done < "temp-symlinklist"
michael@0 263 rm "temp-symlinklist"
michael@0 264 }

mercurial