[svn] r3055 - trunk/tools/dar

svn-commits at lists.rpmforge.net svn-commits at lists.rpmforge.net
Fri Mar 25 17:40:13 CET 2005


Author: dag
Date: 2005-03-25 17:40:12 +0100 (Fri, 25 Mar 2005)
New Revision: 3055

Modified:
   trunk/tools/dar/ChangeLog
   trunk/tools/dar/dar-build
   trunk/tools/dar/dar-exec
   trunk/tools/dar/dar-functions
   trunk/tools/dar/dar-shell
   trunk/tools/dar/dar-update
Log:
Added colors, small improvements

Modified: trunk/tools/dar/ChangeLog
===================================================================
--- trunk/tools/dar/ChangeLog	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/ChangeLog	2005-03-25 16:40:12 UTC (rev 3055)
@@ -42,6 +42,8 @@
 - scripts: Added pre-changelog-trim and pre-diskspace
 - dar-update: If arguments are given, don't do update/upgrade
 - dar-build: Added support for nosrc packages
+- dar-exec: Started adding colors !
+- dar-shell: Started adding colors !
 
 Version 0.6.0
 - dar.conf: Removed DISTSMAP, added it to dists specific section

Modified: trunk/tools/dar/dar-build
===================================================================
--- trunk/tools/dar/dar-build	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/dar-build	2005-03-25 16:40:12 UTC (rev 3055)
@@ -133,7 +133,7 @@
 		fi
 
 		### Export RPMVER to rpmconf
-		export RPMVER="$(chroot $CHROOTDIR/$DISTNICK /bin/su - -m $BUILD_USER -c "rpm --version" | cut -d' ' -f3)"
+		export RPMVER="$(chroot $CHROOTDIR/$DISTNICK /bin/su -lm $BUILD_USER -c "rpm --version" | cut -d' ' -f3)"
 
 		set_archs
 
@@ -329,7 +329,7 @@
 						--define "$DISTNICK 1" \
 						"$NEWSPECFILE"
 				else
-					$SETARCH chroot "$CHROOTDIR/$dist" /bin/su - -m $BUILD_USER -c "/usr/bin/rpmbuild -bb --clean $RPMOPTS \
+					$SETARCH chroot "$CHROOTDIR/$dist" /bin/su -lm $BUILD_USER -c "/usr/bin/rpmbuild -bb --clean $RPMOPTS \
 						--define '_smp_mflags $MAKEFLAGS' \
 						--define '_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \
 						--define '_initrddir %{_sysconfdir}/rc.d/init.d' \

Modified: trunk/tools/dar/dar-exec
===================================================================
--- trunk/tools/dar/dar-exec	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/dar-exec	2005-03-25 16:40:12 UTC (rev 3055)
@@ -1,10 +1,33 @@
 #!/bin/bash
+source "/usr/share/dar/dar-functions"
 
-### dar-exec  [ -d <dists> ]  <cmd> ...
+function help {
+	cat <<EOF
+usage: dar-exec [-q] [-d dist,dist2] cmd	
+Run a command in one or more DAR build environments
 
-source "/usr/share/dar/dar-functions"
+dar-exec options:
 
-daropts "d:" $@
+  -d dist,dist2         select build envs
+  -h                    this help message
+  -q                    be very quiet
+
+exported variables:
+
+  arch, dist, nick, path, repo, tag
+
+examples:
+
+  dar-exec cat /etc/redhat-release
+  dar-exec 'rpm -qa | wc -l'
+  dar-exec 'rpm -ihvU /dar/packages/foo/*\$dist*\$arch.rpm'
+  diff -u <(dar-exec -d el4i rpm -qa | sort) <(dar-exec -d el4a rpm -qa | sort)
+
+EOF
+exit 1
+}
+
+daropts "d:hq" $@
 CMD="$OPTS"
 
 if [ ! -d "$ROOT" ]; then
@@ -17,28 +40,29 @@
 AS_ROOT=1
 
 for distname in $DISTS; do
