SVN: toys/tools/cleanbuild/cleanbuild

sparky sparky at pld-linux.org
Tue Dec 8 02:01:25 CET 2009


Author: sparky
Date: Tue Dec  8 02:01:25 2009
New Revision: 11010

Modified:
   toys/tools/cleanbuild/cleanbuild
Log:
- organized a little


Modified: toys/tools/cleanbuild/cleanbuild
==============================================================================
--- toys/tools/cleanbuild/cleanbuild	(original)
+++ toys/tools/cleanbuild/cleanbuild	Tue Dec  8 02:01:25 2009
@@ -6,6 +6,7 @@
 SRC="-n th -n th-ready"
 SUFFIX=""
 CACHEDIR="$PWD/poldekcache"
+IGNORE=""
 
 [ -r .cleanbuildrc ] && . .cleanbuildrc
 
@@ -19,7 +20,7 @@
 	echo "	./cleanbuild [cleanbuild options] specname [builder options]"
 	echo "	./build [cleanbuild options] specname [builder options]"
 	echo "	./clean [cleanbuild options]"
-	echo "	./cleaninstall [cleanbuild options] packages"
+	echo "	./create [cleanbuild options]"
 	echo "	./install [cleanbuild options] packages"
 	echo ""
 	echo "cleanbuild options:"
@@ -30,28 +31,32 @@
 
 FETCH=false
 CLEAN=false
+CREATE=false
 BUILD=false
 INSTALL=false
 CLEANAFTER=false
 
 case "$0" in
+	*clean)
+		CLEAN=exit_after
+		;;
 	*cleanbuild)
 		FETCH=true
 		CLEAN=true
+		CREATE=true
 		BUILD=true
 		;;
-	*clean)
-		CLEAN=true
-		;;
 	*build)
+		CREATE=true
 		BUILD=true
 		;;
-	*cleaninstall)
+	*create)
 		CLEAN=true
-		INSTALL=true
+		CREATE=exit_after
 		;;
 	*install)
-		INSTALL=true
+		CREATE=true
+		INSTALL=exit_after
 		;;
 	*)
 		usage
@@ -80,7 +85,7 @@
 			DEST="$V"
 			SRC="-n $V"
 			;;
-		-cleanafter | -ca)
+		--cleanafter | -ca)
 			CLEANAFTER=true
 			;;
 		-[a-z])
@@ -104,23 +109,34 @@
 	builder_options="$*"
 fi
 
