From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org)
	by nuthatch.gentoo.org with esmtp (Exim 4.67)
	(envelope-from <gnap-dev+bounces-52-garchives=archives.gentoo.org@gentoo.org>)
	id 1IGxfF-00017s-Gh
	for garchives@archives.gentoo.org; Fri, 03 Aug 2007 13:58:02 +0000
Received: from robin.gentoo.org (localhost [127.0.0.1])
	by robin.gentoo.org (8.14.0/8.14.0) with SMTP id l73DvxQ7029279;
	Fri, 3 Aug 2007 13:57:59 GMT
Received: from mail.bawue.net (phoenix.bawue.net [193.7.176.60])
	by robin.gentoo.org (8.14.0/8.14.0) with ESMTP id l73DvxeQ029274
	for <gnap-dev@lists.gentoo.org>; Fri, 3 Aug 2007 13:57:59 GMT
Received: from [193.166.89.200] (b136a.mtalo.tontut.fi [193.166.89.200])
	(using SSLv3 with cipher RC4-MD5 (128/128 bits))
	(No client certificate requested)
	by mail.bawue.net (Postfix) with ESMTP id 84B51BABD2
	for <gnap-dev@lists.gentoo.org>; Fri,  3 Aug 2007 15:53:39 +0200 (CEST)
Subject: [gnap-dev] [PATCH 4/4] GNAP environment
From: Philipp Riegger <lists@anderedomain.de>
To: gnap-dev@lists.gentoo.org
In-Reply-To: <1186146995.10651.18.camel@b136a>
References: <1186146995.10651.18.camel@b136a>
Content-Type: text/plain
Date: Fri, 03 Aug 2007 16:53:32 +0300
Message-Id: <1186149212.10651.51.camel@b136a>
Precedence: bulk
List-Post: <mailto:gnap-dev@lists.gentoo.org>
List-Help: <mailto:gnap-dev+help@gentoo.org>
List-Unsubscribe: <mailto:gnap-dev+unsubscribe@gentoo.org>
List-Subscribe: <mailto:gnap-dev+subscribe@gentoo.org>
List-Id: Gentoo GNAP development <gnap-dev.gentoo.org>
X-BeenThere: gnap-dev@gentoo.org
Reply-to: gnap-dev@lists.gentoo.org
Mime-Version: 1.0
X-Mailer: Evolution 2.10.2 
Content-Transfer-Encoding: 7bit
X-Archives-Salt: 5709dc77-f04a-48d2-8b3b-8bddd5b33943
X-Archives-Hash: 8fce13c4cc90f24a61f8a0afc780cc54

This cleans up the way gnap_* scripts get their information. Since i
mostly worked on gnap_make this is optimized for gnap_make and the other
scripts are only changed in the same way. In gnap_make we have the
following sources of configuration:

 - The command line
 - common.conf
 - catalyst.conf
 - the environment

Until now, catalyst.conf was used for... i don't know, it was sourced
but not really used, i think. common.conf was used for all the arch
specific stuff, that has to be passed to catalyst. The command line was
used for most of the configuration options, including the location of
common.conf and catalyst.conf.

The new behavior is the following:

gnap_make and gnap_shared specify default values for all the GNAP_
variables (sometimes undef is default). This can be overwritten by
environment variables (export GNAP_LIBDIR=/home/test/foo/bar for
specifying the place of all the gnap files for testing new
configurations, export GNAP_CATALYST_BIN="echo catalyst" for only
getting the configurations created by gnap_make and not building the
stuff come to mind), next the spec location is read from command line if
available and common.conf is sourced, the catalyst.conf info is read
from the command line if available and the file is sourced, the rest of
the command line is read and sets/overwrites whatever is given there.