-	echo "Executing \"$CMD\" for $distname."
+	if [ -z "$QUIET" ]; then
+		echo -e "$_BL_$_WH= Executing \"$_YE$CMD$_WH\" for $_YE$distname$_WH.$_DE"
+	fi
 
 	if [ -r "$CONFIGDIR/dists/$distname/config" ]; then
 		source "$CONFIGDIR/dists/$distname/config"
-		export arch="$DISTARCH" dist="${DISTNAME// *}" nick="$DISTNICK" path="$DISTPATH" repo="$REPO" tag="$TAG"
+		export arch="$DISTARCH" dist="${DISTNAME// *}" nick="$DISTNICK" path="$DISTPATH" repo="$REPO" tag="${DISTTAG// *}"
 	fi
 
 	### Check for building as user
 	if [ $AS_ROOT -eq 1 ]; then
-#		DO_SU="/bin/su - -c"
+#		DO_SU="/bin/su -l -c"
 		DO_SU="/bin/bash -c"
 	else
-		DO_SU="/bin/su - -m $BUILD_USER -c"
+		DO_SU="/bin/su -lm $BUILD_USER -c"
 	fi
 
 	chroot "$CHROOTDIR/$distname" $DO_SU "$CMD"
 	RC=$?
 
 	if [ $RC -ne 0 ]; then
-		error "Failed executing \"$CMD\" (RC=$RC)"
+		error "$_RE_${_WH}Failed execution (RC=$_YE$RC$_WH)$_DE"
 	fi
-	echo
 done
 
 exit 0

Modified: trunk/tools/dar/dar-functions
===================================================================
--- trunk/tools/dar/dar-functions	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/dar-functions	2005-03-25 16:40:12 UTC (rev 3055)
@@ -6,6 +6,25 @@
 ### general variables
 DARCONFIG="/etc/dar/dar.conf"
 
