#!/bin/bash

y2pmbuildconfdir=/etc/y2pmbuild
y2pmbuilddatadir=/usr/share/y2pmsh

: ${builduser:=compiler}
: ${builddebugsolve:=0}

builduserhome="/home/$builduser"

ccache=0
icecream=0
quilt=0
doinit=1
rpmbuild=rpmbuild
rpmbuildstage=a
rpmbopts=()
definesnstuff=()
specdir=
specfiles=
strictrequires=0
create_baselibs=0
extra_packs=

### config file keys
add_sources=
regen_repository=
repository=
buildrootbase="/var/tmp/build-root"
extra_copy=
rpm_sign_name=
rpm_sign_key=
###

success=0;

if [ -z "$BUILD_DIST" ]; then
    have_repo=0;
elif ! . "$y2pmbuildconfdir/dists_common"; then
    have_repo=0
elif ! . "$y2pmbuildconfdir/dists/$BUILD_DIST" ; then
    have_repo=0
else
    have_repo=1
fi

if [ -z "$buildroot" ]; then
    user=`id -un`
    [ "$user" = root -a -n "$SUDO_USER" -a "$SUDO_USER" != root ] && user="$SUDO_USER"
    buildroot="$buildrootbase.$user"
    [ -n "$BUILD_DIST" ] && buildroot="$buildroot.$BUILD_DIST"
fi

if [ -z "$defaultpackages" ]; then
    defaultpackages="aaa_base acl attr bash bind-libs bind-utils bison bzip2 coreutils cpio cpp cracklib cvs cyrus-sasl db diffutils e2fsprogs file filesystem fillup findutils flex gawk gdbm-devel gettext-devel glibc glibc-devel glibc-locale gpm grep groff gzip info insserv klogd less libacl libattr libcom_err libgcc libnscd libstdc++ libxcrypt libzio m4 make man mktemp module-init-tools ncurses ncurses-devel net-tools netcfg openldap2-client openssl pam pam-modules patch permissions popt procinfo procps psmisc pwdutils rcs readline sed strace sysvinit tar tcpd texinfo timezone unzip util-linux vim zlib zlib-devel autoconf automake binutils gcc gdbm gettext libtool perl rpm"
fi

neededpackages=

: ${create_package_descr:=/opt/kde3/share/apps/krpmview/create_package_descr}

removegpgkey()
{
    [ "$buildroot" = / ] && return 1

    rm -rf $buildroot/.gnupg $buildroot/.build.key
}

cleanup()
{
    set +e
    trap EXIT
    if [ "$buildroot" != / ]; then
	umount -n $buildroot/proc 2> /dev/null
	umount -n $buildroot/mnt 2> /dev/null
	umount -n $buildroot/dev/pts 2> /dev/null
    fi

    rm -f "$buildroot/.locked"
    rm -rf "$buildroot/.mkbaselibs"

    if [ "$success" = 0 ]; then
	echo -n "FAILED $spec at " >> "$buildroot/.build.packages"
	date >> "$buildroot/.build.packages"
    fi

    removegpgkey
}

regenrepository()
{
    [ "$have_repo" != 1 ] && return 0

    local do_regen
    do_regen=1
    [ "$1" = "--init" ] && do_regen=0
    
    install -m 755 -d "$repository"

    [ -z "`echo $repository/*`" ] && do_regen=1

    [ "$do_regen" = "0" ] && return 0
    
    local i

    for i in $regen_repository; do
	if [ "$i" = 'plain' ]; then
	    pushd .
	    cd "$repository"
	    genIS_PLAINcache -f -r "$repository"
	    popd
	elif [ "$i" = 'yum' ]; then
	    if [ -x '/usr/bin/createrepo' ]; then
		/usr/bin/createrepo "$repository"
	    else
		echo -e '\e[34mcreaterepo not found, not creating yum source\e[m'
	    fi
	elif [ "$i" = 'ul' ]; then
	    if [ -x "$create_package_descr" ]; then
		pushd .
		cd "$repository"
		$create_package_descr
		popd
	    else
		echo "$create_package_descr not found, not creating ul source"
	    fi
	fi
    done
}