With this you can:
 - add GNAP_ options to catalyst.conf (DON'T DO THAT)
 - add GNAP_ options to common.conf (shorter command line, nice)
 - add GNAP_ options to the environment (GNAP_LIBDIR since we only use
tha lates testing stuff located in /home/somewhere, whatever you want)
 - have new problems because you don't know why a special option is set.
Well, if you are advanced enough to make such a mess, you are advanced
enough for cat, grep, export -p and set -x to debug that.

Before i gorget it: I also did some more cleanup here. I was too lazy to
apply it to all the previous branches that it would be in the -cleanup
patch, i hope you can live with that.

Enjoy,
	Philipp


diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
+cleanup+split+namespace/src/gnap_make gnap-2.0+cleanup+split+namespace
+environment/src/gnap_make
--- gnap-2.0+cleanup+split+namespace/src/gnap_make	2007-08-02
15:50:45.000000000 +0300
+++ gnap-2.0+cleanup+split+namespace+environment/src/gnap_make
2007-08-02 15:46:54.000000000 +0300
@@ -1,7 +1,7 @@
 #!/bin/bash
 VERSION='2.0'
 
-GNAP_LIBDIR='/usr/lib/gnap'
+GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
 source ${GNAP_LIBDIR}/gnap_shared.sh
 echo "GNAP Core Building tool ${NAME} version ${VERSION}"
 
@@ -25,65 +25,31 @@
 	exit 0
 fi
 
-gbegin 'Checking parameters'
-
 # Catalyst executable and config file
-GNAP_CATALYST_BIN="/usr/bin/catalyst"
-GNAP_CATALYST_CONF="/etc/catalyst/catalyst.conf"
+GNAP_CATALYST_BIN=${GNAP_CATALYST_BIN:-"/usr/bin/catalyst"}
+GNAP_CATALYST_CONF=${GNAP_CATALYST_CONF:-"/etc/catalyst/catalyst.conf"}
 
-# Read options
-GNAP_STAGE3=0
-GNAP_LIVECD1=0
-GNAP_LIVECD2=0
-GNAP_TARBALL=0
-GNAP_MODULES=0
-GNAP_STAMP=$(date +%Y%m%d)
-NOTARGET=1
-NEEDS_SNAPSHOT=0
+# Default options
+GNAP_STAMP=${GNAP_STAMP:-$(date +%Y%m%d)}
+
+# Read options (phase 1)
+gbegin 'Checking parameters'
+
+OPTIND=0
 while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
 	case ${option} in
-		h )
+		h ) 
+			gtest
 			usage
 			exit 0;;
-		s ) GNAP_STAGE3FILE="${OPTARG}";;
-		p ) GNAP_SNAPSHOTFILE="${OPTARG}";;
-		o ) GNAP_PORTAGE_OVERLAYS="${GNAP_PORTAGE_OVERLAYS} ${OPTARG}";;
-		v ) GNAP_STAMP="${OPTARG}";;
-		t )
-			case "${OPTARG}" in
-				all )
-					GNAP_STAGE3=1
-					GNAP_LIVECD1=1
-					GNAP_LIVECD2=1
-					GNAP_TARBALL=1
-					GNAP_MODULES=1
-					NEEDS_SNAPSHOT=1;;
-				stage3 )
-					GNAP_STAGE3=1
-					NEEDS_SNAPSHOT=1;;
-				livecd-stage1 )
-					GNAP_LIVECD1=1
-					NEEDS_SNAPSHOT=1;;
-				livecd-stage2 )
-					GNAP_LIVECD2=1
-					NEEDS_SNAPSHOT=1;;
-				tarball )
-					GNAP_TARBALL=1;;
-				extensions )
-					GNAP_MODULES=1
-					NEEDS_SNAPSHOT=1;;
-				* ) gtest 1 'Specified stage is unknown!';;
-			esac
-			NOTARGET=0;;
-		f ) GNAP_FORCEYES=1;;
-		l ) GNAP_LOGPREFIX="${OPTARG}";;
-		c ) GNAP_CATALYST_CONF="${OPTARG}";;
 		e ) GNAP_SPECS="${OPTARG}";;
+		s|p|o|v|t|f|l|c ) :;;
 		* ) gtest 1 'Specified options are incomplete or unknown!';;
 	esac
 done
 
 # Root is needed
+# * non-root can only use "gnap_make -h"
 test "${EUID}" -eq 0
 gtest continued $? "You need to be root to run ${NAME}"
 
@@ -113,15 +79,71 @@
 	DISTCCSPEC="distcc_hosts: ${DISTCC_HOSTS}"
 fi
 
