Bug 1909613 - Enable <details name=''> everywhere, r=emilio
[gecko.git] / tools / update-packaging / test / common.sh
blob0e1857c8b208d29168cdbf1615520a59b74bc3f8
1 #!/bin/bash
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Code shared by update packaging scripts.
8 # Author: Darin Fisher
10 # In here to use the local common.sh to allow the full mars to have unfiltered files
12 # -----------------------------------------------------------------------------
13 # By default just assume that these tools exist on our path
14 MAR=${MAR:-mar}
15 XZ=${XZ:-xz}
16 MBSDIFF=${MBSDIFF:-mbsdiff}
18 # -----------------------------------------------------------------------------
19 # Helper routines
21 notice() {
22 echo "$*" 1>&2
25 get_file_size() {
26 info=($(ls -ln "$1"))
27 echo ${info[4]}
30 copy_perm() {
31 reference="$1"
32 target="$2"
34 if [ -x "$reference" ]; then
35 chmod 0755 "$target"
36 else
37 chmod 0644 "$target"
41 make_add_instruction() {
42 f="$1"
43 filev2="$2"
44 # The third param will be an empty string when a file add instruction is only
45 # needed in the version 2 manifest. This only happens when the file has an
46 # add-if-not instruction in the version 3 manifest. This is due to the
47 # precomplete file prior to the version 3 manifest having a remove instruction
48 # for this file so the file is removed before applying a complete update.
49 filev3="$3"
51 # Used to log to the console
52 if [ $4 ]; then
53 forced=" (forced)"
54 else
55 forced=
58 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
59 if [ $is_extension = "1" ]; then
60 # Use the subdirectory of the extensions folder as the file to test
61 # before performing this add instruction.
62 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
63 notice " add-if \"$testdir\" \"$f\""
64 echo "add-if \"$testdir\" \"$f\"" >> $filev2
65 if [ ! $filev3 = "" ]; then
66 echo "add-if \"$testdir\" \"$f\"" >> $filev3
68 else
69 notice " add \"$f\"$forced"
70 echo "add \"$f\"" >> $filev2
71 if [ ! $filev3 = "" ]; then
72 echo "add \"$f\"" >> $filev3
77 check_for_add_if_not_update() {
78 add_if_not_file_chk="$1"
80 if [ "$(basename "$add_if_not_file_chk")" = "channel-prefs.js" -o \
81 "$(basename "$add_if_not_file_chk")" = "update-settings.ini" ]; then
82 ## "true" *giggle*
83 return 0;
85 ## 'false'... because this is bash. Oh yay!
86 return 1;
89 check_for_add_to_manifestv2() {
90 add_if_not_file_chk="$1"
92 if [ "$(basename "$add_if_not_file_chk")" = "update-settings.ini" ]; then
93 ## "true" *giggle*
94 return 0;
96 ## 'false'... because this is bash. Oh yay!
97 return 1;
100 make_add_if_not_instruction() {
101 f="$1"
102 filev3="$2"
104 notice " add-if-not \"$f\" \"$f\""
105 echo "add-if-not \"$f\" \"$f\"" >> $filev3
108 make_patch_instruction() {
109 f="$1"
110 filev2="$2"
111 filev3="$3"
113 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
114 if [ $is_extension = "1" ]; then
115 # Use the subdirectory of the extensions folder as the file to test
116 # before performing this add instruction.
117 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
118 notice " patch-if \"$testdir\" \"$f.patch\" \"$f\""
119 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev2
120 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev3
121 else
122 notice " patch \"$f.patch\" \"$f\""
123 echo "patch \"$f.patch\" \"$f\"" >> $filev2
124 echo "patch \"$f.patch\" \"$f\"" >> $filev3
128 append_remove_instructions() {
129 dir="$1"
130 filev2="$2"
131 filev3="$3"
133 if [ -f "$dir/removed-files" ]; then
134 listfile="$dir/removed-files"
135 elif [ -f "$dir/Contents/Resources/removed-files" ]; then
136 listfile="$dir/Contents/Resources/removed-files"
138 if [ -n "$listfile" ]; then
139 # Map spaces to pipes so that we correctly handle filenames with spaces.
140 files=($(cat "$listfile" | tr " " "|" | sort -r))
141 num_files=${#files[*]}
142 for ((i=0; $i<$num_files; i=$i+1)); do
143 # Map pipes back to whitespace and remove carriage returns
144 f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
145 # Trim whitespace
146 f=$(echo $f)
147 # Exclude blank lines.
148 if [ -n "$f" ]; then
149 # Exclude comments
150 if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
151 if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
152 notice " rmdir \"$f\""
153 echo "rmdir \"$f\"" >> $filev2
154 echo "rmdir \"$f\"" >> $filev3
155 elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
156 # Remove the *
157 f=$(echo "$f" | sed -e 's:\*$::')
158 notice " rmrfdir \"$f\""
159 echo "rmrfdir \"$f\"" >> $filev2
160 echo "rmrfdir \"$f\"" >> $filev3
161 else
162 notice " remove \"$f\""
163 echo "remove \"$f\"" >> $filev2
164 echo "remove \"$f\"" >> $filev3
168 done
172 # List all files in the current directory, stripping leading "./"
173 # Pass a variable name and it will be filled as an array.
174 list_files() {
175 count=0
177 # Removed the exclusion cases here to allow for generation of testing mars
178 find . -type f \
179 | sed 's/\.\/\(.*\)/\1/' \
180 | sort -r > "$workdir/temp-filelist"
181 while read file; do
182 eval "${1}[$count]=\"$file\""
183 (( count++ ))
184 done < "$workdir/temp-filelist"
185 rm "$workdir/temp-filelist"
188 # List all directories in the current directory, stripping leading "./"
189 list_dirs() {
190 count=0
192 find . -type d \
193 ! -name "." \
194 ! -name ".." \
195 | sed 's/\.\/\(.*\)/\1/' \
196 | sort -r > "$workdir/temp-dirlist"
197 while read dir; do
198 eval "${1}[$count]=\"$dir\""
199 (( count++ ))
200 done < "$workdir/temp-dirlist"
201 rm "$workdir/temp-dirlist"