Added quiet option to all git commands.
authoretrunko <eblima@gmail.com>
Wed, 5 Dec 2007 21:13:25 +0000 (21:13 +0000)
committeretrunko <eblima@gmail.com>
Wed, 5 Dec 2007 21:13:25 +0000 (21:13 +0000)
Added -c option, to skip the update of source repositories.
Added check_distro() to set distro/arch dependent variables.
More sanity checks.
Be a bit more verbose.

trunk/build-all.sh

index 127bd86..43aef8a 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
 source "helper-functions.sh"
+
+###########################################################
+# Variable definitions
+###########################################################
 __this_script=`basename $0`
 __this_script_dir=`dirname $0`
 
@@ -13,9 +17,10 @@ __sed=`which sed`
 __uname=`which uname`
 
 # git definitions
-__git_clone="$__git clone"
-__git_pull="$__git pull"
-__git_clean="$__git clean"
+__git_clone="$__git clone -q"
+__git_pull="$__git pull -q -n"
+__git_clean="$__git clean -q -x -d"
+
 __git_repo="git://staff.get-e.org/"
 
 # e17 repositories paths
@@ -31,26 +36,23 @@ __python_modules="python-evas:python-ecore:python-edje:python-epsilon:python-e_d
 __python_etk_module="python-etk"
 
 # dpkg definitions
-__arch=`$__uname -m`
 __common_build_pkg_options="-rfakeroot -us -uc -D -tc"
-__build_pkg_options="$__common_build_pkg_options -sa"
-if [ "x$__arch" = "xarm" ] ; then
-    __build_pkg_options="$__common_build_pkg_options -B"
-fi
-
-# Distro
-__distro=`$__head -1 /etc/apt/sources.list|cut -d" " -f3`
 
 # Packages dirs and log file
 __today=`$__date +%Y%m%d`
 __base_pkg_dir="$__this_script_dir/packages_$__today"
-__pkg_dir="$__base_pkg_dir/$__distro/$__arch"
 __output_file="$PWD/$__base_pkg_dir/packages_$__today.log"
 
 # Scratchbox definitions
 __scratchbox=/scratchbox
 
+# Other
+__update_repositories=1
+
+###########################################################
 # Function definitions
+###########################################################
+
 function usage() {
     cat << EOF
 
@@ -59,12 +61,23 @@ Usage: $__this_script [OPTIONS]
 Build script for EFL debian packages for Maemo.
 
 Options:
+    -c      Don't update source repositories.
     -h      Show this usage guide.
     -s PATH Specify alternate scratchbox path (default: $__scratchbox).
 
 EOF
 }
 