+
+# Read options (phase 2)
+OPTIND=0
+while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
+	case ${option} in
+		c ) GNAP_CATALYST_CONF="${OPTARG}";;
+		s|p|o|v|t|f|l|e|h ) :;;
+		* ) gtest 1 'Specified options are incomplete or unknown!';;
+	esac
+done
+
 # catalyst.conf file
 test -f "${GNAP_CATALYST_CONF}"
 gtest continued $? "${GNAP_CATALYST_CONF} file not found!"
 source "${GNAP_CATALYST_CONF}"
 
+# Read options (phase 3)
+OPTIND=0
+while getopts ':hs:p:m:o:v:t:fl:c:e:' option; do
+	case ${option} in
+		s ) GNAP_STAGE3FILE="${OPTARG}";;
+		p ) GNAP_SNAPSHOTFILE="${OPTARG}";;
+		o ) GNAP_PORTAGE_OVERLAYS="${GNAP_PORTAGE_OVERLAYS} ${OPTARG}";;
+		v ) GNAP_STAMP="${OPTARG}";;
+		t )
+			case "${OPTARG}" in
+				all )
+					GNAP_STAGE3=1
+					GNAP_LIVECD1=1
+					GNAP_LIVECD2=1
+					GNAP_TARBALL=1
+					GNAP_MODULES=1;;
+				stage3 ) GNAP_STAGE3=1;;
+				livecd-stage1 ) GNAP_LIVECD1=1;;
+				livecd-stage2 ) GNAP_LIVECD2=1;;
+				tarball ) GNAP_TARBALL=1;;
+				extensions ) GNAP_MODULES=1;;
+				* ) gtest 1 'Specified stage is unknown!';;
+			esac;;
+		f ) GNAP_FORCEYES=1;;
+		l ) GNAP_LOGPREFIX="${OPTARG}";;
+		c|e|h ) :;;
+		* ) gtest 1 'Specified options are incomplete or unknown!';;
+	esac
+done
+
 # At least one target is needed
-test "${NOTARGET}" -eq 0
-gtest continued $? \
+test "${GNAP_STAGE3}" -eq 0 &&
+test "${GNAP_LIVECD1}" -eq 0 &&
+test "${GNAP_LIVECD2}" -eq 0 &&
+test "${GNAP_TARBALL}" -eq 0 &&
+test "${GNAP_MODULES}" -eq 0
+if [[ $? -eq 0 ]]; then
+	gtest continued 1 \
 	'No target specified. You should provide at least one -t option.'
+fi
+
+NEEDS_SNAPSHOT=0
+test "${GNAP_STAGE3}" -eq 1 ||
+test "${GNAP_LIVECD1}" -eq 1 ||
+test "${GNAP_LIVECD2}" -eq 1 ||
+test "${GNAP_MODULES}" -eq 1
+if [[ $? -eq 0 ]]; then
+	NEEDS_SNAPSHOT=1
+fi
 
 # storedir must exist
 gmkdir "${storedir}"
diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
+cleanup+split+namespace/tools/gnap_overlay gnap-2.0+cleanup+split
+namespace+environment/tools/gnap_overlay
--- gnap-2.0+cleanup+split+namespace/tools/gnap_overlay	2007-07-27
16:00:02.000000000 +0300
+++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_overlay
2007-07-31 23:22:33.000000000 +0300
@@ -1,7 +1,7 @@
 #!/bin/bash
 VERSION='2.0'
 
-GNAP_LIBDIR='/usr/lib/gnap'
+GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
 source ${GNAP_LIBDIR}/gnap_shared.sh
 echo "GNAP overlay tool ${NAME} ${VERSION}"
 
@@ -42,19 +42,14 @@
 	exit 0
 fi
 
-gbegin 'Checking parameters'
+# Default settings
+GNAP_NOLOGO=${GNAP_NOLOGO:-0}
+GNAP_CREATE=${GNAP_CREATE:-'n'}
+GNAP_IMG_SIZE=${GNAP_IMG_SIZE:-15}
 
 # Read options
