Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / bin / update / common.sh
blob5bba576c702cf173feee63e43968c458baad3303
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
11 # -----------------------------------------------------------------------------
12 # By default just assume that these tools exist on our path
13 MAR=${MAR:-mar}
14 BZIP2=${BZIP2:-bzip2}
15 MBSDIFF=${MBSDIFF:-mbsdiff}
17 # -----------------------------------------------------------------------------
18 # Helper routines
20 notice() {
21 echo "$*" 1>&2
24 get_file_size() {
25 info=($(ls -ln "$1"))
26 echo ${info[4]}
29 check_externals() {
31 # check whether we can call the mar executable
32 "$MAR" --version > /dev/null 2>&1
33 if [ $? != 0 ]; then
34 notice "Could not find a valid mar executable in the path or in the MAR environment variable"
35 exit 1
38 # check whether we can access the bzip2 executable
39 "$BZIP2" --help > /dev/null 2>&1
40 if [ $? != 0 ]; then
41 notice "Could not find a valid bzip2 executable in the PATH or in the BZIP2 environment variable"
42 exit 1
46 copy_perm() {
47 reference="$1"
48 target="$2"
50 if [ -x "$reference" ]; then
51 chmod 0755 "$target"
52 else
53 chmod 0644 "$target"
57 make_add_instruction() {
58 f="$1"
59 filev2="$2"
60 # The third param will be an empty string when a file add instruction is only
61 # needed in the version 2 manifest. This only happens when the file has an
62 # add-if-not instruction in the version 3 manifest. This is due to the
63 # precomplete file prior to the version 3 manifest having a remove instruction
64 # for this file so the file is removed before applying a complete update.
65 filev3="$3"
67 # Used to log to the console
68 if [ $4 ]; then
69 forced=" (forced)"
70 else
71 forced=
74 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
75 if [ $is_extension = "1" ]; then
76 # Use the subdirectory of the extensions folder as the file to test
77 # before performing this add instruction.
78 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
79 notice " add-if \"$testdir\" \"$f\""
80 echo "add-if \"$testdir\" \"$f\"" >> $filev2
81 if [ ! $filev3 = "" ]; then
82 echo "add-if \"$testdir\" \"$f\"" >> $filev3
84 else
85 notice " add \"$f\"$forced"
86 echo "add \"$f\"" >> $filev2
87 if [ ! $filev3 = "" ]; then
88 echo "add \"$f\"" >> $filev3
93 check_for_add_if_not_update() {
94 add_if_not_file_chk="$1"
96 if [ `basename $add_if_not_file_chk` = "channel-prefs.js" -o \
97 `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
98 ## "true" *giggle*
99 return 0;
101 ## 'false'... because this is bash. Oh yay!
102 return 1;
105 check_for_add_to_manifestv2() {
106 add_if_not_file_chk="$1"
108 if [ `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
109 ## "true" *giggle*
110 return 0;
112 ## 'false'... because this is bash. Oh yay!
113 return 1;
116 make_add_if_not_instruction() {
117 f="$1"
118 filev3="$2"
120 notice " add-if-not \"$f\" \"$f\""
121 echo "add-if-not \"$f\" \"$f\"" >> $filev3
124 make_patch_instruction() {
125 f="$1"
126 filev2="$2"
127 filev3="$3"
129 is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
130 if [ $is_extension = "1" ]; then
131 # Use the subdirectory of the extensions folder as the file to test
132 # before performing this add instruction.
133 testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
134 notice " patch-if \"$testdir\" \"$f.patch\" \"$f\""
135 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev2
136 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev3
137 else
138 notice " patch \"$f.patch\" \"$f\""
139 echo "patch \"$f.patch\" \"$f\"" >> $filev2
140 echo "patch \"$f.patch\" \"$f\"" >> $filev3
144 append_remove_instructions() {
145 dir="$1"
146 filev2="$2"
147 filev3="$3"
149 if [ -f "$dir/removed-files" ]; then
150 listfile="$dir/removed-files"
151 elif [ -f "$dir/Contents/Resources/removed-files" ]; then
152 listfile="$dir/Contents/Resources/removed-files"
154 if [ -n "$listfile" ]; then
155 # Map spaces to pipes so that we correctly handle filenames with spaces.
156 files=($(cat "$listfile" | tr " " "|" | sort -r))
157 num_files=${#files[*]}
158 for ((i=0; $i<$num_files; i=$i+1)); do
159 # Map pipes back to whitespace and remove carriage returns
160 f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
161 # Trim whitespace
162 f=$(echo $f)
163 # Exclude blank lines.
164 if [ -n "$f" ]; then
165 # Exclude comments
166 if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
167 if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
168 notice " rmdir \"$f\""
169 echo "rmdir \"$f\"" >> $filev2
170 echo "rmdir \"$f\"" >> $filev3
171 elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
172 # Remove the *
173 f=$(echo "$f" | sed -e 's:\*$::')
174 notice " rmrfdir \"$f\""
175 echo "rmrfdir \"$f\"" >> $filev2
176 echo "rmrfdir \"$f\"" >> $filev3
177 else
178 notice " remove \"$f\""
179 echo "remove \"$f\"" >> $filev2
180 echo "remove \"$f\"" >> $filev3
184 done
188 # List all files in the current directory, stripping leading "./"
189 # Pass a variable name and it will be filled as an array.
190 list_files() {
191 count=0
193 find . -type f \
194 ! -name "update.manifest" \
195 ! -name "updatev2.manifest" \
196 ! -name "updatev3.manifest" \
197 ! -name "temp-dirlist" \
198 ! -name "temp-filelist" \
199 | sed 's/\.\/\(.*\)/\1/' \
200 | sort -r > "temp-filelist"
201 while read file; do
202 eval "${1}[$count]=\"$file\""
203 (( count++ ))
204 done < "temp-filelist"
205 rm "temp-filelist"
208 # List all directories in the current directory, stripping leading "./"
209 list_dirs() {
210 count=0
212 find . -type d \
213 ! -name "." \
214 ! -name ".." \
215 | sed 's/\.\/\(.*\)/\1/' \
216 | sort -r > "temp-dirlist"
217 while read dir; do
218 eval "${1}[$count]=\"$dir\""
219 (( count++ ))
220 done < "temp-dirlist"
221 rm "temp-dirlist"