tools/update-packaging/test/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 #
    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 BZIP2=${BZIP2:-bzip2}
    16 MBSDIFF=${MBSDIFF:-mbsdiff}
    18 # -----------------------------------------------------------------------------
    19 # Helper routines
    21 notice() {
    22   echo "$*" 1>&2
    23 }
    25 get_file_size() {
    26   info=($(ls -ln "$1"))
    27   echo ${info[4]}
    28 }
    30 copy_perm() {
    31   reference="$1"
    32   target="$2"
    34   if [ -x "$reference" ]; then
    35     chmod 0755 "$target"
    36   else
    37     chmod 0644 "$target"
    38   fi
    39 }
    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=
    56   fi
    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
    67     fi
    68   else
    69     notice "        add \"$f\"$forced"
    70     echo "add \"$f\"" >> $filev2
    71     if [ ! $filev3 = "" ]; then
    72       echo "add \"$f\"" >> $filev3
    73     fi
    74   fi
    75 }
    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;
    84   fi
    85   ## 'false'... because this is bash. Oh yay!
    86   return 1;
    87 }
    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;
    95   fi
    96   ## 'false'... because this is bash. Oh yay!
    97   return 1;
    98 }
   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
   106 }
   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
   125   fi
   126 }
   128 append_remove_instructions() {
   129   dir="$1"
   130   filev2="$2"
   131   filev3="$3"
   133   if [ -f "$dir/removed-files" ]; then
   134     prefix=
   135     listfile="$dir/removed-files"
   136   elif [ -f "$dir/Contents/MacOS/removed-files" ]; then
   137     prefix=Contents/MacOS/
   138     listfile="$dir/Contents/MacOS/removed-files"
   139   fi
   140   if [ -n "$listfile" ]; then
   141     # Map spaces to pipes so that we correctly handle filenames with spaces.
   142     files=($(cat "$listfile" | tr " " "|"  | sort -r))
   143     num_files=${#files[*]}
   144     for ((i=0; $i<$num_files; i=$i+1)); do
   145       # Map pipes back to whitespace and remove carriage returns
   146       f=$(echo ${files[$i]} | tr "|" " " | tr -d '\r')
   147       # Trim whitespace
   148       f=$(echo $f)
   149       # Exclude blank lines.
   150       if [ -n "$f" ]; then
   151         # Exclude comments
   152         if [ ! $(echo "$f" | grep -c '^#') = 1 ]; then
   153           # Normalize the path to the root of the Mac OS X bundle if necessary
   154           fixedprefix="$prefix"
   155           if [ $prefix ]; then
   156             if [ $(echo "$f" | grep -c '^\.\./') = 1 ]; then
   157               if [ $(echo "$f" | grep -c '^\.\./\.\./') = 1 ]; then
   158                 f=$(echo $f | sed -e 's:^\.\.\/\.\.\/::')
   159                 fixedprefix=""
   160               else
   161                 f=$(echo $f | sed -e 's:^\.\.\/::')
   162                 fixedprefix=$(echo "$prefix" | sed -e 's:[^\/]*\/$::')
   163               fi
   164             fi
   165           fi
   166           if [ $(echo "$f" | grep -c '\/$') = 1 ]; then
   167             notice "      rmdir \"$fixedprefix$f\""
   168             echo "rmdir \"$fixedprefix$f\"" >> $filev2
   169             echo "rmdir \"$fixedprefix$f\"" >> $filev3
   170           elif [ $(echo "$f" | grep -c '\/\*$') = 1 ]; then
   171             # Remove the *
   172             f=$(echo "$f" | sed -e 's:\*$::')
   173             notice "    rmrfdir \"$fixedprefix$f\""
   174             echo "rmrfdir \"$fixedprefix$f\"" >> $filev2
   175             echo "rmrfdir \"$fixedprefix$f\"" >> $filev3
   176           else
   177             notice "     remove \"$fixedprefix$f\""
   178             echo "remove \"$fixedprefix$f\"" >> $filev2
   179             echo "remove \"$fixedprefix$f\"" >> $filev3
   180           fi
   181         fi
   182       fi
   183     done
   184   fi
   185 }
   187 # List all files in the current directory, stripping leading "./"
   188 # Pass a variable name and it will be filled as an array.
   189 list_files() {
   190   count=0
   192   # Removed the exclusion cases here to allow for generation of testing mars
   193   find . -type f \
   194     | sed 's/\.\/\(.*\)/\1/' \
   195     | sort -r > "$workdir/temp-filelist"
   196   while read file; do
   197     eval "${1}[$count]=\"$file\""
   198     (( count++ ))
   199   done < "$workdir/temp-filelist"
   200   rm "$workdir/temp-filelist"
   201 }
   203 # List all directories in the current directory, stripping leading "./"
   204 list_dirs() {
   205   count=0
   207   find . -type d \
   208     ! -name "." \
   209     ! -name ".." \
   210     | sed 's/\.\/\(.*\)/\1/' \
   211     | sort -r > "$workdir/temp-dirlist"
   212   while read dir; do
   213     eval "${1}[$count]=\"$dir\""
   214     (( count++ ))
   215   done < "$workdir/temp-dirlist"
   216   rm "$workdir/temp-dirlist"
   217 }

mercurial