-warn() {
+CHNAME="chroot-$DEST$SUFFIX"
+CHDIR="$PWD/$CHNAME"
+CHHOME="/home/users/$USER"
+
+warn()
+{
 	echo -n -e "\033[31;1m" >&2
 	echo -n "$*" >&2
 	echo -e "\033[0m" >&2
 }
-die() {
+
+die()
+{
 	code=$1
 	shift
 	warn "$*"
 	exit $code
 }
-info() {
+
+info()
+{
 	echo -n -e "\033[32m"
 	echo -n "$*"
 	echo -e "\033[0m"
 }
-title() {
+
+title()
+{
 	[ -t 1 ] || return 0
 	local msg="$CHNAME: $build_pkg: $*"
 	case "$TERM" in
@@ -134,11 +150,13 @@
 	return 0
 }
 
+exit_after()
+{
+	return 0;
+}
 
-CHNAME="chroot-$DEST$SUFFIX"
-CHDIR="$PWD/$CHNAME"
-
-check_running() {
+check_running()
+{
 	[ -r "$CHDIR/.pid" ] || return
 	PID=$(< "$CHDIR/.pid")
 	if [ -d /proc/$PID ]; then
@@ -146,25 +164,15 @@
 	fi
 }
 
-check_running
-
 for D in installed buildlogs $CACHEDIR; do
 	if [ ! -d "$D" ]; then
-		echo "mkdir $D"
+		info "mkdir $D"
 		su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
 	fi
 done
 
-if $FETCH; then
-	info "Fetching $build_pkg"
-	title "fetch"
-	su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
-		|| die 11 "Fetch failed"
-fi
-
 poldek_options="-O keep_downloads=yes -O suggests=no -O ignore=vserver-packages -O unique_package_names=yes -O particle_install=no"
 
-IGNORE=""
 ignore() { IGNORE="$IGNORE $*"; }
 ignore \
 	vserver-packages \
@@ -188,43 +196,41 @@
 	java-sun-jre
 
 
-rebuilddb() {
+rebuilddb()
+{
 	rpm --root=$CHDIR --rebuilddb
 }
 
-poldek() {
+poldek()
+{
 	rebuilddb
 	/usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" $poldek_options "$@"
 }
 
 
-CHHOME="/home/users/$USER"
-
-#set -x
-
-build_umount() {
+build_umount()
+{
 	for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
 		[ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
 	done
 }
 
-build_remove_root() {
+build_remove_root()
+{
 	umount $CHDIR
 	rmdir $CHDIR
 }
 
-check_running
-
-clean() {
+clean()
+{
 	info "Cleaning $CHNAME"
 	build_umount
 	build_remove_root
 	title "clean"
 }
 
-$CLEAN && clean
-
-build_prepare_root() {
+build_prepare_root()
+{
 	set -e
 	mkdir $CHDIR
 	mount -t tmpfs -o size=8G /dev/null $CHDIR
@@ -259,27 +265,14 @@
 	set +e
 }
 
-build_mount_home() {
+build_mount_home()
+{
 	mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
 }
 
-if ! $BUILD && ! $INSTALL; then
-	exit
-fi
-
-if $CLEAN; then
-	su $USER -c "poldek -s $RPMS_FROM --mkidx"
-
-	# rm -f installed/$build_pkg
-
-	info "Preparing $CHNAME"
-	build_prepare_root
-	build_mount_home
-fi
-
-echo $$ > $CHDIR/.pid
 
-print_installed() {
+print_installed()
+{
 	echo=$1
 	if [ -r installed/$build_pkg ]; then
 		$echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
@@ -288,7 +281,8 @@
 	fi
 }
 
-addlist() {
+addlist()
+{
 	LIST="$1"
 
 	print_installed info
@@ -296,11 +290,14 @@
 	print_installed echo >> $LIST
 }
 
-builddie() {
+builddie()
+{
 	LIST="$1"; shift
 	CODE="$1"; shift
 	MSG="$*"
 
+	rm -f $CHDIR/.pid
+
 	$CLEANAFTER && clean
 	title "failed !"
 
@@ -309,7 +306,8 @@
 }
 
 LAST_INSTALL=""
-poldek_install() {
+poldek_install()
+{
 	I="$1";
 	# Nothing to install
 	[ -n "$I" ] || return 1
@@ -339,9 +337,52 @@
 	return 1
 }
 
-if $INSTALL; then
-	poldek_install "$*"
-	exit
+maybe_call()
+{
+	local cond="$1"; shift
+	local func="$1"; shift
+
+	[ $cond == "false" ] && return
+	$func "$@"
+	[ $cond == "exit_after" ] && exit
+}
+
+fetch()
+{
+	info "Fetching $build_pkg"
+	title "fetch"
+	su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
+		|| die 11 "Fetch failed"
+}
+
+create()
+{
+	su $USER -c "poldek -s $RPMS_FROM --mkidx"
+
+	if [ ! -d $CHDIR ]; then
+		info "Preparing $CHNAME"
+		build_prepare_root
+		build_mount_home
+	fi
+}
+
+
+maybe_call $FETCH fetch
+
+check_running
+
+maybe_call $CLEAN clean
+
+maybe_call $CREATE create
+
+echo $$ > $CHDIR/.pid
+
+maybe_call $INSTALL poldek_install "$*"
+
+$BUILD || exit
+
+if [ -p /tmp/fixfreq ]; then
+	echo $$ > /tmp/fixfreq
 fi
 
 while true; do


More information about the pld-cvs-commit mailing list