diff previous-work/more_control_helpers/etc/build @ 1:d6bef198ae71

add work by Matthias S. Benkmann which is the inspiration for this project.
author Robert McIntyre <rlm@mit.edu>
date Tue, 08 Jan 2013 11:45:01 +0000
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/previous-work/more_control_helpers/etc/build	Tue Jan 08 11:45:01 2013 +0000
     1.3 @@ -0,0 +1,178 @@
     1.4 +#!/bin/bash
     1.5 +# Copyright (c) 2000-2006 Matthias S. Benkmann <article AT winterdrache DOT de>
     1.6 +# You may do everything with this code except misrepresent its origin.
     1.7 +# PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
     1.8 +
     1.9 +# This script will build a package based on the commands in $HOME/build.conf
    1.10 +# It can be called with the following parameters that
    1.11 +# will cause it to execute the respective *_commands() functions. If it is
    1.12 +# called with no parameter, that is equivalent to
    1.13 +# build unpack patch configure make check install clean
    1.14 +#
    1.15 +# It will create 8 log files in the $HOME directory:
    1.16 +#   configure.log: All messages output during configure
    1.17 +#   configure.err: Just the errors output during configure
    1.18 +#   check.log: All messages output during checking
    1.19 +#   check.err: Just the errors output during checking
    1.20 +#   make.log: All messages output during make
    1.21 +#   make.err: Just the errors output during make
    1.22 +#   install.log: All messages output during make install
    1.23 +#   install.err: Just the errors output during make install
    1.24 +#
    1.25 +# After running the script you should check the *.err files to see
    1.26 +# if any problems have occurred. If that is the case, use the corresponding
    1.27 +# *.log files to see the error messages in context.
    1.28 +
    1.29 +build_script="$(readlink -f "$0")"
    1.30 +
    1.31 +cd  # go HOME
    1.32 +
    1.33 +source "$HOME"/build.conf
    1.34 +
    1.35 +if [ "_$(whoami)" != _root ]; then
    1.36 +  export PACKAGE_OWNER="$(whoami)"
    1.37 +fi
    1.38 +
    1.39 +
    1.40 + # This function auto-extracts tarballs based on PATTERNS (see build.conf) inside
    1.41 + # the directory $HOME/xxxbuild and
    1.42 + # cds into the fist directory created by the first tarball. This is also
    1.43 + # stored in the variable $srcdir.
    1.44 +unpack_commands()
    1.45 +{ :
    1.46 +  export srcdir=""
    1.47 +  rm -rf "$HOME/xxxbuild"
    1.48 +  mkdir -p "$HOME/xxxbuild" 
    1.49 +  cd "$HOME/xxxbuild" || return 1
    1.50 +  
    1.51 +  for p in $PATTERNS ; do
    1.52 +    for archive in "$HOME"/*"$p"* ; do
    1.53 +      dir=""
    1.54 +      if [ -f "$archive" ]; then
    1.55 +        case z"$archive" in
    1.56 +          z*.tar.bz2) dir=$(tar tjf "$archive" | grep / | head -n 1) ; tar xjf "$archive"  ;;
    1.57 +          z*.tar.gz)  dir=$(tar tzf "$archive" | grep / | head -n 1) ; tar xzf "$archive"  ;;
    1.58 +        esac
    1.59 +      fi
    1.60 +      dir=${dir##./}
    1.61 +      test -z "$dir" && echo 1>&2 "Error extracting $archive"
    1.62 +      test -z "$srcdir" && srcdir=${dir%%/*}
    1.63 +    done
    1.64 +  done
    1.65 +  
    1.66 +  test -z "$srcdir" && { echo 1>&2 "Source directory not found" ; return 1 ; }
    1.67 +  ln -s "$srcdir" yyysrc
    1.68 +}
    1.69 +
    1.70 +clean_commands()
    1.71 +{
    1.72 +  rm -rf "$HOME/xxxbuild"
    1.73 +}
    1.74 +
    1.75 +test_pipe()
    1.76 +{
    1.77 +  for i in "${PIPESTATUS[@]}" 
    1.78 +  do
    1.79 +    test $i != 0 && { echo FAILED! ; exit 1 ; }
    1.80 +  done
    1.81 +  echo successful!
    1.82 +  return 0
    1.83 +}
    1.84 +
    1.85 +if [ $# -eq 0 ]; then
    1.86 +  set -- unpack patch configure make check root_pre_install install root_post_install clean
    1.87 +fi
    1.88 +
    1.89 +while [ -n "$1" ]; do
    1.90 +  case "_$1" in
    1.91 +    _all)
    1.92 +        shift 1
    1.93 +        set -- dummy unpack patch configure make check root_pre_install install root_post_install clean "$@"
    1.94 +        ;;
    1.95 +        
    1.96 +    _unpack)
    1.97 +        echo -n Unpacking...
    1.98 +
    1.99 +        unpack_commands # no logging for unpack necessary 
   1.100 +        test_pipe
   1.101 +        ;;
   1.102 +   
   1.103 +    _patch)
   1.104 +        cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
   1.105 +        patch_commands # no logging for patch necessary 
   1.106 +        #test_pipe
   1.107 +        ;;
   1.108 +
   1.109 +    _configure)
   1.110 +        cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
   1.111 +        echo -n Configuring...
   1.112 +
   1.113 +        { configure_commands 3>&1 1>&2 2>&3 | tee "$HOME/configure.err" ;} &>"$HOME/configure.log"
   1.114 +        test_pipe
   1.115 +        # NOTE: Simply using && instead of test_pipe would not work, because &&
   1.116 +        # only tests the exit status of the last command in the pipe, which is tee.
   1.117 +        ;;
   1.118 +
   1.119 +    _make)
   1.120 +        cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
   1.121 +        echo -n Building...
   1.122 +
   1.123 +        { make_commands 3>&1 1>&2 2>&3 | tee "$HOME/make.err" ;} &>"$HOME/make.log"
   1.124 +        test_pipe
   1.125 +        ;;
   1.126 +
   1.127 +    _check)
   1.128 +        cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
   1.129 +        echo -n Checking...
   1.130 +
   1.131 +        { check_commands 3>&1 1>&2 2>&3 | tee "$HOME/check.err" ;} &>"$HOME/check.log"
   1.132 +        test_pipe
   1.133 +        ;;
   1.134 +    
   1.135 +    _root_pre_install)
   1.136 +        if type root_pre_install_commands &>/dev/null ; then
   1.137 +          if [ _$(whoami) != _root ]; then
   1.138 +            su --preserve-environment root -c "HOME='$HOME' '$build_script' root_pre_install" || exit 1
   1.139 +          else  
   1.140 +            echo -n "Preparing for install(root)..."
   1.141 +  
   1.142 +            { root_pre_install_commands 3>&1 1>&2 2>&3 | tee "$HOME/preinstall.err" ;} &>"$HOME/preinstall.log"
   1.143 +            test_pipe
   1.144 +          fi  
   1.145 +        fi
   1.146 +        ;;
   1.147 +        
   1.148 +    _install)
   1.149 +        cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
   1.150 +        echo -n Installing...
   1.151 +
   1.152 +        { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/install.err" ;} &>"$HOME/install.log"
   1.153 +        test_pipe
   1.154 +        ;;
   1.155 +    
   1.156 +    _root_post_install)
   1.157 +        if type root_post_install_commands &>/dev/null ; then
   1.158 +          if [ _$(whoami) != _root ]; then
   1.159 +            su --preserve-environment root -c "HOME='$HOME' '$build_script' root_post_install" || exit 1
   1.160 +          else  
   1.161 +            echo -n "Finishing install(root)..."
   1.162 +  
   1.163 +            { root_post_install_commands 3>&1 1>&2 2>&3 | tee "$HOME/postinstall.err" ;} &>"$HOME/postinstall.log"
   1.164 +            test_pipe
   1.165 +          fi  
   1.166 +        fi  
   1.167 +        ;;
   1.168 +        
   1.169 +    _clean)
   1.170 +        cd "$HOME"
   1.171 +        echo -n Cleaning...
   1.172 +        clean_commands
   1.173 +        echo done!
   1.174 +        ;;
   1.175 +    *)
   1.176 +        echo 1>&2 "Unknown command '$1'"
   1.177 +        exit 1
   1.178 +        ;;
   1.179 +  esac       
   1.180 +  shift 1
   1.181 +done