Gentoo Archives: gnap-dev

From: Philipp Riegger <lists@××××××××××××.de>
To: gnap-dev@l.g.o
Subject: [gnap-dev] [PATCH 4/4] GNAP environment
Date: Fri, 03 Aug 2007 13:58:02
Message-Id: 1186149212.10651.51.camel@b136a
In Reply to: [gnap-dev] [PATCH 0/4] GNAP improvements, probably for 2.1 by Philipp Riegger
1 This cleans up the way gnap_* scripts get their information. Since i
2 mostly worked on gnap_make this is optimized for gnap_make and the other
3 scripts are only changed in the same way. In gnap_make we have the
4 following sources of configuration:
5
6 - The command line
7 - common.conf
8 - catalyst.conf
9 - the environment
10
11 Until now, catalyst.conf was used for... i don't know, it was sourced
12 but not really used, i think. common.conf was used for all the arch
13 specific stuff, that has to be passed to catalyst. The command line was
14 used for most of the configuration options, including the location of
15 common.conf and catalyst.conf.
16
17 The new behavior is the following:
18
19 gnap_make and gnap_shared specify default values for all the GNAP_
20 variables (sometimes undef is default). This can be overwritten by
21 environment variables (export GNAP_LIBDIR=/home/test/foo/bar for
22 specifying the place of all the gnap files for testing new
23 configurations, export GNAP_CATALYST_BIN="echo catalyst" for only
24 getting the configurations created by gnap_make and not building the
25 stuff come to mind), next the spec location is read from command line if
26 available and common.conf is sourced, the catalyst.conf info is read
27 from the command line if available and the file is sourced, the rest of
28 the command line is read and sets/overwrites whatever is given there.
29
30 With this you can:
31 - add GNAP_ options to catalyst.conf (DON'T DO THAT)
32 - add GNAP_ options to common.conf (shorter command line, nice)
33 - add GNAP_ options to the environment (GNAP_LIBDIR since we only use
34 tha lates testing stuff located in /home/somewhere, whatever you want)
35 - have new problems because you don't know why a special option is set.
36 Well, if you are advanced enough to make such a mess, you are advanced
37 enough for cat, grep, export -p and set -x to debug that.
38
39 Before i gorget it: I also did some more cleanup here. I was too lazy to
40 apply it to all the previous branches that it would be in the -cleanup
41 patch, i hope you can live with that.
42
43 Enjoy,
44 Philipp
45
46
47 diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
48 +cleanup+split+namespace/src/gnap_make gnap-2.0+cleanup+split+namespace
49 +environment/src/gnap_make
50 --- gnap-2.0+cleanup+split+namespace/src/gnap_make 2007-08-02
51 15:50:45.000000000 +0300
52 +++ gnap-2.0+cleanup+split+namespace+environment/src/gnap_make
53 2007-08-02 15:46:54.000000000 +0300
54 @@ -1,7 +1,7 @@
55 #!/bin/bash
56 VERSION='2.0'
57
58 -GNAP_LIBDIR='/usr/lib/gnap'
59 +GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
60 source ${GNAP_LIBDIR}/gnap_shared.sh
61 echo "GNAP Core Building tool ${NAME} version ${VERSION}"
62
63 @@ -25,65 +25,31 @@
64 exit 0
65 fi
66
67 -gbegin 'Checking parameters'
68 -
69 # Catalyst executable and config file
70 -GNAP_CATALYST_BIN="/usr/bin/catalyst"
71 -GNAP_CATALYST_CONF="/etc/catalyst/catalyst.conf"
72 +GNAP_CATALYST_BIN=${GNAP_CATALYST_BIN:-"/usr/bin/catalyst"}
73 +GNAP_CATALYST_CONF=${GNAP_CATALYST_CONF:-"/etc/catalyst/catalyst.conf"}
74
75 -# Read options
76 -GNAP_STAGE3=0
77 -GNAP_LIVECD1=0
78 -GNAP_LIVECD2=0
79 -GNAP_TARBALL=0
80 -GNAP_MODULES=0
81 -GNAP_STAMP=$(date +%Y%m%d)
82 -NOTARGET=1
83 -NEEDS_SNAPSHOT=0
84 +# Default options
85 +GNAP_STAMP=${GNAP_STAMP:-$(date +%Y%m%d)}
86 +
87 +# Read options (phase 1)
88 +gbegin 'Checking parameters'
89 +
90 +OPTIND=0
91 while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
92 case ${option} in
93 - h )
94 + h )
95 + gtest
96 usage
97 exit 0;;
98 - s ) GNAP_STAGE3FILE="${OPTARG}";;
99 - p ) GNAP_SNAPSHOTFILE="${OPTARG}";;
100 - o ) GNAP_PORTAGE_OVERLAYS="${GNAP_PORTAGE_OVERLAYS} ${OPTARG}";;
101 - v ) GNAP_STAMP="${OPTARG}";;
102 - t )
103 - case "${OPTARG}" in
104 - all )
105 - GNAP_STAGE3=1
106 - GNAP_LIVECD1=1
107 - GNAP_LIVECD2=1
108 - GNAP_TARBALL=1
109 - GNAP_MODULES=1
110 - NEEDS_SNAPSHOT=1;;
111 - stage3 )
112 - GNAP_STAGE3=1
113 - NEEDS_SNAPSHOT=1;;
114 - livecd-stage1 )
115 - GNAP_LIVECD1=1
116 - NEEDS_SNAPSHOT=1;;
117 - livecd-stage2 )
118 - GNAP_LIVECD2=1
119 - NEEDS_SNAPSHOT=1;;
120 - tarball )
121 - GNAP_TARBALL=1;;
122 - extensions )
123 - GNAP_MODULES=1
124 - NEEDS_SNAPSHOT=1;;
125 - * ) gtest 1 'Specified stage is unknown!';;
126 - esac
127 - NOTARGET=0;;
128 - f ) GNAP_FORCEYES=1;;
129 - l ) GNAP_LOGPREFIX="${OPTARG}";;
130 - c ) GNAP_CATALYST_CONF="${OPTARG}";;
131 e ) GNAP_SPECS="${OPTARG}";;
132 + s|p|o|v|t|f|l|c ) :;;
133 * ) gtest 1 'Specified options are incomplete or unknown!';;
134 esac
135 done
136
137 # Root is needed
138 +# * non-root can only use "gnap_make -h"
139 test "${EUID}" -eq 0
140 gtest continued $? "You need to be root to run ${NAME}"
141
142 @@ -113,15 +79,71 @@
143 DISTCCSPEC="distcc_hosts: ${DISTCC_HOSTS}"
144 fi
145
146 +
147 +# Read options (phase 2)
148 +OPTIND=0
149 +while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
150 + case ${option} in
151 + c ) GNAP_CATALYST_CONF="${OPTARG}";;
152 + s|p|o|v|t|f|l|e|h ) :;;
153 + * ) gtest 1 'Specified options are incomplete or unknown!';;
154 + esac
155 +done
156 +
157 # catalyst.conf file
158 test -f "${GNAP_CATALYST_CONF}"
159 gtest continued $? "${GNAP_CATALYST_CONF} file not found!"
160 source "${GNAP_CATALYST_CONF}"
161
162 +# Read options (phase 3)
163 +OPTIND=0
164 +while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
165 + case ${option} in
166 + s ) GNAP_STAGE3FILE="${OPTARG}";;
167 + p ) GNAP_SNAPSHOTFILE="${OPTARG}";;
168 + o ) GNAP_PORTAGE_OVERLAYS="${GNAP_PORTAGE_OVERLAYS} ${OPTARG}";;
169 + v ) GNAP_STAMP="${OPTARG}";;
170 + t )
171 + case "${OPTARG}" in
172 + all )
173 + GNAP_STAGE3=1
174 + GNAP_LIVECD1=1
175 + GNAP_LIVECD2=1
176 + GNAP_TARBALL=1
177 + GNAP_MODULES=1;;
178 + stage3 ) GNAP_STAGE3=1;;
179 + livecd-stage1 ) GNAP_LIVECD1=1;;
180 + livecd-stage2 ) GNAP_LIVECD2=1;;
181 + tarball ) GNAP_TARBALL=1;;
182 + extensions ) GNAP_MODULES=1;;
183 + * ) gtest 1 'Specified stage is unknown!';;
184 + esac;;
185 + f ) GNAP_FORCEYES=1;;
186 + l ) GNAP_LOGPREFIX="${OPTARG}";;
187 + c|e|h ) :;;
188 + * ) gtest 1 'Specified options are incomplete or unknown!';;
189 + esac
190 +done
191 +
192 # At least one target is needed
193 -test "${NOTARGET}" -eq 0
194 -gtest continued $? \
195 +test "${GNAP_STAGE3}" -eq 0 &&
196 +test "${GNAP_LIVECD1}" -eq 0 &&
197 +test "${GNAP_LIVECD2}" -eq 0 &&
198 +test "${GNAP_TARBALL}" -eq 0 &&
199 +test "${GNAP_MODULES}" -eq 0
200 +if [[ $? -eq 0 ]]; then
201 + gtest continued 1 \
202 'No target specified. You should provide at least one -t option.'
203 +fi
204 +
205 +NEEDS_SNAPSHOT=0
206 +test "${GNAP_STAGE3}" -eq 1 ||
207 +test "${GNAP_LIVECD1}" -eq 1 ||
208 +test "${GNAP_LIVECD2}" -eq 1 ||
209 +test "${GNAP_MODULES}" -eq 1
210 +if [[ $? -eq 0 ]]; then
211 + NEEDS_SNAPSHOT=1
212 +fi
213
214 # storedir must exist
215 gmkdir "${storedir}"
216 diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
217 +cleanup+split+namespace/tools/gnap_overlay gnap-2.0+cleanup+split
218 +namespace+environment/tools/gnap_overlay
219 --- gnap-2.0+cleanup+split+namespace/tools/gnap_overlay 2007-07-27
220 16:00:02.000000000 +0300
221 +++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_overlay
222 2007-07-31 23:22:33.000000000 +0300
223 @@ -1,7 +1,7 @@
224 #!/bin/bash
225 VERSION='2.0'
226
227 -GNAP_LIBDIR='/usr/lib/gnap'
228 +GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
229 source ${GNAP_LIBDIR}/gnap_shared.sh
230 echo "GNAP overlay tool ${NAME} ${VERSION}"
231
232 @@ -42,19 +42,14 @@
233 exit 0
234 fi
235
236 -gbegin 'Checking parameters'
237 +# Default settings
238 +GNAP_NOLOGO=${GNAP_NOLOGO:-0}
239 +GNAP_CREATE=${GNAP_CREATE:-'n'}
240 +GNAP_IMG_SIZE=${GNAP_IMG_SIZE:-15}
241
242 # Read options
243 -GNAP_NOLOGO=0
244 -GNAP_FORCEYES=0
245 -GNAP_OUTPUT=''
246 -GNAP_TYPE=''
247 -GNAP_CREATE='n'
248 -GNAP_IMG_SIZE=15
249 -GNAP_TARGETROOT=''
250 -GNAP_CACHE=''
251 -GNAP_SERIAL=''
252 -GNAP_BAUDRATE=''
253 +gbegin 'Checking parameters'
254 +
255 while getopts ':hg:o:c:nfi:d:l:r:ms:S:L:' option; do
256 case ${option} in
257 h ) usage
258 diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
259 +cleanup+split+namespace/tools/gnap_remaster gnap-2.0+cleanup+split
260 +namespace+environment/tools/gnap_remaster
261 --- gnap-2.0+cleanup+split+namespace/tools/gnap_remaster 2007-07-27
262 16:17:48.000000000 +0300
263 +++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_remaster
264 2007-07-31 23:29:03.000000000 +0300
265 @@ -1,12 +1,10 @@
266 #!/bin/bash
267 VERSION='2.0'
268
269 -GNAP_LIBDIR='/usr/lib/gnap'
270 +GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
271 source ${GNAP_LIBDIR}/gnap_shared.sh
272 echo "GNAP remastering tool ${NAME} ${VERSION}"
273
274 -GNAP_OUTPUT='mygnap-core.tar'
275 -
276 usage() {
277 echo
278 echo 'Usage:'
279 @@ -33,12 +31,8 @@
280 gbegin 'Checking parameters'
281
282 # Read options
283 -GNAP_EXTENSIONS=''
284 -GNAP_KERNEXT=''
285 -GNAP_MODEXT=''
286 -GNAP_BASEFS=''
287 -GNAP_EXTDIR=''
288 -GNAP_FORCEYES=0
289 +GNAP_OUTPUT=${GNAP_OUTPUT:-'mygnap-core.tar'}
290 +
291 while getopts ':he:k:m:o:g:b:d:f' option; do
292 case ${option} in
293 h ) usage
294 diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
295 +cleanup+split+namespace/tools/gnap_shared.sh gnap-2.0+cleanup+split
296 +namespace+environment/tools/gnap_shared.sh
297 --- gnap-2.0+cleanup+split+namespace/tools/gnap_shared.sh 2007-08-02
298 15:51:30.000000000 +0300
299 +++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_shared.sh
300 2007-08-02 15:46:44.000000000 +0300
301 @@ -6,34 +6,44 @@
302 gnap_remaster ) GNAP_PRODUCT="Remaster";;
303 * ) GNAP_PRODUCT="Something";;
304 esac
305 -GNAP_STAGE3FILE="${GNAP_LIBDIR}/gnap-stage3seed.tar.bz2"
306 -GNAP_SNAPSHOTFILE="${GNAP_LIBDIR}/gnap-portagesnapshot.tar.bz2"
307 -GNAP_SPECS="${GNAP_LIBDIR}/gnap-specs.tar.bz2"
308 -GNAP_CORE="${GNAP_LIBDIR}/gnap-core.tar"
309 -GNAP_MBR="${GNAP_LIBDIR}/mbr/mbr.bin"
310 -GNAP_EXTDIR="${GNAP_LIBDIR}/extensions"
311 -GNAP_BASEFS="${GNAP_LIBDIR}/gnap-basefs.tar.bz2"
312
313 -GNAP_FORCEYES=0
314 +GNAP_STAGE3FILE=
315 ${GNAP_STAGE3FILE:-"${GNAP_LIBDIR}/gnap-stage3seed.tar.bz2"}
316 +GNAP_SNAPSHOTFILE=
317 ${GNAP_SNAPSHOTFILE:-"${GNAP_LIBDIR}/gnap-portagesnapshot.tar.bz2"}
318 +GNAP_SPECS=${GNAP_SPECS:-"${GNAP_LIBDIR}/gnap-specs.tar.bz2"}
319 +GNAP_CORE=${GNAP_CORE:-"${GNAP_LIBDIR}/gnap-core.tar"}
320 +GNAP_MBR=${GNAP_MBR:-"${GNAP_LIBDIR}/mbr/mbr.bin"}
321 +GNAP_EXTDIR=${GNAP_EXTDIR:-"${GNAP_LIBDIR}/extensions"}
322 +GNAP_BASEFS=${GNAP_BASEFS:-"${GNAP_LIBDIR}/gnap-basefs.tar.bz2"}
323 +
324 +GNAP_FORCEYES=${GNAP_FORCEYES:-0}
325 +
326 +#CONTINUED=0
327 TEMPDIR=''
328 LOOP=''
329
330 -G=$'\e[32;01m'
331 -B=$'\e[31;01m'
332 -N=$'\e[0m'
333 -W=$'\e[33;01m'
334 -K=$'\e[34;01m'
335 -C="$[$(set -- $(stty size 2>/dev/null); echo ${2}) - 7]"
336 -E=$'\e['${C}'G'
337 +G=$'\e[32;01m' # green
338 +B=$'\e[31;01m' # red
339 +N=$'\e[0m' # neutral
340 +W=$'\e[33;01m' # yellow
341 +K=$'\e[34;01m' # blue
342 +C="$[$(set -- $(stty size 2>/dev/null); echo ${2}) - 7]" # end of line
343 helper
344 +E=$'\e['${C}'G' # end of line
345 +
346 +ginfo() {
347 + echo -e " ${G}*${N} ${*}"
348 +}
349
350 gwarn() {
351 echo -e " ${W}*${N} ${*}"
352 }
353
354 -ginfo() {
355 - echo -e " ${G}*${N} ${*}"
356 +gdie() {
357 + echo -e " ${B}*${N} ${*}"
358 + cleanup
359 + exit 1
360 }
361
362 +
363 gmkdir() {
364 mkdir -p "$1"
365 gtest continued $? "Failed to create \"$1\"."
366 @@ -44,29 +54,31 @@
367 gwarn "${*} forced to yes"
368 else
369 read -ep " ${W}*${N} ${*} [N]: " answer
370 - if [[ "${answer}" != 'y' && "${answer}" != 'Y' ]]; then
371 - if [[ -n "${TEMPDIR}" || -n "${LOOP}" ]]; then
372 - cleanup
373 - fi
374 - echo '${GNAP_PRODUCT} aborted!'
375 - exit 2
376 - fi
377 + [[ "${answer}" != 'y' && "${answer}" != 'Y' ]] && \
378 + gdie "${GNAP_PRODUCT} aborted!"
379 fi
380 }
381
382 gbegin() {
383 +# [[ "${CONTINUED}" -eq 1 ]] && gdie "BUG triggered by gbegin()"
384 +
385 echo -ne " ${G}*${N} ${*}..."
386 +# CONTINUED=1
387 }
388
389 gtest() {
390 - continued=0
391 +# # TODO: Remove this after removing all "gtest continued"
392 +# if [[ "${#}" -gt 0 && "${1}" == 'continued' ]]; then
393 +# shift
394 +# fi
395 + CONTINUED=0
396 if [[ "${#}" -gt 0 && "${1}" == 'continued' ]]; then
397 + CONTINUED=1
398 shift
399 - continued=1
400 fi
401
402 if [[ "${#}" -eq 0 || "${1}" -eq 0 ]]; then
403 - if [[ "${continued}" -eq 0 ]]; then
404 + if [[ "${CONTINUED}" -eq 0 ]]; then
405 echo -e "${E} ${K}[ ${G}ok${K} ]${N}"
406 fi
407 else
408 @@ -76,11 +88,7 @@
409 echo -en " ${B}*${N} ${*}"
410 echo -e "${E} ${K}[ ${B}!!${K} ]${N}"
411 fi
412 - if [[ -n "${TEMPDIR}" || -n "${LOOP}" ]]; then
413 - cleanup
414 - fi
415 - echo " ${GNAP_PRODUCT} failed, try ${NAME} -h for more help"
416 - exit 1
417 + gdie "${GNAP_PRODUCT} failed, try man ${NAME} for more help"
418 fi
419 }
420
421 @@ -90,13 +98,10 @@
422 umount "${LOOP}" && losetup -d "${LOOP}"
423 gtest $? "Failed to unmount ${LOOP}"
424 fi
425 - gbegin 'Cleaning temporary directories'
426 if [[ -d "${TEMPDIR}" ]]; then
427 - DIRTOREMOVE="${TEMPDIR}"
428 - TEMPDIR=''
429 - rm -rf "${DIRTOREMOVE}"
430 + gbegin 'Cleaning temporary directories'
431 + rm -rf "${TEMPDIR}"
432 gtest $? "Failed to remove ${DIRTOREMOVE}"
433 - else
434 - gtest 0
435 + TEMPDIR=''
436 fi
437 }
438
439 --
440 gnap-dev@g.o mailing list