1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/update-packaging/test/common.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,217 @@ 1.4 +#!/bin/bash 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 +# 1.10 +# Code shared by update packaging scripts. 1.11 +# Author: Darin Fisher 1.12 +# 1.13 +# In here to use the local common.sh to allow the full mars to have unfiltered files 1.14 + 1.15 +# ----------------------------------------------------------------------------- 1.16 +# By default just assume that these tools exist on our path 1.17 +MAR=${MAR:-mar} 1.18 +BZIP2=${BZIP2:-bzip2} 1.19 +MBSDIFF=${MBSDIFF:-mbsdiff} 1.20 + 1.21 +# ----------------------------------------------------------------------------- 1.22 +# Helper routines 1.23 + 1.24 +notice() { 1.25 + echo "$*" 1>&2 1.26 +} 1.27 + 1.28 +get_file_size() { 1.29 + info=($(ls -ln "$1")) 1.30 + echo ${info[4]} 1.31 +} 1.32 + 1.33 +copy_perm() { 1.34 + reference="$1" 1.35 + target="$2" 1.36 + 1.37 + if [ -x "$reference" ]; then 1.38 + chmod 0755 "$target" 1.39 + else 1.40 + chmod 0644 "$target" 1.41 + fi 1.42 +} 1.43 + 1.44 +make_add_instruction() { 1.45 + f="$1" 1.46 + filev2="$2" 1.47 + # The third param will be an empty string when a file add instruction is only 1.48 + # needed in the version 2 manifest. This only happens when the file has an 1.49 + # add-if-not instruction in the version 3 manifest. This is due to the 1.50 + # precomplete file prior to the version 3 manifest having a remove instruction 1.51 + # for this file so the file is removed before applying a complete update. 1.52 + filev3="$3" 1.53 + 1.54 + # Used to log to the console 1.55 + if [ $4 ]; then 1.56 + forced=" (forced)" 1.57 + else 1.58 + forced= 1.59 + fi 1.60 + 1.61 + is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/') 1.62 + if [ $is_extension = "1" ]; then 1.63 + # Use the subdirectory of the extensions folder as the file to test 1.64 + # before performing this add instruction. 1.65 + testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/') 1.66 + notice " add-if \"$testdir\" \"$f\"" 1.67 + echo "add-if \"$testdir\" \"$f\"" >> $filev2 1.68 + if [ ! $filev3 = "" ]; then 1.69 + echo "add-if \"$testdir\" \"$f\"" >> $filev3 1.70 + fi 1.71 + else 1.72 + notice " add \"$f\"$forced" 1.73 + echo "add \"$f\"" >> $filev2 1.74 + if [ ! $filev3 = "" ]; then 1.75 + echo "add \"$f\"" >> $filev3 1.76 + fi 1.77 + fi 1.78 +} 1.79 + 1.80 +check_for_add_if_not_update() { 1.81 + add_if_not_file_chk="$1" 1.82 + 1.83 + if [ `basename $add_if_not_file_chk` = "channel-prefs.js" -o \ 1.84 + `basename $add_if_not_file_chk` = "update-settings.ini" ]; then 1.85 + ## "true" *giggle* 1.86 + return 0; 1.87 + fi 1.88 + ## 'false'... because this is bash. Oh yay! 1.89 + return 1; 1.90 +} 1.91 + 1.92 +check_for_add_to_manifestv2() { 1.93 + add_if_not_file_chk="$1" 1.94 + 1.95 + if [ `basename $add_if_not_file_chk` = "update-settings.ini" ]; then 1.96 + ## "true" *giggle* 1.97 + return 0; 1.98 + fi 1.99 + ## 'false'... because this is bash. Oh yay! 1.100 + return 1; 1.101 +} 1.102 + 1.103 +make_add_if_not_instruction() { 1.104 + f="$1" 1.105 + filev3="$2" 1.106 + 1.107 + notice " add-if-not \"$f\" \"$f\"" 1.108 + echo "add-if-not \"$f\" \"$f\"" >> $filev3 1.109 +} 1.110 + 1.111 +make_patch_instruction() { 1.112 + f="$1" 1.113 + filev2="$2" 1.114 + filev3="$3" 1.115 + 1.116 + is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/') 1.117 + if [ $is_extension = "1" ]; then 1.118 + # Use the subdirectory of the extensions folder as the file to test 1.119 + # before performing this add instruction. 1.120 + testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/') 1.121 + notice " patch-if \"$testdir\" \"$f.patch\" \"$f\"" 1.122 + echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev2 1.123 + echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev3 1.124 + else 1.125 + notice " patch \"$f.patch\" \"$f\"" 1.126 + echo "patch \"$f.patch\" \"$f\"" >> $filev2 1.127 + echo "patch \"$f.patch\" \"$f\"" >> $filev3 1.128 + fi 1.129 +} 1.130 + 1.131 +append_remove_instructions() { 1.132 + dir="$1" 1.133 + filev2="$2" 1.134 + filev3="$3" 1.135 + 1.136 + if [ -f "$dir/removed-files" ]; then 1.137 + prefix= 1.138 + listfile="$dir/removed-files" 1.139 + elif [ -f "$dir/Contents/MacOS/removed-files" ]; then 1.140 + prefix=Contents/MacOS/ 1.141 + listfile="$dir/Contents/MacOS/removed-files" 1.142 + fi 1.143 + if [ -n "$listfile" ]; then 1.144 + # Map spaces to pipes so that we correctly handle filenames with spaces. 1.145 + files=($(cat "$listfile" | tr " " "|" | sort -r)) 1.146 + num_files=${#files[*]} 1.147 + for ((i=0; $i<$num_files; i=$i+1)); do 1.148 + # Map pipes back to whitespace and remove carriage returns 1.149 + f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r') 1.150 + # Trim whitespace 1.151 + f=$(echo $f) 1.152 + # Exclude blank lines. 1.153 + if [ -n "$f" ]; then 1.154 + # Exclude comments 1.155 + if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then 1.156 + # Normalize the path to the root of the Mac OS X bundle if necessary 1.157 + fixedprefix="$prefix" 1.158 + if [ $prefix ]; then 1.159 + if [ $(echo "$f" | grep -c '^\.\./') = 1 ]; then 1.160 + if [ $(echo "$f" | grep -c '^\.\./\.\./') = 1 ]; then 1.161 + f=$(echo $f | sed -e 's:^\.\.\/\.\.\/::') 1.162 + fixedprefix="" 1.163 + else 1.164 + f=$(echo $f | sed -e 's:^\.\.\/::') 1.165 + fixedprefix=$(echo "$prefix" | sed -e 's:[^\/]*\/$::') 1.166 + fi 1.167 + fi 1.168 + fi 1.169 + if [ $(echo "$f" | grep -c '\/$') = 1 ]; then 1.170 + notice " rmdir \"$fixedprefix$f\"" 1.171 + echo "rmdir \"$fixedprefix$f\"" >> $filev2 1.172 + echo "rmdir \"$fixedprefix$f\"" >> $filev3 1.173 + elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then 1.174 + # Remove the * 1.175 + f=$(echo "$f" | sed -e 's:\*$::') 1.176 + notice " rmrfdir \"$fixedprefix$f\"" 1.177 + echo "rmrfdir \"$fixedprefix$f\"" >> $filev2 1.178 + echo "rmrfdir \"$fixedprefix$f\"" >> $filev3 1.179 + else 1.180 + notice " remove \"$fixedprefix$f\"" 1.181 + echo "remove \"$fixedprefix$f\"" >> $filev2 1.182 + echo "remove \"$fixedprefix$f\"" >> $filev3 1.183 + fi 1.184 + fi 1.185 + fi 1.186 + done 1.187 + fi 1.188 +} 1.189 + 1.190 +# List all files in the current directory, stripping leading "./" 1.191 +# Pass a variable name and it will be filled as an array. 1.192 +list_files() { 1.193 + count=0 1.194 + 1.195 + # Removed the exclusion cases here to allow for generation of testing mars 1.196 + find . -type f \ 1.197 + | sed 's/\.\/\(.*\)/\1/' \ 1.198 + | sort -r > "$workdir/temp-filelist" 1.199 + while read file; do 1.200 + eval "${1}[$count]=\"$file\"" 1.201 + (( count++ )) 1.202 + done < "$workdir/temp-filelist" 1.203 + rm "$workdir/temp-filelist" 1.204 +} 1.205 + 1.206 +# List all directories in the current directory, stripping leading "./" 1.207 +list_dirs() { 1.208 + count=0 1.209 + 1.210 + find . -type d \ 1.211 + ! -name "." \ 1.212 + ! -name ".." \ 1.213 + | sed 's/\.\/\(.*\)/\1/' \ 1.214 + | sort -r > "$workdir/temp-dirlist" 1.215 + while read dir; do 1.216 + eval "${1}[$count]=\"$dir\"" 1.217 + (( count++ )) 1.218 + done < "$workdir/temp-dirlist" 1.219 + rm "$workdir/temp-dirlist" 1.220 +}