myhsh 4.11 KB
Newer Older
1
#!/bin/bash
2
# 2003-2006, 2008 (c) Etersoft www.etersoft.ru
3 4 5 6 7 8
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
#   SRPM-  hasher
# -i    hasher  

9 10
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
11
load_mod hasher
12 13

#############################
14
Usage="Usage: $name [-m -s -u -i -c] src.rpm..."
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
function mygetopts()
{
name=${0##*/}
Descr="$name - build package via hasher"

phelp()
{
	echog "$Descr"
	echog "$Usage"
	echog "Options:"
	echog " -s - sign package(s)"
	echog " -u - sign and upload package(s) to Incoming"
	echog " -i - install built packages in test hasher"
	echog " -c - build without stuff (previous built packages)"
}

while getopts :hmic opt; do
    case $opt in
    h) phelp; exit 0;;
    i) TESTINSTALL=1;;
	c) HASHERARG="--without-stuff $HASHERARG";;
    +?) echog "$name: options should not be preceded by a '+'." 1>&2; exit 2;;
#    ?)  echog "$name: $OPTARG: bad option.  Use -h for help." 1>&2 ; exit 2;;
	?) OPTIND=$((OPTIND-1)); break;
    esac
done
 
# remove args that were options
if [ $# -gt 0 ]; then 
	shift $((OPTIND - 1))
fi

LISTRPMARGS=$@
}


parse_cmd_pre "$@"
mygetopts $LISTARGS

RESULT=0

HASHERDIR=$HASHERDIR$MENVARG
mkdir -p $LOGDIR $HASHERDIR || fatal "cannot mkdir"
check_locking

HSH=/usr/bin/hsh
if [ ! -x "$HSH" ] ; then
	echo "Please install hasher package before use it"
	exit 1
fi

echog "List of packages: \$LISTNAMES"

68
if [ -z "${LISTNAMES/*spec/}"  ] ; then
69 70 71 72
	echo "!!!!!!!!"
	fatal "Please use src.rpm as argument, not spec"
fi

73 74 75 76 77 78
# Skip checking for tar arg
if [ -n "${LISTNAMES/*tar/}" ] ; then
	echog -n "Checking with sisyphus_check..."
	sisyphus_check --no-check=$HASHER_NOCHECK --files $LISTNAMES || fatal "check for sisyphus failed"
	echog "OK"
fi
79

Vitaly Lipatov's avatar
Vitaly Lipatov committed
80 81 82
# export OURAPTCONF with temp. file contains correct path to sources.list
prepare_aptconfig

83
# TODO: for add $LISTRPMARGS we need skip function for delete "our" params
Vitaly Lipatov's avatar
Vitaly Lipatov committed
84
HASHERARG="--no-sisyphus-check=$HASHER_NOCHECK --apt-config=$OURAPTCONF --target $DEFAULTARCH $HASHERARG"
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
if [ "$MENV" != "SS" ] && [ "$MENV" != "DD" ]; then
	HASHERARG="--build-args \"--with=build_$MENV\" --build-args \"--with=build_backport\" $HASHERARG"
fi
LISTBUILTSH=""
for i in $LISTNAMES
do
	# !        
	# --nprocs=2 
	# Note: hasher is already use renice for low priority
	LOGFILE="$LOGDIR/`basename $i .src.rpm`$MENVARG.log"
	echo "Build in hasher ($MENV)" >$LOGFILE
	rm -f $LOGFILE.failed
	# enable /proc support only if require it
	#rpm --requires -p $i | grep "/proc" && ARG="$HASHERARG --mountpoints=/proc" || ARG="$HASHERARG"
	# we do not need check cases for mount points, thanks ldv@ 
	ARG="$HASHERARG --mountpoints=/proc,/dev/pts"
	echog "Build in hasher: $i (arg: $ARG, distro: $MENV, hasherdir: $HASHERDIR)"

	($HSH $ARG --build-args "--define 'backport_distro ${MENV}'" -- $HASHERDIR $i 2>&1 || touch $LOGFILE.failed) | tee -a $LOGFILE
	test -L $HASHERDIR/BUILD || ln -s chroot/usr/src/RPM/BUILD $HASHERDIR/
	if [ -f $LOGFILE.failed ] ;	then
		RESULT=1
		break
	fi
	check_log $LOGFILE ; RESULT=$?
	test $RESULT = 1 && break
	echog "########## Build of `basename $i` is done in hasher $MENV  #############"
	echo
	LISTBUILTSH="$LISTBUILTSH$i "
114
	LASTPACKAGE=$i
115 116 117 118 119 120 121 122 123
done

echo
if [ "$RESULT" = "1" ] ; then
	echog "!!!!!!! Hasher: FAILED FAILED FAILED !!!!!!!!!"
	echog "Failed with $i, built only"
else
	echog "Full list of the hashered packages:"
fi
124
print_list $LISTBUILTSH
125 126 127 128 129 130 131

echo


if [ "$RESULT" = "0" -a -n "$TESTINSTALL" ] ; then
	# test install (only for last package in list)
	# some key for build hasher from scratch
132 133
	echog "Find binary packages for $LASTPACKAGE ..."
	BINPACKAGES=`get_binpkg_list $HASHERDIR/repo/$DEFAULTARCH/RPMS.hasher $LASTPACKAGE`
Vitaly Lipatov's avatar
Vitaly Lipatov committed
134
	test -n "$BINPACKAGES" || fatal "Can't find binary packages for $LASTPACKAGE in `ls -l $HASHERDIR/repo/$DEFAULTARCH/RPMS.hasher`"
135 136 137 138 139
	echo "List: $BINPACKAGES"
	echo
	loginhsh -t -i $MENVARG $BINPACKAGES || exit 1
fi

140
# make src.rpm if need
141 142 143 144 145
if [ "$RESULT" = "0" ] ; then
	test -n "$LISTRPMARGS" && rpmbs $MENVARG $LISTRPMARGS $LISTBUILTSH
fi

exit $RESULT