3c3,74
< source /etc/makepkg.conf
---
> ## SUBROUTINES
> upload_pkg() { # $1 = repo, $2 = pkgfile
>     if [ "$1" != "community" ]; then
>     	scp $2 archlinux.org:staging/$1/add
>     else
>     	tupkg $1
>     fi
>     if [ $? -ne 0 ]; then
>     	warning "Cancelled upload of $pkgfile"
>     	return 1
>     fi
> 
>     msg "Uploaded $pkgfile"
>     return 0
> }
> 
> #ganked from makepkg - should we consolidate these into a single file?
> check_buildenv() {
> 	local needle=$(echo $1 | tr [:upper:] [:lower:])
> 	local i
> 	# use options from makepkg.conf
> 	for i in ${BUILDENV[@]}; do
> 		local lc=$(echo $i | tr [:upper:] [:lower:])
> 		if [ "$lc" = "$needle" ]; then
> 			echo "y"
> 			return
> 		elif [ "$lc" = "!$needle" ]; then
> 			echo "n"
> 			return
> 		fi
> 	done
> 	echo "unknown"
> 	return
> }
> 
> msg() {
> 	if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> 		echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2
> 	else
> 		echo "==> $1" >&2
> 	fi
> }
> 
> warning() {
> 	if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> 		echo -e "\033[1;33m==> WARNING:\033[1;0m \033[1;1m$1\033[1;0m" >&2
> 	else
> 		echo "==> WARNING: $1" >&2
> 	fi
> }
> 
> error() {
> 	if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> 		echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
> 	else
> 		echo "==> ERROR: $1" >&2
> 	fi
> }
> 
> startdir=$(pwd)
> 
> #preserve environment variables
> _PKGDEST=${PKGDEST}
> _SRCDEST=${SRCDEST}
> 
> #Source makepkg.conf; fail if it is not found
> if [ -f /etc/makepkg.conf ]; then
> 	source /etc/makepkg.conf
> else
> 	error "/etc/makepkg.conf not found. Cannot continue."
> 	exit 1
> fi
4a76
> #Source user-specific makepkg.conf overrides
12c84
< 	echo "No PKGBUILD file"
---
>     error "PKGBUILD file not found. Cannot continue."
16,17c88,92
< source PKGBUILD
< pkgfile=${pkgname}-${pkgver}-${pkgrel}.pkg.tar.gz
---
> # override settings with an environment variable for batch processing
> PKGDEST=${_PKGDEST:-$PKGDEST}
> PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
> SRCDEST=${_SRCDEST:-$SRCDEST}
> SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
19,26c94
< if [ ! -f $pkgfile ]; then
< 	pkgfile=$PKGDEST/$pkgfile
< fi
< 
< if [ ! -f $pkgfile ]; then
< 	echo "File $pkgfile doesn't exist"
< 	exit 1
< fi
---
> source PKGBUILD
28,31c96
< if [ "$cmd" == "extrapkg" ]; then
< 	repo="extra"
< 	tag="CURRENT"
< elif [ "$cmd" == "currentpkg" ]; then
---
> if [ "$cmd" == "currentpkg" ]; then
33a99,101
> elif [ "$cmd" == "extrapkg" ]; then
> 	repo="extra"
> 	tag="CURRENT"
42a111,115
> 
>     if [ ! -f ~/.tupkg ]; then
>        error "Must configure tupkg via ~/.tupkg. Cannot continue."
>        exit 1
>     fi
45,52c118,148
< if [ "$repo" != "community" ]; then
< 	scp $pkgfile archlinux.org:staging/$repo/add
< else
< 	if [ ! -f ~/.tupkg ]; then
< 	   echo "Must configure tupkg via ~/.tupkg, cancelled"
< 	   exit 1
< 	fi
< 	tupkg $pkgfile
---
> pkgfound=0
> pkguploaded=0
> 
> for curarch in "" ${arch[@]}; do
> 
>     pkgfile=${pkgname}-${pkgver}-${pkgrel}
> 
>     if [ "" != "$curarch" ]; then
>         pkgfile=${pkgfile}-${curarch}
>     fi
> 
>     pkgfile=${pkgfile}.pkg.tar.gz
> 
>     if [ ! -f $pkgfile ]; then
>         pkgfile=$PKGDEST/$pkgfile
>     fi
> 
>     if [ -f $pkgfile ]; then
>         pkgfound=1
>         if upload_pkg $repo $pkgfile; then
>             pkguploaded=1
>         fi
>     else
>         warning "File $pkgfile doesn't exist."
>     fi
> 
> done
> 
> if [ "$pkgfound" -eq "0" ]; then
>     error "No built packages found. Cannot continue."
>     exit 1
54,56c150,152
< if [ $? -ne 0 ]; then
< 	echo "Cancelled"
< 	exit 1
---
> if [ "$pkguploaded" -eq "0" ]; then
>     error "No packages uploaded. Cannot continue."
>     exit 1
58d153
< echo "===> Uploaded $pkgfile"
59a155
> upgmessage="upgpkg: $pkgname $pkgver-$pkgrel"
61,65c157,158
< cvs commit -m "upgpkg: $pkgname $pkgver-$pkgrel
< $1" > /dev/null
< if [ $? -ne 0 ]; then
< 	echo "Cancelled"
< 	exit 1
---
> 	upgmessage="$upgmessage 
> $1"
67,70c160,161
< echo "===> Commited with \"upgpkg: $pkgname $pkgver-$pkgrel
< $1\" message"
< else
< cvs commit -m "upgpkg: $pkgname $pkgver-$pkgrel" > /dev/null
---
> 
> cvs commit -m "$upgmessage" > /dev/null
72c163
< 	echo "Cancelled"
---
> 	error "Commit cancelled. Cannot continue."
75,76c166
< echo "===> Commited with \"upgpkg: $pkgname $pkgver-$pkgrel\" message"
< fi
---
> msg "Commited with \"$upgmessage\" message"
80c170
< 	echo "Cancelled"
---
> 	error "Tagging cancelled. Cannot continue."
83c173
< echo "===> Tagged as $tag"
---
> msg "Tagged as $tag"
