2005-09-22 22:18:27 +04:00
|
|
|
#!/bin/bash
|
2012-05-21 15:12:37 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2005-09-22 22:18:27 +04:00
|
|
|
#
|
|
|
|
# Code shared by update packaging scripts.
|
|
|
|
# Author: Darin Fisher
|
|
|
|
#
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# By default just assume that these tools exist on our path
|
|
|
|
MAR=${MAR:-mar}
|
|
|
|
BZIP2=${BZIP2:-bzip2}
|
|
|
|
MBSDIFF=${MBSDIFF:-mbsdiff}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Helper routines
|
|
|
|
|
|
|
|
notice() {
|
2011-04-12 08:23:18 +04:00
|
|
|
echo "$*" 1>&2
|
2005-09-22 22:18:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
get_file_size() {
|
2006-03-02 09:34:22 +03:00
|
|
|
info=($(ls -ln "$1"))
|
|
|
|
echo ${info[4]}
|
2005-09-22 22:18:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_perm() {
|
|
|
|
reference="$1"
|
|
|
|
target="$2"
|
|
|
|
|
|
|
|
if [ -x "$reference" ]; then
|
|
|
|
chmod 0755 "$target"
|
|
|
|
else
|
|
|
|
chmod 0644 "$target"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
make_add_instruction() {
|
|
|
|
f="$1"
|
2014-03-05 23:42:56 +04:00
|
|
|
filev2="$2"
|
|
|
|
# The third param will be an empty string when a file add instruction is only
|
|
|
|
# needed in the version 2 manifest. This only happens when the file has an
|
|
|
|
# add-if-not instruction in the version 3 manifest. This is due to the
|
|
|
|
# precomplete file prior to the version 3 manifest having a remove instruction
|
|
|
|
# for this file so the file is removed before applying a complete update.
|
|
|
|
filev3="$3"
|
2011-04-12 08:23:18 +04:00
|
|
|
|
|
|
|
# Used to log to the console
|
2014-03-05 23:42:56 +04:00
|
|
|
if [ $4 ]; then
|
2011-04-12 08:23:18 +04:00
|
|
|
forced=" (forced)"
|
|
|
|
else
|
|
|
|
forced=
|
|
|
|
fi
|
|
|
|
|
2013-02-20 19:48:58 +04:00
|
|
|
is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
|
2005-09-22 22:18:27 +04:00
|
|
|
if [ $is_extension = "1" ]; then
|
|
|
|
# Use the subdirectory of the extensions folder as the file to test
|
|
|
|
# before performing this add instruction.
|
2013-02-20 19:48:58 +04:00
|
|
|
testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
|
2014-03-05 23:42:56 +04:00
|
|
|
notice " add-if \"$testdir\" \"$f\""
|
|
|
|
echo "add-if \"$testdir\" \"$f\"" >> $filev2
|
|
|
|
if [ ! $filev3 = "" ]; then
|
|
|
|
echo "add-if \"$testdir\" \"$f\"" >> $filev3
|
|
|
|
fi
|
2005-09-22 22:18:27 +04:00
|
|
|
else
|
2014-03-05 23:42:56 +04:00
|
|
|
notice " add \"$f\"$forced"
|
|
|
|
echo "add \"$f\"" >> $filev2
|
|
|
|
if [ ! $filev3 = "" ]; then
|
|
|
|
echo "add \"$f\"" >> $filev3
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_for_add_if_not_update() {
|
|
|
|
add_if_not_file_chk="$1"
|
|
|
|
|
|
|
|
if [ `basename $add_if_not_file_chk` = "channel-prefs.js" -o \
|
|
|
|
`basename $add_if_not_file_chk` = "update-settings.ini" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
## 'false'... because this is bash. Oh yay!
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_for_add_to_manifestv2() {
|
|
|
|
add_if_not_file_chk="$1"
|
|
|
|
|
|
|
|
if [ `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
|
|
|
|
## "true" *giggle*
|
|
|
|
return 0;
|
2005-09-22 22:18:27 +04:00
|
|
|
fi
|
2014-03-05 23:42:56 +04:00
|
|
|
## 'false'... because this is bash. Oh yay!
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_add_if_not_instruction() {
|
|
|
|
f="$1"
|
|
|
|
filev3="$2"
|
|
|
|
|
|
|
|
notice " add-if-not \"$f\" \"$f\""
|
|
|
|
echo "add-if-not \"$f\" \"$f\"" >> $filev3
|
2005-09-22 22:18:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
make_patch_instruction() {
|
|
|
|
f="$1"
|
2014-03-05 23:42:56 +04:00
|
|
|
filev2="$2"
|
|
|
|
filev3="$3"
|
|
|
|
|
2013-02-20 19:48:58 +04:00
|
|
|
is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
|
2005-09-22 22:18:27 +04:00
|
|
|
if [ $is_extension = "1" ]; then
|
|
|
|
# Use the subdirectory of the extensions folder as the file to test
|
|
|
|
# before performing this add instruction.
|
2013-02-20 19:48:58 +04:00
|
|
|
testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
|
2014-03-05 23:42:56 +04:00
|
|
|
notice " patch-if \"$testdir\" \"$f.patch\" \"$f\""
|
|
|
|
echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev2
|
|
|
|
echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> $filev3
|
2005-09-22 22:18:27 +04:00
|
|
|
else
|
2014-03-05 23:42:56 +04:00
|
|
|
notice " patch \"$f.patch\" \"$f\""
|
|
|
|
echo "patch \"$f.patch\" \"$f\"" >> $filev2
|
|
|
|
echo "patch \"$f.patch\" \"$f\"" >> $filev3
|
2005-09-22 22:18:27 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
append_remove_instructions() {
|
2005-10-17 19:26:50 +04:00
|
|
|
dir="$1"
|
2014-03-05 23:42:48 +04:00
|
|
|
filev2="$2"
|
2014-03-05 23:42:56 +04:00
|
|
|
filev3="$3"
|
|
|
|
|
2005-10-17 19:26:50 +04:00
|
|
|
if [ -f "$dir/removed-files" ]; then
|
|
|
|
listfile="$dir/removed-files"
|
2014-09-29 22:52:04 +04:00
|
|
|
elif [ -f "$dir/Contents/Resources/removed-files" ]; then
|
|
|
|
listfile="$dir/Contents/Resources/removed-files"
|
2005-10-17 19:26:50 +04:00
|
|
|
fi
|
|
|
|
if [ -n "$listfile" ]; then
|
2005-09-22 22:18:27 +04:00
|
|
|
# Map spaces to pipes so that we correctly handle filenames with spaces.
|
2011-04-12 08:23:18 +04:00
|
|
|
files=($(cat "$listfile" | tr " " "|" | sort -r))
|
2005-09-22 22:18:27 +04:00
|
|
|
num_files=${#files[*]}
|
|
|
|
for ((i=0; $i<$num_files; i=$i+1)); do
|
2011-04-12 08:23:18 +04:00
|
|
|
# Map pipes back to whitespace and remove carriage returns
|
|
|
|
f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
|
|
|
|
# Trim whitespace
|
|
|
|
f=$(echo $f)
|
|
|
|
# Exclude blank lines.
|
2005-09-22 22:18:27 +04:00
|
|
|
if [ -n "$f" ]; then
|
2011-04-12 08:23:18 +04:00
|
|
|
# Exclude comments
|
|
|
|
if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
|
|
|
|
if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
|
2014-09-29 22:52:04 +04:00
|
|
|
notice " rmdir \"$f\""
|
|
|
|
echo "rmdir \"$f\"" >> $filev2
|
|
|
|
echo "rmdir \"$f\"" >> $filev3
|
2011-04-12 08:23:18 +04:00
|
|
|
elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
|
|
|
|
# Remove the *
|
|
|
|
f=$(echo "$f" | sed -e 's:\*$::')
|
2014-09-29 22:52:04 +04:00
|
|
|
notice " rmrfdir \"$f\""
|
|
|
|
echo "rmrfdir \"$f\"" >> $filev2
|
|
|
|
echo "rmrfdir \"$f\"" >> $filev3
|
2011-04-12 08:23:18 +04:00
|
|
|
else
|
2014-09-29 22:52:04 +04:00
|
|
|
notice " remove \"$f\""
|
|
|
|
echo "remove \"$f\"" >> $filev2
|
|
|
|
echo "remove \"$f\"" >> $filev3
|
2011-04-12 08:23:18 +04:00
|
|
|
fi
|
2005-09-22 22:18:27 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# List all files in the current directory, stripping leading "./"
|
2014-03-05 23:42:56 +04:00
|
|
|
# Pass a variable name and it will be filled as an array.
|
2005-09-22 22:18:27 +04:00
|
|
|
list_files() {
|
2007-03-29 18:11:40 +04:00
|
|
|
count=0
|
|
|
|
|
2005-10-07 04:44:41 +04:00
|
|
|
find . -type f \
|
|
|
|
! -name "update.manifest" \
|
2011-04-12 08:23:18 +04:00
|
|
|
! -name "updatev2.manifest" \
|
2014-03-05 23:42:56 +04:00
|
|
|
! -name "updatev3.manifest" \
|
2011-04-12 08:23:18 +04:00
|
|
|
! -name "temp-dirlist" \
|
2008-01-10 23:59:46 +03:00
|
|
|
! -name "temp-filelist" \
|
2007-03-29 18:11:40 +04:00
|
|
|
| sed 's/\.\/\(.*\)/\1/' \
|
2011-04-12 08:23:18 +04:00
|
|
|
| sort -r > "temp-filelist"
|
2007-03-29 18:11:40 +04:00
|
|
|
while read file; do
|
|
|
|
eval "${1}[$count]=\"$file\""
|
|
|
|
(( count++ ))
|
2008-01-10 23:59:46 +03:00
|
|
|
done < "temp-filelist"
|
|
|
|
rm "temp-filelist"
|
2005-09-22 22:18:27 +04:00
|
|
|
}
|
2011-04-12 08:23:18 +04:00
|
|
|
|
|
|
|
# List all directories in the current directory, stripping leading "./"
|
|
|
|
list_dirs() {
|
|
|
|
count=0
|
|
|
|
|
|
|
|
find . -type d \
|
|
|
|
! -name "." \
|
|
|
|
! -name ".." \
|
|
|
|
| sed 's/\.\/\(.*\)/\1/' \
|
|
|
|
| sort -r > "temp-dirlist"
|
|
|
|
while read dir; do
|
|
|
|
eval "${1}[$count]=\"$dir\""
|
|
|
|
(( count++ ))
|
|
|
|
done < "temp-dirlist"
|
|
|
|
rm "temp-dirlist"
|
|
|
|
}
|