+function create_log_file() {
+    if [ ! -r $__output_file ]; then
+        msg_begin "Creating log file"
+        touch $__output_file
+        msg_end $?
+    else
+        msg "Using existing log file: $__output_file"
+    fi
+}
+
 function log_to_file() {
     local now
     local msg
@@ -82,13 +95,7 @@ function start_log() {
     local now
     now=`$__date -R`
 
-    if [ ! -r $__output_file ]; then
-        msg_begin "Creating log file"
-        touch $__output_file
-        msg_end $?
-    else
-        echo "" >> $__output_file
-    fi
+    echo "" >> $__output_file
 
     if [ $? != 0 ] ; then
         error "start_log(): Could not create $__output_file file"
@@ -123,16 +130,17 @@ EOF
 function clone() {
     local repo
     repo=$1
-    `$__git_clone $repo.git 2>&1>> $__output_file`
+    `$__git_clone $repo.git 2>&1 >> $__output_file`
     return $?
 }
 
 function pull() {
-    `$__git_pull 2>&1>> $__output_file`
+    `$__git_pull 2>&1 >> $__output_file`
     return $?
 }
 
 function clean() {
+    `$__git_clean 2>&1>> $__output_file`
     return $?
 }
 
@@ -159,12 +167,16 @@ function get_sources() {
 
     for module in $modules; do
         if [ -d $module/$module/.git ]; then
-            log_to_file "Updating existing repository at $PWD/$module/$module"
-            cd $module/$module
-            msg_begin "  Updating $module repository"
-            pull
-            msg_end $?
-            cd - 2>&1 >> /dev/null
+            if [ ! $__update_repositories -eq 0 ]; then
+                log_to_file "Updating existing repository at $PWD/$module/$module"
+                cd $module/$module
+                msg_begin "  Updating $module repository"
+                pull
+                msg_end $?
+                cd - 2>&1 >> /dev/null
+            else
+                log_to_file "Skipping update of $module repository"
+            fi
         elif [ -d $module/$module ]; then
             log_to_file "Removing invalid repository at $PWD/$module/$module"
             rm -rf $module/$module
@@ -182,9 +194,55 @@ function get_sources() {
     done
 }
 
-# Verify options
-while getopts "hs" opt ; do
+# XXX: FIXME Figure out a better way to get the distro string
+function check_distro() {
+    local target
+    local sources_list_file
+    local target_conf_file
+    local ret
+    target=$1
+    sources_list_file=$__scratchbox/users/$USER/targets/$target/etc/apt/sources.list
+    target_conf_file=$__scratchbox/users/$USER/targets/$target.config
+    ret=1
+
+    log_to_file "check_distro(): Target $target"
+    log_to_file "check_distro(): sources.list file : $sources_list_file"
+    log_to_file "check_distro(): config file: $target_conf_file"
+
+    if [ "x$target" != "x" ] && [ -r $sources_list_file ] && [ -r $target_conf_file ]; then
+        __distro=`$__head -1 $sources_list_file|cut -d" " -f3`
+        __arch=`grep SBOX_CPU= $target_conf_file|cut -d= -f2`
+        __pkg_dir="$__base_pkg_dir/$__distro/$__arch"
+        __build_pkg_options="$__common_build_pkg_options -sa"
+        if [ "x$__arch" = "xarm" ] ; then
+            __build_pkg_options="$__common_build_pkg_options -B"
+        fi
+        ret=0
+    fi
+
+    if [ $ret -eq 0 ]; then
+        log_to_file "check_distro(): Configuration:"
+        log_to_file "check_distro(): distro...........: $__distro"
+        log_to_file "check_distro(): arch.............: $__arch"
+        log_to_file "check_distro(): build options....: $__build_pkg_options"
+        log_to_file "check_distro(): pkg_dir..........: $__pkg_dir"
+    fi
+
+    log_to_file "check_distro(): Returning $ret"
+
+    return $ret
+}
+
+###########################################################
+# Begin script
+###########################################################
+
+# Parse comand line options
+while getopts "chs" opt ; do
     case "$opt" in
+        c)
+            __update_repositories=0
+            ;;
         h)
             usage
             exit 0
@@ -201,20 +259,20 @@ done
 
 # Initial checks
 
-# Distro variable must not be empty
-msg_begin "Checking maemo distro"
-test "x$__distro" != "x"
-msg_end $?
-
 # Check if we're running inside scratchbox
-msg_begin "Checking for scratchbox environment"
-test -r /targets/links/scratchbox.config
-msg_end $?
+if [ -r /targets/links/scratchbox.config ]; then
+    error "You should run this script ouside the scratchbox environment."
+fi
+
+# Create base packages dir
+if [ ! -d $__base_pkg_dir ]; then
+    msg_begin "Creating base packages dir $__base_pkg_dir"
+    $__mkdir -p $__base_pkg_dir
+    msg_end $?
+fi
 
-# Create packages dir and log file
-$__mkdir -p $__pkg_dir
-start_log
-log_to_file "Created $__pkg_dir"
+# Create log file
+create_log_file
 
 # Download modules under e17/libs
 msg "Downloading e17 modules"
@@ -227,17 +285,29 @@ get_sources $__python_modules $__git_repo$__e17_python_efl
 # Download python-etk module
 get_sources $__python_etk_module $__git_repo$__e17_python_etk
 
-# Build package
+# For each scratchbox target
+for target in `$__scratchbox/tools/bin/sb-conf list --targets`; do
+    msg_begin "Checking distro and arch for target $target"
+    check_distro $target
+    msg_end $?
 
-# Install package
+    msg "  Distribution..: $__distro"
+    msg "  Architecture..: $__arch"
+    msg "  Build Options.: $__build_pkg_options"
 
-# Download user modules (python-etk)
+    if [ ! -d $__pkg_dir ]; then
+        msg_begin "Creating dir for $__distro $__arch packages"
+        $__mkdir -p $__pkg_dir
+        msg_end $?
+    fi
+    # Build package
 
-# Build package
+    # Install packages
 
-# Install package
+    # Clean tree
 
-# Uninstall all packages
+done
 
+# Uninstall all packages
 # END
 finish_log