Mercurial > pkg
view 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 source
1 #!/bin/bash2 # Copyright (c) 2000-2006 Matthias S. Benkmann <article AT winterdrache DOT de>3 # You may do everything with this code except misrepresent its origin.4 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!6 # This script will build a package based on the commands in $HOME/build.conf7 # It can be called with the following parameters that8 # will cause it to execute the respective *_commands() functions. If it is9 # called with no parameter, that is equivalent to10 # build unpack patch configure make check install clean11 #12 # It will create 8 log files in the $HOME directory:13 # configure.log: All messages output during configure14 # configure.err: Just the errors output during configure15 # check.log: All messages output during checking16 # check.err: Just the errors output during checking17 # make.log: All messages output during make18 # make.err: Just the errors output during make19 # install.log: All messages output during make install20 # install.err: Just the errors output during make install21 #22 # After running the script you should check the *.err files to see23 # if any problems have occurred. If that is the case, use the corresponding24 # *.log files to see the error messages in context.26 build_script="$(readlink -f "$0")"28 cd # go HOME30 source "$HOME"/build.conf32 if [ "_$(whoami)" != _root ]; then33 export PACKAGE_OWNER="$(whoami)"34 fi37 # This function auto-extracts tarballs based on PATTERNS (see build.conf) inside38 # the directory $HOME/xxxbuild and39 # cds into the fist directory created by the first tarball. This is also40 # stored in the variable $srcdir.41 unpack_commands()42 { :43 export srcdir=""44 rm -rf "$HOME/xxxbuild"45 mkdir -p "$HOME/xxxbuild"46 cd "$HOME/xxxbuild" || return 148 for p in $PATTERNS ; do49 for archive in "$HOME"/*"$p"* ; do50 dir=""51 if [ -f "$archive" ]; then52 case z"$archive" in53 z*.tar.bz2) dir=$(tar tjf "$archive" | grep / | head -n 1) ; tar xjf "$archive" ;;54 z*.tar.gz) dir=$(tar tzf "$archive" | grep / | head -n 1) ; tar xzf "$archive" ;;55 esac56 fi57 dir=${dir##./}58 test -z "$dir" && echo 1>&2 "Error extracting $archive"59 test -z "$srcdir" && srcdir=${dir%%/*}60 done61 done63 test -z "$srcdir" && { echo 1>&2 "Source directory not found" ; return 1 ; }64 ln -s "$srcdir" yyysrc65 }67 clean_commands()68 {69 rm -rf "$HOME/xxxbuild"70 }72 test_pipe()73 {74 for i in "${PIPESTATUS[@]}"75 do76 test $i != 0 && { echo FAILED! ; exit 1 ; }77 done78 echo successful!79 return 080 }82 if [ $# -eq 0 ]; then83 set -- unpack patch configure make check root_pre_install install root_post_install clean84 fi86 while [ -n "$1" ]; do87 case "_$1" in88 _all)89 shift 190 set -- dummy unpack patch configure make check root_pre_install install root_post_install clean "$@"91 ;;93 _unpack)94 echo -n Unpacking...96 unpack_commands # no logging for unpack necessary97 test_pipe98 ;;100 _patch)101 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1102 patch_commands # no logging for patch necessary103 #test_pipe104 ;;106 _configure)107 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1108 echo -n Configuring...110 { configure_commands 3>&1 1>&2 2>&3 | tee "$HOME/configure.err" ;} &>"$HOME/configure.log"111 test_pipe112 # NOTE: Simply using && instead of test_pipe would not work, because &&113 # only tests the exit status of the last command in the pipe, which is tee.114 ;;116 _make)117 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1118 echo -n Building...120 { make_commands 3>&1 1>&2 2>&3 | tee "$HOME/make.err" ;} &>"$HOME/make.log"121 test_pipe122 ;;124 _check)125 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1126 echo -n Checking...128 { check_commands 3>&1 1>&2 2>&3 | tee "$HOME/check.err" ;} &>"$HOME/check.log"129 test_pipe130 ;;132 _root_pre_install)133 if type root_pre_install_commands &>/dev/null ; then134 if [ _$(whoami) != _root ]; then135 su --preserve-environment root -c "HOME='$HOME' '$build_script' root_pre_install" || exit 1136 else137 echo -n "Preparing for install(root)..."139 { root_pre_install_commands 3>&1 1>&2 2>&3 | tee "$HOME/preinstall.err" ;} &>"$HOME/preinstall.log"140 test_pipe141 fi142 fi143 ;;145 _install)146 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1147 echo -n Installing...149 { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/install.err" ;} &>"$HOME/install.log"150 test_pipe151 ;;153 _root_post_install)154 if type root_post_install_commands &>/dev/null ; then155 if [ _$(whoami) != _root ]; then156 su --preserve-environment root -c "HOME='$HOME' '$build_script' root_post_install" || exit 1157 else158 echo -n "Finishing install(root)..."160 { root_post_install_commands 3>&1 1>&2 2>&3 | tee "$HOME/postinstall.err" ;} &>"$HOME/postinstall.log"161 test_pipe162 fi163 fi164 ;;166 _clean)167 cd "$HOME"168 echo -n Cleaning...169 clean_commands170 echo done!171 ;;172 *)173 echo 1>&2 "Unknown command '$1'"174 exit 1175 ;;176 esac177 shift 1178 done