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

mercurial