-GNAP_NOLOGO=0
-GNAP_FORCEYES=0
-GNAP_OUTPUT=''
-GNAP_TYPE=''
-GNAP_CREATE='n'
-GNAP_IMG_SIZE=15
-GNAP_TARGETROOT=''
-GNAP_CACHE=''
-GNAP_SERIAL=''
-GNAP_BAUDRATE=''
+gbegin 'Checking parameters'
+
 while getopts ':hg:o:c:nfi:d:l:r:ms:S:L:' option; do
 	case ${option} in
 		h ) usage
diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
+cleanup+split+namespace/tools/gnap_remaster gnap-2.0+cleanup+split
+namespace+environment/tools/gnap_remaster
--- gnap-2.0+cleanup+split+namespace/tools/gnap_remaster	2007-07-27
16:17:48.000000000 +0300
+++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_remaster
2007-07-31 23:29:03.000000000 +0300
@@ -1,12 +1,10 @@
 #!/bin/bash
 VERSION='2.0'
 
-GNAP_LIBDIR='/usr/lib/gnap'
+GNAP_LIBDIR=${GNAP_LIBDIR:-'/usr/lib/gnap'}
 source ${GNAP_LIBDIR}/gnap_shared.sh
 echo "GNAP remastering tool ${NAME} ${VERSION}"
 
-GNAP_OUTPUT='mygnap-core.tar'
-
 usage() {
 	echo
 	echo 'Usage:'
@@ -33,12 +31,8 @@
 gbegin 'Checking parameters'
 
 # Read options
-GNAP_EXTENSIONS=''
-GNAP_KERNEXT=''
-GNAP_MODEXT=''
-GNAP_BASEFS=''
-GNAP_EXTDIR=''
-GNAP_FORCEYES=0
+GNAP_OUTPUT=${GNAP_OUTPUT:-'mygnap-core.tar'}
+
 while getopts ':he:k:m:o:g:b:d:f' option; do
 	case ${option} in
 		h ) usage
diff -ur --exclude .svn --exclude upload.sh --exclude diff.sh gnap-2.0
+cleanup+split+namespace/tools/gnap_shared.sh gnap-2.0+cleanup+split
+namespace+environment/tools/gnap_shared.sh
--- gnap-2.0+cleanup+split+namespace/tools/gnap_shared.sh	2007-08-02
15:51:30.000000000 +0300
+++ gnap-2.0+cleanup+split+namespace+environment/tools/gnap_shared.sh
2007-08-02 15:46:44.000000000 +0300
@@ -6,34 +6,44 @@
  	gnap_remaster ) GNAP_PRODUCT="Remaster";;
  	* )             GNAP_PRODUCT="Something";;
 esac
-GNAP_STAGE3FILE="${GNAP_LIBDIR}/gnap-stage3seed.tar.bz2"
-GNAP_SNAPSHOTFILE="${GNAP_LIBDIR}/gnap-portagesnapshot.tar.bz2"
-GNAP_SPECS="${GNAP_LIBDIR}/gnap-specs.tar.bz2"
-GNAP_CORE="${GNAP_LIBDIR}/gnap-core.tar"
-GNAP_MBR="${GNAP_LIBDIR}/mbr/mbr.bin"
-GNAP_EXTDIR="${GNAP_LIBDIR}/extensions"
-GNAP_BASEFS="${GNAP_LIBDIR}/gnap-basefs.tar.bz2"
 
-GNAP_FORCEYES=0
+GNAP_STAGE3FILE=
${GNAP_STAGE3FILE:-"${GNAP_LIBDIR}/gnap-stage3seed.tar.bz2"}
+GNAP_SNAPSHOTFILE=
${GNAP_SNAPSHOTFILE:-"${GNAP_LIBDIR}/gnap-portagesnapshot.tar.bz2"}
+GNAP_SPECS=${GNAP_SPECS:-"${GNAP_LIBDIR}/gnap-specs.tar.bz2"}
+GNAP_CORE=${GNAP_CORE:-"${GNAP_LIBDIR}/gnap-core.tar"}
+GNAP_MBR=${GNAP_MBR:-"${GNAP_LIBDIR}/mbr/mbr.bin"}
+GNAP_EXTDIR=${GNAP_EXTDIR:-"${GNAP_LIBDIR}/extensions"}
+GNAP_BASEFS=${GNAP_BASEFS:-"${GNAP_LIBDIR}/gnap-basefs.tar.bz2"}
+
+GNAP_FORCEYES=${GNAP_FORCEYES:-0}
+
+#CONTINUED=0
 TEMPDIR=''
 LOOP=''
 