+### ANSI colors
+_DE="\033[0;0m"		# Default
+_BK="\033[0;30m"	# Black
+_DB="\033[0;34m"	# Dark Blue
+_SI="\033[0;37m"	# Silver
+_GA="\033[1;30m"	# Gray
+_RE="\033[1;31m"	# Red
+_GR="\033[1;32m"	# Green
+_YE="\033[1;33m"	# Yellow
+_BL="\033[1;34m"	# Blue
+_MA="\033[1;35m"	# Magenta
+_CY="\033[1;36m"	# Cyan
+_WH="\033[1;37m"	# White
+
+_BK_="\033[40m"		# Black BG
+_RE_="\033[41m"		# Red BG
+_BL_="\033[44m"		# Blue BG
+_WH_="\033[47m"		# White BG
+
 ### Cleans environment
 function clean_env {
 	:
@@ -36,7 +55,7 @@
 ### Log and put error-boolean on (so die will escalate the problem)
 function error {
 	ERROR="yes"
-	echo "ERROR: $*" >&2
+	echo -e "ERROR: $*" >&2
 #	log "ERROR: $*"
 }
 
@@ -75,7 +94,7 @@
 		fi
 
 	(
-	if [ -z "$DISTNICK" ] || [ "$RPMVER" \< "4.1" ] || ! chroot "$CHROOTDIR/$DISTNICK" /bin/su - -m $BUILD_USER -c "rpmdb -D \"dist $DISTNAME\" -D \"$DISTNICK 1\" -D \"$DISTNAME 1\" -E \"%{expand:%(head -n128 $SPECFILE)}\"" | grep -i "^ *$CONFIG *:" | sed -e "s/^ *$CONFIG *: *//i" | head -1; then
+	if [ -z "$DISTNICK" ] || [ "$RPMVER" \< "4.1" ] || ! chroot "$CHROOTDIR/$DISTNICK" /bin/su -lm $BUILD_USER -c "rpmdb -D \"dist $DISTNAME\" -D \"$DISTNICK 1\" -D \"$DISTNAME 1\" -E \"%{expand:%(head -n128 $SPECFILE)}\"" | grep -i "^ *$CONFIG *:" | sed -e "s/^ *$CONFIG *: *//i" | head -1; then
 		if ! grep -i "^ *$CONFIG *:" $SPECFILE | sed -e "s/^ *$CONFIG *: *//i" | head -1; then
 			debug "Config $CONFIG not found in $SPECFILE"
 		fi
@@ -140,11 +159,13 @@
 			(a)	FORCE_ARCHS="$OPTARG";;
 			(d)	FORCE_DISTS="$OPTARG";;
 			(f)	FORCE_OVERWRITE="true";;
+			(h)	help;;
 			(n)	NOSOURCE="true";;
 			(r)	CREATE_REPO="true";;
 			(s)	FORCE_SOURCE_DISTS="$OPTARG";;
 			(t)	FORCE_TAG="$OPTARG";;
 			(v)	FORCE_VERBOSE="true";;
+			(q)	QUIET="true";;
 #			(-)	c=${OPTARG/#-/}; OPTARG="$(echo $* | cut -d' ' -f$OPTIND)"
 #			case "$c" in
 #				(port) port="$OPTARG"; OPTIND=$((OPTIND+1));;

Modified: trunk/tools/dar/dar-shell
===================================================================
--- trunk/tools/dar/dar-shell	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/dar-shell	2005-03-25 16:40:12 UTC (rev 3055)
@@ -1,10 +1,26 @@
 #!/bin/bash
+source "/usr/share/dar/dar-functions"
 
-### dar-shell  [ -d <dists> ]
+function help {
+	cat <<EOF
+usage: dar-shell [-q] [-d dist,dist2] cmd     
+Acquire a shell in one or more DAR build environments
 
-source "/usr/share/dar/dar-functions"
+dar-exec options:
 
-daropts "d:" $@
+  -d dist,dist2         select build envs
+  -h                    this help message
+  -q                    be very quiet
+
+exported variables:
+
+  arch, dist, nick, path, repo, tag
+
+EOF
+exit 1
+}
+
+daropts "d:hq" $@
 CMD="$OPTS"
 
 if [ ! -d "$ROOT" ]; then
@@ -16,16 +32,20 @@
 set_as_root
 AS_ROOT=1
 
-echo "Entering shells."
+if [ -z "$QUIET" ]; then
+	echo -e "$_BL_$_WH= Entering shells.$_DE"
+fi
 for distname in $DISTS; do
 	if [ -r "$CONFIGDIR/dists/$distname/config" ]; then
 		source "$CONFIGDIR/dists/$distname/config"
-		export arch="$DISTARCH" dist="${DISTNAME// *}" nick="$DISTNICK" path="$DISTPATH" repo="$REPO" tag="$TAG"
+		export arch="$DISTARCH" dist="${DISTNAME// *}" nick="$DISTNICK" path="$DISTPATH" repo="$REPO" tag="${DISTTAG// *}"
 	fi
 
 	chroot $CHROOTDIR/$distname
 done
-echo -n "Returning to parent shell. Press ENTER."
-read a
+if [ -z "$QUIET" ]; then
+	echo -en "$_BL_$_WH= Returning to parent shell. Press ENTER.$_DE"
+	read a
+fi
 
 exit 0

Modified: trunk/tools/dar/dar-update
===================================================================
--- trunk/tools/dar/dar-update	2005-03-25 00:16:20 UTC (rev 3054)
+++ trunk/tools/dar/dar-update	2005-03-25 16:40:12 UTC (rev 3055)
@@ -30,7 +30,7 @@
 		chroot $CHROOTDIR/$distname $UPDATECMD
 	fi
 
-	if [ -z "$PKGS" "$UPGRADECMD" ]; then
+	if [ -z "$PKGS" -a "$UPGRADECMD" ]; then
 		chroot $CHROOTDIR/$distname $UPGRADECMD
 	fi
 




More information about the commits mailing list