tools/update-packaging/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.

     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/.
     6 #
     7 # Code shared by update packaging scripts.
     8 # Author: Darin Fisher
     9 #
    11 # -----------------------------------------------------------------------------
    12 QUIET=0
    14 # By default just assume that these tools exist on our path
    15 MAR=${MAR:-mar}
    16 BZIP2=${BZIP2:-bzip2}
    17 MBSDIFF=${MBSDIFF:-mbsdiff}
    19 # -----------------------------------------------------------------------------
    20 # Helper routines
    22 notice() {
    23   echo "$*" 1>&2
    24 }
    26 verbose_notice() {
    27   if [ $QUIET -eq 0 ]; then
    28     notice "$*"
    29   fi
    30 }
    32 get_file_size() {
    33   info=($(ls -ln "$1"))
    34   echo ${info[4]}
    35 }
    37 copy_perm() {
    38   reference="$1"
    39   target="$2"
    41   if [ -x "$reference" ]; then
    42     chmod 0755 "$target"
    43   else
    44     chmod 0644 "$target"
    45   fi
    46 }
    48 make_add_instruction() {
    49   f="$1"
    50   filev2="$2"
    51   # The third param will be an empty string when a file add instruction is only
    52   # needed in the version 2 manifest. This only happens when the file has an
    53   # add-if-not instruction in the version 3 manifest. This is due to the
    54   # precomplete file prior to the version 3 manifest having a remove instruction
    55   # for this file so the file is removed before applying a complete update.
    56   filev3="$3"
    58   # Used to log to the console
    59   if [ $4 ]; then
    60     forced=" (forced)"
    61   else
    62     forced=
    63   fi
    65   is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
    66   if [ $is_extension = "1" ]; then
    67     # Use the subdirectory of the extensions folder as the file to test
    68     # before performing this add instruction.
    69     testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
    70     verbose_notice "     add-if \"$testdir\" \"$f\""
    71     echo "add-if \"$testdir\" \"$f\"" >> "$filev2"
    72     if [ ! "$filev3" = "" ]; then
    73       echo "add-if \"$testdir\" \"$f\"" >> "$filev3"
    74     fi
    75   else
    76     verbose_notice "        add \"$f\"$forced"
    77     echo "add \"$f\"" >> "$filev2"
    78     if [ ! "$filev3" = "" ]; then
    79       echo "add \"$f\"" >> "$filev3"
    80     fi
    81   fi
    82 }
    84 check_for_add_if_not_update() {
    85   add_if_not_file_chk="$1"
    87   if [ `basename $add_if_not_file_chk` = "channel-prefs.js" -o \
    88        `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
    89     ## "true" *giggle*
    90     return 0;
    91   fi
    92   ## 'false'... because this is bash. Oh yay!
    93   return 1;
    94 }
    96 check_for_add_to_manifestv2() {
    97   add_if_not_file_chk="$1"
    99   if [ `basename $add_if_not_file_chk` = "update-settings.ini" ]; then
   100     ## "true" *giggle*
   101     return 0;
   102   fi
   103   ## 'false'... because this is bash. Oh yay!
   104   return 1;
   105 }
   107 make_add_if_not_instruction() {
   108   f="$1"
   109   filev3="$2"
   111   verbose_notice " add-if-not \"$f\" \"$f\""
   112   echo "add-if-not \"$f\" \"$f\"" >> "$filev3"
   113 }
   115 make_addsymlink_instruction() {
   116   link="$1"
   117   target="$2"
   118   filev2="$3"
   119   filev3="$4"
   121   verbose_notice "        addsymlink: $link -> $target"
   122   echo "addsymlink \"$link\" \"$target\"" >> "$filev2"
   123   echo "addsymlink \"$link\" \"$target\"" >> "$filev3"
   124 }
   126 make_patch_instruction() {
   127   f="$1"
   128   filev2="$2"
   129   filev3="$3"
   131   is_extension=$(echo "$f" | grep -c 'distribution/extensions/.*/')
   132   if [ $is_extension = "1" ]; then
   133     # Use the subdirectory of the extensions folder as the file to test
   134     # before performing this add instruction.
   135     testdir=$(echo "$f" | sed 's/\(.*distribution\/extensions\/[^\/]*\)\/.*/\1/')
   136     verbose_notice "   patch-if \"$testdir\" \"$f.patch\" \"$f\""
   137     echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> "$filev2"
   138     echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" >> "$filev3"
   139   else
   140     verbose_notice "      patch \"$f.patch\" \"$f\""
   141     echo "patch \"$f.patch\" \"$f\"" >> "$filev2"
   142     echo "patch \"$f.patch\" \"$f\"" >> "$filev3"
   143   fi
   144 }
   146 append_remove_instructions() {
   147   dir="$1"
   148   filev2="$2"
   149   filev3="$3"
   151   if [ -f "$dir/removed-files" ]; then
   152     prefix=
   153     listfile="$dir/removed-files"
   154   elif [ -f "$dir/Contents/MacOS/removed-files" ]; then
   155     prefix=Contents/MacOS/
   156     listfile="$dir/Contents/MacOS/removed-files"
   157   fi
   158   if [ -n "$listfile" ]; then
   159     # Map spaces to pipes so that we correctly handle filenames with spaces.
   160     files=($(cat "$listfile" | tr " " "|"  | sort -r))
   161     num_files=${#files[*]}
   162     for ((i=0; $i<$num_files; i=$i+1)); do
   163       # Map pipes back to whitespace and remove carriage returns
   164       f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
   165       # Trim whitespace
   166       f=$(echo $f)
   167       # Exclude blank lines.
   168       if [ -n "$f" ]; then
   169         # Exclude comments
   170         if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
   171           # Normalize the path to the root of the Mac OS X bundle if necessary
   172           fixedprefix="$prefix"
   173           if [ $prefix ]; then
   174             if [ $(echo "$f" | grep -c '^\.\./') = 1 ]; then
   175               if [ $(echo "$f" | grep -c '^\.\./\.\./') = 1 ]; then
   176                 f=$(echo $f | sed -e 's:^\.\.\/\.\.\/::')
   177                 fixedprefix=""
   178               else
   179                 f=$(echo $f | sed -e 's:^\.\.\/::')
   180                 fixedprefix=$(echo "$prefix" | sed -e 's:[^\/]*\/$::')
   181               fi
   182             fi
   183           fi
   184           if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
   185             verbose_notice "      rmdir \"$fixedprefix$f\""
   186             echo "rmdir \"$fixedprefix$f\"" >> "$filev2"
   187             echo "rmdir \"$fixedprefix$f\"" >> "$filev3"
   188           elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
   189             # Remove the *
   190             f=$(echo "$f" | sed -e 's:\*$::')
   191             verbose_notice "    rmrfdir \"$fixedprefix$f\""
   192             echo "rmrfdir \"$fixedprefix$f\"" >> "$filev2"
   193             echo "rmrfdir \"$fixedprefix$f\"" >> "$filev3"
   194           else
   195             verbose_notice "     remove \"$fixedprefix$f\""
   196             echo "remove \"$fixedprefix$f\"" >> "$filev2"
   197             echo "remove \"$fixedprefix$f\"" >> "$filev3"
   198           fi
   199         fi
   200       fi
   201     done
   202   fi
   203 }
   205 # List all files in the current directory, stripping leading "./"
   206 # Pass a variable name and it will be filled as an array.
   207 # To support Tor Browser updates, skip the following files:
   208 #    TorBrowser/Data/Browser/profiles.ini
   209 #    TorBrowser/Data/Browser/profile.default/bookmarks.html
   210 #    TorBrowser/Data/Tor/torrc
   211 list_files() {
   212   count=0
   214   find . -type f \
   215     ! -name "update.manifest" \
   216     ! -name "updatev2.manifest" \
   217     ! -name "updatev3.manifest" \
   218     ! -name "temp-dirlist" \
   219     ! -name "temp-filelist" \
   220     | sed 's/\.\/\(.*\)/\1/' \
   221     | sort -r > "temp-filelist"
   222   while read file; do
   223     if [ "$file" = "TorBrowser/Data/Browser/profiles.ini" -o                   \
   224          "$file" = "TorBrowser/Data/Browser/profile.default/bookmarks.html" -o \
   225          "$file" = "TorBrowser/Data/Tor/torrc" ]; then
   226       continue;
   227     fi
   228     eval "${1}[$count]=\"$file\""
   229     (( count++ ))
   230   done < "temp-filelist"
   231   rm "temp-filelist"
   232 }
   234 # List all directories in the current directory, stripping leading "./"
   235 list_dirs() {
   236   count=0
   238   find . -type d \
   239     ! -name "." \
   240     ! -name ".." \
   241     | sed 's/\.\/\(.*\)/\1/' \
   242     | sort -r > "temp-dirlist"
   243   while read dir; do
   244     eval "${1}[$count]=\"$dir\""
   245     (( count++ ))
   246   done < "temp-dirlist"
   247   rm "temp-dirlist"
   248 }
   250 # List all symbolic links in the current directory, stripping leading "./"
   251 list_symlinks() {
   252   count=0
   254   find . -type l \
   255     | sed 's/\.\/\(.*\)/\1/' \
   256     | sort -r > "temp-symlinklist"
   257   while read symlink; do
   258 	target=$(readlink "$symlink")
   259     eval "${1}[$count]=\"$symlink\""
   260     eval "${2}[$count]=\"$target\""
   261     (( count++ ))
   262   done < "temp-symlinklist"
   263   rm "temp-symlinklist"
   264 }

mercurial