-G=$'\e[32;01m'
-B=$'\e[31;01m'
-N=$'\e[0m'
-W=$'\e[33;01m'
-K=$'\e[34;01m'
-C="$[$(set -- $(stty size 2>/dev/null); echo ${2}) - 7]"
-E=$'\e['${C}'G'
+G=$'\e[32;01m' # green
+B=$'\e[31;01m' # red
+N=$'\e[0m'     # neutral
+W=$'\e[33;01m' # yellow
+K=$'\e[34;01m' # blue
+C="$[$(set -- $(stty size 2>/dev/null); echo ${2}) - 7]" # end of line
helper
+E=$'\e['${C}'G' # end of line
+
+ginfo() {
+	echo -e " ${G}*${N} ${*}"
+}
 
 gwarn() {
 	echo -e " ${W}*${N} ${*}"
 }
 
-ginfo() {
-	echo -e " ${G}*${N} ${*}"
+gdie() {
+	echo -e " ${B}*${N} ${*}"
+	cleanup
+	exit 1
 }
 
+
 gmkdir() {
 	mkdir -p "$1"
 	gtest continued $? "Failed to create \"$1\"."
@@ -44,29 +54,31 @@
 		gwarn "${*} forced to yes"
 	else
 		read -ep " ${W}*${N} ${*} [N]: " answer
-		if [[ "${answer}" != 'y' && "${answer}" != 'Y' ]]; then
-			if [[ -n "${TEMPDIR}" || -n "${LOOP}" ]]; then
-				cleanup
-			fi
-			echo '${GNAP_PRODUCT} aborted!'
-			exit 2
-		fi
+		[[ "${answer}" != 'y' && "${answer}" != 'Y' ]] && \
+			gdie "${GNAP_PRODUCT} aborted!"
 	fi
 }
 
 gbegin() {
+#	[[ "${CONTINUED}" -eq 1 ]] && gdie "BUG triggered by gbegin()"
+
 	echo -ne " ${G}*${N} ${*}..."
+#	CONTINUED=1
 }
 
 gtest() {
-	continued=0
+#	# TODO: Remove this after removing all "gtest continued"
+#	if [[ "${#}" -gt 0 && "${1}" == 'continued' ]]; then
+#		shift
+#	fi
+	CONTINUED=0
 	if [[ "${#}" -gt 0 && "${1}" == 'continued' ]]; then
+		CONTINUED=1
 		shift
-		continued=1
 	fi
 
 	if [[ "${#}" -eq 0 || "${1}" -eq 0 ]]; then
-		if [[ "${continued}" -eq 0 ]]; then
+		if [[ "${CONTINUED}" -eq 0 ]]; then
 			echo -e "${E}  ${K}[ ${G}ok${K} ]${N}"
 		fi
 	else
@@ -76,11 +88,7 @@
 			echo -en " ${B}*${N} ${*}"
 			echo -e "${E}  ${K}[ ${B}!!${K} ]${N}"
 		fi
-		if [[ -n "${TEMPDIR}" || -n "${LOOP}" ]]; then
-			cleanup
-		fi
-		echo " ${GNAP_PRODUCT} failed, try ${NAME} -h for more help"
-		exit 1
+		gdie "${GNAP_PRODUCT} failed, try man ${NAME} for more help"
 	fi
 }
 
@@ -90,13 +98,10 @@
 		umount "${LOOP}" && losetup -d "${LOOP}"
 		gtest $? "Failed to unmount ${LOOP}"
 	fi
-	gbegin 'Cleaning temporary directories'
 	if [[ -d "${TEMPDIR}" ]]; then
-		DIRTOREMOVE="${TEMPDIR}"
-		TEMPDIR=''
-		rm -rf "${DIRTOREMOVE}"
+		gbegin 'Cleaning temporary directories'
+		rm -rf "${TEMPDIR}"
 		gtest $? "Failed to remove ${DIRTOREMOVE}"
-	else
-		gtest 0
+		TEMPDIR=''
 	fi
 }

-- 
gnap-dev@gentoo.org mailing list