Mercurial > pkg
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:0b7a589f6e9a | 1:d6bef198ae71 |
---|---|
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! | |
5 | |
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. | |
25 | |
26 build_script="$(readlink -f "$0")" | |
27 | |
28 cd # go HOME | |
29 | |
30 source "$HOME"/build.conf | |
31 | |
32 if [ "_$(whoami)" != _root ]; then | |
33 export PACKAGE_OWNER="$(whoami)" | |
34 fi | |
35 | |
36 | |
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 | |
47 | |
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 | |
62 | |
63 test -z "$srcdir" && { echo 1>&2 "Source directory not found" ; return 1 ; } | |
64 ln -s "$srcdir" yyysrc | |
65 } | |
66 | |
67 clean_commands() | |
68 { | |
69 rm -rf "$HOME/xxxbuild" | |
70 } | |
71 | |
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 } | |
81 | |
82 if [ $# -eq 0 ]; then | |
83 set -- unpack patch configure make check root_pre_install install root_post_install clean | |
84 fi | |
85 | |
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 ;; | |
92 | |
93 _unpack) | |
94 echo -n Unpacking... | |
95 | |
96 unpack_commands # no logging for unpack necessary | |
97 test_pipe | |
98 ;; | |
99 | |
100 _patch) | |
101 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1 | |
102 patch_commands # no logging for patch necessary | |
103 #test_pipe | |
104 ;; | |
105 | |
106 _configure) | |
107 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1 | |
108 echo -n Configuring... | |
109 | |
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 ;; | |
115 | |
116 _make) | |
117 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1 | |
118 echo -n Building... | |
119 | |
120 { make_commands 3>&1 1>&2 2>&3 | tee "$HOME/make.err" ;} &>"$HOME/make.log" | |
121 test_pipe | |
122 ;; | |
123 | |
124 _check) | |
125 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1 | |
126 echo -n Checking... | |
127 | |
128 { check_commands 3>&1 1>&2 2>&3 | tee "$HOME/check.err" ;} &>"$HOME/check.log" | |
129 test_pipe | |
130 ;; | |
131 | |
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)..." | |
138 | |
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 ;; | |
144 | |
145 _install) | |
146 cd "$HOME/xxxbuild/yyysrc" && srcdir="$(pwd)" || exit 1 | |
147 echo -n Installing... | |
148 | |
149 { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/install.err" ;} &>"$HOME/install.log" | |
150 test_pipe | |
151 ;; | |
152 | |
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)..." | |
159 | |
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 ;; | |
165 | |
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 |