view previous-work/more_control_helpers/etc/build @ 30:f1d0574937b5

minor cosmetic changes.
author Robert McIntyre <rlm@mit.edu>
date Tue, 15 Jan 2013 03:56:59 +0000
parents d6bef198ae71
children
line wrap: on
line source
1 #!/bin/bash
2 # 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.conf
7 # It can be called with the following parameters that
8 # will cause it to execute the respective *_commands() functions. If it is
9 # called with no parameter, that is equivalent to
10 # build unpack patch configure make check install clean
11 #
12 # It will create 8 log files in the $HOME directory:
13 # configure.log: All messages output during configure
14 # configure.err: Just the errors output during configure
15 # check.log: All messages output during checking
16 # check.err: Just the errors output during checking
17 # make.log: All messages output during make
18 # make.err: Just the errors output during make
19 # install.log: All messages output during make install
20 # install.err: Just the errors output during make install
21 #
22 # After running the script you should check the *.err files to see
23 # if any problems have occurred. If that is the case, use the corresponding
24 # *.log files to see the error messages in context.
26 build_script="$(readlink -f "$0")"
28 cd # go HOME
30 source "$HOME"/build.conf
32 if [ "_$(whoami)" != _root ]; then
33 export PACKAGE_OWNER="$(whoami)"
34 fi
37 # This function auto-extracts tarballs based on PATTERNS (see build.conf) inside
38 # the directory $HOME/xxxbuild and
39 # cds into the fist directory created by the first tarball. This is also
40 # 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 1
48 for p in $PATTERNS ; do
49 for archive in "$HOME"/*"$p"* ; do
50 dir=""
51 if [ -f "$archive" ]; then
52 case z"$archive" in
53 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 esac
56 fi
57 dir=${dir##./}
58 test -z "$dir" && echo 1>&2 "Error extracting $archive"
59 test -z "$srcdir" && srcdir=${dir%%/*}
60 done
61 done
63 test -z "$srcdir" && { echo 1>&2 "Source directory not found" ; return 1 ; }
64 ln -s "$srcdir" yyysrc
65 }
67 clean_commands()
68 {
69 rm -rf "$HOME/xxxbuild"
70 }
72 test_pipe()
73 {
74 for i in "${PIPESTATUS[@]}"
75 do
76 test $i != 0 && { echo FAILED! ; exit 1 ; }
77 done
78 echo successful!
79 return 0
80 }
82 if [ $# -eq 0 ]; then
83 set -- unpack patch configure make check root_pre_install install root_post_install clean
84 fi
86 while [ -n "$1" ]; do
87 case "_$1" in
88 _all)
89 shift 1
90 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 necessary
97 test_pipe
98 ;;
100 _patch)
101 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
102 patch_commands # no logging for patch necessary
103 #test_pipe
104 ;;
106 _configure)
107 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
108 echo -n Configuring...
110 { configure_commands 3>&1 1>&2 2>&3 | tee "$HOME/configure.err" ;} &>"$HOME/configure.log"
111 test_pipe
112 # 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 1
118 echo -n Building...
120 { make_commands 3>&1 1>&2 2>&3 | tee "$HOME/make.err" ;} &>"$HOME/make.log"
121 test_pipe
122 ;;
124 _check)
125 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
126 echo -n Checking...
128 { check_commands 3>&1 1>&2 2>&3 | tee "$HOME/check.err" ;} &>"$HOME/check.log"
129 test_pipe
130 ;;
132 _root_pre_install)
133 if type root_pre_install_commands &>/dev/null ; then
134 if [ _$(whoami) != _root ]; then
135 su --preserve-environment root -c "HOME='$HOME' '$build_script' root_pre_install" || exit 1
136 else
137 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_pipe
141 fi
142 fi
143 ;;
145 _install)
146 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1
147 echo -n Installing...
149 { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/install.err" ;} &>"$HOME/install.log"
150 test_pipe
151 ;;
153 _root_post_install)
154 if type root_post_install_commands &>/dev/null ; then
155 if [ _$(whoami) != _root ]; then
156 su --preserve-environment root -c "HOME='$HOME' '$build_script' root_post_install" || exit 1
157 else
158 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_pipe
162 fi
163 fi
164 ;;
166 _clean)
167 cd "$HOME"
168 echo -n Cleaning...
169 clean_commands
170 echo done!
171 ;;
172 *)
173 echo 1>&2 "Unknown command '$1'"
174 exit 1
175 ;;
176 esac
177 shift 1
178 done