#!/bin/bash # # Helper script for self-build rpm package. # arguments 1:package name, 2:spec file, 3 and on: source url # # NOTE: To avoid scriptlet failure during rpm transaction, # This script should always return 0 even if there is an error. TEXTDOMAIN=self-build-setup TEXTDOMAINDIR=/usr/share/locale _NAME=$1 _SPEC=$2 _ARCH=$(rpm --eval %_arch) _QUEDIR=/var/cache/self-build . /etc/self-build.conf echo -n " " echo -n $"Start creating rpm packages." echo "($_NAME)" # create temporary rpm directory if ! _TOPDIR=`mktemp -d $TEMP_DIR/$_NAME.XXXXXX`; then echo -n " " echo $"*ERROR: can't crete temporary directory." exit 0 fi mkdir $_TOPDIR/rpm mkdir $_TOPDIR/rpm/BUILD mkdir $_TOPDIR/rpm/RPMS mkdir $_TOPDIR/rpm/RPMS/$_ARCH mkdir $_TOPDIR/rpm/RPMS/noarch mkdir $_TOPDIR/rpm/SOURCES # copy patches and other files. cp -a /usr/share/$_NAME/* $_TOPDIR/rpm/SOURCES # get source echo -n " " echo $"Downloading source files..." shift 2 for u in $@; do _SRC=$_TOPDIR/rpm/SOURCES/$(basename $u) [ -s $_SRC ] && continue if [ ! $DL_SHOW_PROGRESS = "yes" ]; then # run quiet, no GUI wget -q -P $_TOPDIR/rpm/SOURCES $u RESULT=$? elif [ -z `pgrep -n synaptic` ]; then # run verbose, without GUI (because no synaptic running) wget -P $_TOPDIR/rpm/SOURCES $u RESULT=$? else # run verbose with GUI (zenity) wget -P $_TOPDIR/rpm/SOURCES $u 2>&1 | \ sed -u 's/.* \+\([0-9]\+%\).*$/\1/' 2>/dev/null | \ zenity --auto-close --progress \ --title $"Download files" \ --text $"Downloading $(basename $u)..." & # workaround for killing remaining wget process when cancel button pressed. WGETPID=`pgrep -f "wget -P $_TOPDIR/rpm/SOURCES $u"` ZENITYPID=$! # last child pid = zenity pid RESULT=0 # hold exit status of zenity RUNNING=0 while [ $RUNNING -eq 0 ] do sleep 1 if [ -z `ps -p $ZENITYPID -o pid=` ]; then if [ `ps -p $WGETPID -o pid=` ]; then # if zenity exited but wget still running, # then we suppose that zenity is cancelled by user. sleep 3 kill -KILL $WGETPID RESULT=1 fi RUNNING=1 fi done fi [ $RESULT -ne 0 -a -e $_SRC ] && rm -f $_SRC done for f in $(echo $@|xargs -r -n1 basename|sort -u); do if [ ! -s $_TOPDIR/rpm/SOURCES/$f ]; then echo -n " " echo $"*ERROR: can't download source file."": $f" rm -rf $_TOPDIR exit 0 fi done echo -n " " echo $"Source files download successfully." # build rpm package echo -n " " echo $"Building rpm packages..." echo -n " " echo $"(see $TEMP_DIR/$_NAME.log for detail.)" # now rpmbuild done by non-root user $BUILD_USER rm -f $TEMP_DIR/$_NAME.log chown -R $BUILD_USER:$BUILD_USER $_TOPDIR if su $BUILD_USER -c "rpmbuild -bb --define=\"_topdir $_TOPDIR/rpm\" /usr/share/$_NAME/$_SPEC > $TEMP_DIR/$_NAME.log 2>&1" > /dev/null 2>&1; then echo -n " " echo $"rpm packages are successfully built." if ls $_TOPDIR/rpm/RPMS/$_ARCH | grep -e "\.rpm$" > /dev/null ; then mv -f $_TOPDIR/rpm/RPMS/$_ARCH/*.rpm $_QUEDIR fi if ls $_TOPDIR/rpm/RPMS/noarch | grep -e "\.rpm$" > /dev/null ; then mv -f $_TOPDIR/rpm/RPMS/noarch/*.rpm $_QUEDIR fi rm -rf $_TOPDIR else echo -n " " echo $"*ERROR: can't build rpm packages." rm -rf $_TOPDIR exit 0 fi exit 0