addsourcesfromrepository()
{
    [ "$have_repo" != 1 ] && return 0

    echo "set runningfromsystem false"
    echo "_deletemediaatexit"
    echo "set autosource false"

    if [ -n "$url_repository" ]; then
	echo "source -a $url_repository"
    fi

    for s in $add_sources; do
	eval src=\$url_$s
	echo "source -a $src"
    done
}

copyfilestorepository()
{
    find "$buildroot/usr/src/packages/RPMS" -type f -printf '\033[1m%p\033[m\n'
    find "$buildroot/usr/src/packages/SRPMS" -type f

    [ "$have_repo" != 1 -o -n "$no_copy_repo" ] && return 0

    rpmdir="$buildroot"/usr/src/packages/RPMS
    while read rpm; do
	dir="$repository"/${rpm%%/*}
	mkdir -p "$dir"
	set -- cp "$rpmdir/$rpm" "$dir"
	echo "$@"
	"$@"
    done < <(find "$rpmdir" -type f -printf '%P\n')

    rpmdir="$buildroot"/usr/src/packages/SRPMS
    while read rpm; do
	dir="$repository"/src
	mkdir -p "$dir"
	set -- cp "$rpmdir/$rpm" "$dir"
	echo "$@"
	"$@"
    done < <(find "$rpmdir" -type f -printf '%P\n')

    regenrepository
}

parse_spec()
{
    local i=0;
    local line
    while read line; do
	[ "$line" = "/ERROR/" ] && false
	case $i in
	    0) # name
		i=1
	    ;;
	    1) # ver
		i=2
	    ;;
	    2) # subpacks
		i=3
	    ;;
	    3) # buildrequires
		neededpackages="$line"
		i=0
	    ;;
	esac
    done < <($y2pmbuilddatadir/parse_spec.pl "$@" || echo /ERROR/)
}

# $1 specfile
getneededforbuild()
{
    local line
    local file="$1";
    [ ! -e "$file" ] && return 1

    spec_norootforbuild=`grep "^# *norootforbuild" "$file" || true`

    if [ -z "$spec_norootforbuild" ]; then
	echo -e "\e[34mWARNING: spec file misses 'norootforbuild'\e[m"
    fi

    if ! grep -q '^BuildRequires' "$file"; then
	spec_usedforbuild=`grep "^# *usedforbuild" "$file" || true`
	local seen_aaa_base=0
	for i in $spec_usedforbuild; do
	    case "$i" in
	    \#*)
	    ;;
	    usedforbuild)
	    ;;
	    *)
		neededpackages="$neededpackages $i"
		[ "$i" = 'aaa_base' ] && seen_aaa_base=1
	    ;;
	    esac
	done
    else
	if [ -n "$BUILD_DIST" ]; then
	    if [ ! -e "$y2pmbuildconfdir/macros/$BUILD_DIST/macros" ]; then
		    echo "rpm macros for $BUILD_DIST not configured"
		    exit 1
	    fi
	    parse_spec --dist "$BUILD_DIST" "${definesnstuff[@]}" "$file"
	else
	    parse_spec "${definesnstuff[@]}" "$file"
	fi
    fi

    if [ "$ccache" -eq 1 ]; then
	neededpackages="$neededpackages ccache"
    fi
    if [ "$icecream" -gt 0 ]; then
	neededpackages="$neededpackages icecream gcc-c++"
    fi
    if [ "$quilt" -eq 1 ]; then
	neededpackages="$neededpackages quilt"
    fi
    if [ "$create_baselibs" -eq 1 ]; then
	neededpackages="$neededpackages build"
    fi
    neededpackages="$neededpackages $extra_packs"

    if [ "$seen_aaa_base" != 1 ]; then
	echo "BuildRequires: $neededpackages"
	echo "aaa_base not in BuildRequires, adding default packages"
	neededpackages="$defaultpackages $neededpackages"
    else
	echo "aaa_base in BuildRequires, not adding default packages"
    fi
}

installpackages()
{
    local logfile
    local instlog

    setuptimezone

    logfile="$buildroot/.y2log"
    instlog="$buildroot/.y2logRPM"
    y2pmshcmds="$buildroot/.y2pmshcmds"
    > "$logfile"
    > "$instlog"
    cat > "$y2pmshcmds" <<-EOF
	set root $buildroot
	set logfile $logfile
	set instlog $instlog
	set quitonfail 1
	set verbose 1
	set build::strictrequires $strictrequires
	EOF
    
    regenrepository --init

    addsourcesfromrepository >> "$y2pmshcmds"
	
    cat >> "$y2pmshcmds" <<-EOF
	source -s
	set debug $builddebugsolve
	buildsolve $neededpackages
	set debug 0
	summary
	commit
	EOF

    # don't restart daemons etc.
    export YAST_IS_RUNNING=instsys

    y2pmsh < "$y2pmshcmds"
}

setuptimezone()
{
    # FIXME sucks
    if [ -e "$buildroot/usr/sbin/zic" -a -e "$buildroot/bin/su" -a -e "$buildroot/etc/passwd" ]; then
	chroot "$buildroot" su - -c "/usr/sbin/zic -l GMT"
    else
	install -m 755 -d "$buildroot/etc"
	install -m 644 /etc/localtime "$buildroot/etc/localtime"
    fi
}

runsuseconfig()
{
    echo "SuSEconfig ..."
    chroot "$buildroot" su - -c /sbin/SuSEconfig
}

runldconfig()
{
    echo "ldconfig ..."
    chroot "$buildroot" su - -c /sbin/ldconfig
}

copysourcestobuildroot()
{
    [ "$buildroot" = / ] && return 1
    
    rm -rf "$buildroot"/usr/src/packages

    for i in BUILD RPMS/`arch` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS; do
	mkdir -p "$buildroot"/usr/src/packages/$i
    done

    find . -maxdepth 1 \( -type f -or -type l \) -and -not -name '.*' \
	-print0 | \
	xargs -0 -iXX cp -p XX "$buildroot"/usr/src/packages/SOURCES/
}

addbuilduser()
{
    > "$buildroot"/etc/profile.d/build_path.sh
    if [ "$builduser" != "root" ]; then
	if ! grep $builduser "$buildroot"/etc/passwd; then
		echo adding user $builduser
		chroot "$buildroot" /usr/sbin/useradd -m $builduser -d $builduserhome
	fi
	echo adjusting permissions
	chroot "$buildroot" chown -R $builduser.root /usr/src/packages

	echo 'export PATH=/sbin:/usr/sbin:$PATH' >> "$buildroot"/etc/profile.d/build_path.sh
    fi
}

setupccache()
{
    chroot "$buildroot" su - "$builduser" -c "ls -ld ~$builduser"
    if [ "$ccache" = 1 ]; then
	if mkdir -p $buildroot/opt/ccache/bin; then
	    for i in gcc g++ cc c++; do
#		ln -sf /usr/bin/ccache $buildroot/opt/ccache/bin/$i
		rm -f $buildroot/opt/ccache/bin/$i
		test -e $buildroot/usr/bin/$i || continue
		echo '#! /bin/sh' > $buildroot/opt/ccache/bin/$i
		echo "test -e /usr/bin/$i || exit 1" > $buildroot/opt/ccache/bin/$i
	        echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $buildroot/opt/ccache/bin/$i
		echo "ccache $i \"\$@\"" >> $buildroot/opt/ccache/bin/$i
		chmod 755 $buildroot/opt/ccache/bin/$i
		echo "Installed ccache wrapper as $buildroot/opt/ccache/bin/$i"
	    done
	fi
	mkdir -p "$buildroot"/.ccache
	chroot "$buildroot" chown -R "$builduser" "/.ccache"
	echo "export CCACHE_DIR=/.ccache" > "$buildroot"/etc/profile.d/build_ccache.sh
	echo 'export PATH=/opt/ccache/bin:$PATH' >> "$buildroot"/etc/profile.d/build_ccache.sh
    else
	chroot "$buildroot" su - -c "rm -f ~$builduser/bin/{gcc,g++,cc,c++}"
	rm -f $buildroot/opt/ccache/bin/{gcc,g++,cc,c++}
    fi
    chroot "$buildroot" su - "$builduser" -c "ls -ld ~$builduser"
}

setupicecream()
{
    if [ "$icecream" -eq 0 ]; then
	rm -rf $buildroot/var/run/icecream
	return
    fi

    if ! rpm -q --root $buildroot icecream >/dev/null 2>/dev/null; then
	echo "*** icecream package not installed ***"
	false
	return
    fi
    
    echo "using icecream with $icecream jobs"

    if [ "$ccache" -ne 1 ]; then
	echo 'export PATH=/opt/icecream/bin:$PATH' >> "$buildroot"/etc/profile.d/build_path.sh
    else
	echo 'export CCACHE_PATH=/opt/icecream/bin' >> "$buildroot"/etc/profile.d/build_path.sh
    fi
    
    local icecc_vers=`cd $buildroot; ls -1 var/run/icecream/*.tar.bz2`

    # only run create-env if compiler or glibc changed
    if [ -z "$icecc_vers" \
	-o ! -e "$buildroot/$icecc_vers" \
	-o "$buildroot/usr/bin/gcc" -nt "$buildroot/$icecc_vers" \
	-o "$buildroot/usr/bin/g++" -nt "$buildroot/$icecc_vers" \
	-o "$buildroot/usr/bin/as" -nt "$buildroot/$icecc_vers" \
	-o "$buildroot/lib/libc.so.6" -nt "$buildroot/$icecc_vers" ]
    then
	rm -rf $buildroot/var/run/icecream
	mkdir -p $buildroot/var/run/icecream
	chroot $buildroot bash -c 'cd /var/run/icecream; /usr/bin/create-env'
	icecc_vers=`cd $buildroot; ls -1 var/run/icecream/*.tar.bz2`
    else
	echo "reusing existing icecream environment /$icecc_vers"
    fi
    echo "export ICECC_VERSION=/$icecc_vers" >> "$buildroot"/etc/profile.d/build_path.sh
}

copyextrafiles()
{
    [ "$have_repo" != 1 ] && return 0

    if [ -n "$BUILD_DIST" -a -d "$y2pmbuildconfdir/files/$BUILD_DIST/" ]; then
	extra_copy="$y2pmbuildconfdir/files/$BUILD_DIST/ $extra_copy"
    fi

    [ -z "$extra_copy" ] && return 0

    local dir
    for dir in $extra_copy; do
	echo "copying $dir"
	rsync -av $dir $buildroot
    done
}

determinerpmversion()
{
    local a
    local b
    local ver
    read a b ver < <(chroot "$buildroot" rpm --version)
    case "$ver" in
	3*) rpmbuild=rpm ;;
    esac
}

mkdevs()
{
    local dir=$buildroot/dev
    mkdir -p $dir
    while read a b c d e; do
	rm -f $dir/$b
	case $a in
	    l)
		ln -s $c $dir/$b
		;;
	    *)
		mknod -m $e $dir/$b $a $c $d
		;;
	esac
    done <<-EOF
	c null 1 3 666
	c zero 1 5 666
	c full 1 7 622
	c random 1 8 666
	c urandom 1 9 644
	c tty 5 0 666
	c ptmx 5 2 666
	l fd /proc/self/fd/ fd
	l stdin /proc/self/fd/0
	l stdout /proc/self/fd/1
	l stderr /proc/self/fd/2
	EOF
    true
}

mountfilesystems()
{
    mkdir -p $buildroot/proc
    mkdir -p $buildroot/dev/pts
    pwd
    # -oro doesn't have the desired effect anyways ...
    mount -n -tproc proc $buildroot/proc
    mount -n -tdevpts none $buildroot/dev/pts
}

setmemorylimit()
{
    local mem
    while read mem; do
	case "$mem" in
	    MemTotal:*)
		set -- $mem
		eval "mem=\$(($2/3*2))"
		ulimit -v $mem
		echo "Memory limit set to ${mem}KB"
		break;
	    ;;
	esac
    done < <(cat /proc/meminfo) # cat for proc stuff
}

# create a shell script from command line. Used for preserving arguments
# through /bin/su -c
toshellscript()
{
    echo "#!/bin/sh -x"
    echo -n exec
    for arg; do
	arg=${arg/\$/\\\$}
	arg=${arg/\"/\\\"}
	arg=${arg/\`/\\\`}
	arg=${arg/\\/\\\\}
	echo -n " \"$arg\""
    done
    echo
}

createuserrpmmacros()
{
    > $buildroot$builduserhome/.rpmmacros
}

installgpgkey()
{
    removegpgkey

    if [ -n "$rpm_sign_name" ]; then
	echo 'installing gpg key ...'
	[ -z "$rpm_sign_key" ] && rpm_sign_key="$y2pmbuildconfdir/signkey.asc"
	install -d -m 700 $buildroot/.gnupg
	install -m 600 "$rpm_sign_key" $buildroot/.build.key

	chroot "$buildroot" chown $builduser /.gnupg /.build.key
	chroot "$buildroot" su - $builduser -c "gpg -q --homedir /.gnupg --import /.build.key" < /dev/null

	cat > $buildroot$builduserhome/.rpmmacros <<-EOF
	%_gpg_name $rpm_sign_name
	%_gpg_path /.gnupg
	%_signature gpg
	EOF

	rpmbopts[${#rpmbopts[@]}]="--sign"
    fi
}

docreate_baselibs()
{
    [ "$create_baselibs" -ne 1 ] && return
    
    echo "creating baselibs ..."
    local f brpms baselibs_cfg
    brpms=
    for f in $buildroot/usr/src/packages/RPMS/*/*.rpm ; do
        brpms="$brpms ${f#$buildroot}"
    done
    if test -e $buildroot/usr/src/packages/SOURCES/baselibs.conf ; then
	baselibs_cfg="-c /usr/src/packages/SOURCES/baselibs.conf"
    fi
    if test -f $buildroot/usr/lib/build/mkbaselibs ; then
	if test -z "$baselibs_cfg" -a -e $buildroot/usr/lib/build/baselibs.conf ; then
	    baselibs_cfg="-c /usr/lib/build/baselibs.conf"
	fi
	toshellscript /usr/lib/build/mkbaselibs -c /usr/lib/build/baselibs_global.conf \
	    $baselibs_cfg $brpms > $buildroot/.mkbaselibs.command
    elif test -f /usr/lib/build/mkbaselibs; then
	# use external version
	rm -rf $buildroot/.mkbaselibs
	mkdir -p $buildroot/.mkbaselibs
	cp -f /usr/lib/build/mkbaselibs $buildroot/.mkbaselibs
	cp -f /usr/lib/build/baselibs_global.conf $buildroot/.mkbaselibs
	if test -z "$baselibs_cfg" -a -e /usr/lib/build/baselibs.conf; then
	    cp -f /usr/lib/build/baselibs.conf $buildroot/.mkbaselibs/baselibs.conf
	    baselibs_cfg="-c /.mkbaselibs/baselibs.conf"
	fi
	toshellscript /.mkbaselibs/mkbaselibs -c /.mkbaselibs/baselibs_global.conf \
	    $baselibs_cfg $brpms > $buildroot/.mkbaselibs.command
    else
	echo -e "\e[34mmkbaselibs not installed, not creating baselibs packages\e[m"
	return
    fi

    chmod 755 $buildroot/.mkbaselibs.command
    chroot "$buildroot" su - $builduser -c /.mkbaselibs.command < /dev/null
}

helpandquit()
{
    cat <<EOF
Usage: $0 [OPTIONS]

y2pmbuild rebuilds all .spec files in the current directory
    
OPTIONS:
    --ccache		use ccache to speed up rebuilds
    --icecream=N	use N parallel build jobs with icecream
    --jobs=N		use N parallel build jobs
    --quilt		install quilt
    --no-init		do not install any packages, just start compiling
    --no-copy-repo	if called with repository, don't copy to repository
    --target=X          use X as rpm target
    --with=X            enable configure X for build
    --without=X         disable configure X for build
    --define='X Y'      define macro X with value Y
    --stage=X           use X as build stage (default: a)
    --strictrequires    unresolved build requires cause build to abort
    --signas=X          sign built packages with id X
    --baselibs          Create -32bit/-64bit/-x86 rpms for other architectures
    --extra-packs=X     Also install the listed packages.
    --help		this screen

EOF
    exit 0
}

parsecmdline()
{
    local bjobs=0
    shortopts=
    longopts=icecream:,jobs:,ccache,root,no-init,quilt,no-copy-repo,help,signas:,target:,define:,with:,without:,stage:,strictrequires,baselibs,extra-packs:
    getopt_tmp=`getopt -o "$shortops" --long "$longopts" \
	 -n 'y2pmbuild' -- "$@"`

    if [ $? != 0 ] ; then echo "error parsing command line options" >&2 ; exit 1 ; fi

    eval set -- "$getopt_tmp"

    while true ; do
	case "$1" in
	    --ccache) ccache=1 ; shift ;;
	    --icecream) icecream="$2"; bjobs="$icecream" ; shift 2 ;;
	    --jobs) bjobs="$2" ; shift 2 ;;
	    --quilt) quilt=1 ; shift ;;
	    --root) builduser=root; builduserhome=/root ; shift ;;
	    --no-init) doinit=0 ; shift ;;
	    --no-copy-repo) no_copy_repo=1 ; shift ;;
	    --help) helpandquit ;;
	    --target|--define|--with|--without)
		    definesnstuff[${#definesnstuff[@]}]="$1";
		    definesnstuff[${#definesnstuff[@]}]="$2";
		    shift 2 ;;
	    --stage) rpmbuildstage="$2"; shift 2 ;;
	    --signas) rpm_sign_name="$2"; shift 2 ;;
	    --strictrequires) strictrequires=1; shift ;;
	    --baselibs) create_baselibs=1; shift ;;
	    --extra-packs) extra_packs="$extra_packs $2"; shift 2 ;;
	    --) shift ; break ;;
	    *) echo "error parsing command line options" ; exit 1 ;;
	esac
    done

    if [ "$bjobs" -gt 1 ]; then
	rpmbopts[${#rpmbopts[@]}]='-D'
	rpmbopts[${#rpmbopts[@]}]="jobs $bjobs"
    fi

    if [ "$strictrequires" -ne 1 ]; then
	rpmbopts[${#rpmbopts[@]}]='--nodeps'
    fi

    specfiles="$*"
}

set -e

unset ${!LC_*}
export LANG=POSIX

parsecmdline "$@"

if [ `id -nu` != "root" ]; then
    echo "only root can build packages this way" >&2
    exit 2
fi

if [ "$buildroot" = / -o -z "$buildroot" ]; then
    echo "invalid build root: $buildroot" >&2
    exit 1
fi

mkdir -p "$buildroot"

if [ ! -e "$buildroot" ]; then
    echo "couldn't create $buildroot" >&2
    exit 1
elif [ ! -d "$buildroot" ]; then
    echo "$buildroot is no directory" >&2
    exit 1
elif [ ! -O "$buildroot" ]; then
    echo "$buildroot is not owned by `id -nu`" >&2
    exit 1
fi

if [ -e "$buildroot/.locked" ]; then
    echo -n "$buildroot already locked by pid " >&2
    cat "$buildroot/.locked" >&2
    exit 1
fi

echo $$ > "$buildroot/.locked"

trap cleanup EXIT

rm -f $buildroot/.build.log
exec > >(tee $buildroot/.build.log) 2>&1

shopt -s nullglob

if [ -z "$specfiles" ]; then
    specfiles=`echo *.spec`
fi

if [ -z "$specfiles" ]; then
    echo "no spec files found" >&2
    exit 1
fi

mkdevs
mountfilesystems

for spec in $specfiles; do

    case "$spec" in
	*/*) specdir=${spec%/*}; spec=${spec##*/} ;;
	*) specdir=. ;;
    esac

    pushd $specdir

    echo -n "start $spec at " >> "$buildroot/.build.packages"
    date >> "$buildroot/.build.packages"

    getneededforbuild $spec

    if [ "$doinit" -eq 1 ]; then
	installpackages
	if [ ! -e $buildroot/dev/null ]; then
	    # missing nodes if devs got uninstalled
	    mkdevs
	fi
	copyextrafiles
	runsuseconfig
	runldconfig
    fi

    copysourcestobuildroot

    addbuilduser

    setupicecream

    setupccache

    createuserrpmmacros

    installgpgkey

    determinerpmversion

    setmemorylimit

    echo sync ... 
    sync
    echo -----------------------------------------------------------------
    echo "----- building $spec (user $builduser)"
    echo -----------------------------------------------------------------
    echo -----------------------------------------------------------------

    toshellscript $rpmbuild \
	-b$rpmbuildstage "${rpmbopts[@]}" "${definesnstuff[@]}" \
	/usr/src/packages/SOURCES/$spec \
	> $buildroot/.build.command
    chmod 755 $buildroot/.build.command
    chroot "$buildroot" su - $builduser -c /.build.command < /dev/null

    docreate_baselibs

    success=1;
    echo -n "done $spec at " >> "$buildroot/.build.packages"
    date >> "$buildroot/.build.packages"

    copyfilestorepository

    popd

done

# vim:sw=4
