rpmbs 7.6 KB
Newer Older
1 2 3 4 5 6
#!/bin/bash
# (c) Etersoft 2003-2006
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
# BS - build source
7
#
8 9 10 11 12 13 14 15 16 17 18
#      
# :
# -  -
# -  
#    -s,  
#    --nodeps,    
#    -u,    incoming
#    -d,   incoming
#   -n,    
# TODO: -r

19 20
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
21
load_mod rpm
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 68 69 70 71 72 73 74 75 76 77 78 79 80

SIGN=
UPLOADNOW=
CHECKONLY=
NOSOURCE=
NOCHECK=
UPDATES=
DELETENOW=


#############################
Usage="Usage: $name [-s -u -c -n --nodeps] spec..."
function mygetopts()
{
name=${0##*/}
Descr="$name - make src.rpm from spec"

phelp()
{
	echog "$Descr"
	echog "$Usage"
	echog "Options:"
	echog " -s - sign package(s) and move it to upload dir"
	echog " -c - only sign package(s) with checking"
	echog " -u - sign package(s) and upload it to Incoming (backports)"
	echog " -U - sign package(s) and upload it to Incoming (updates)"
	echog " -d - remove package(s) from SRPMS and Incoming"
	echog " -n - do not check with sisyphus_check before upload"
	echog " -o - create nosrc.rpm package"
	echog " -z - create src.rpm with compatible gzip compression"
}

while getopts :hscuUdnoz opt; do
    case $opt in
    h) phelp; exit 0;;
    s) SIGN=1 ;;
    c) CHECKONLY=1 ; SIGN=1 ;;
    u) UPLOADNOW=1 ; SIGN=1 ;;
    U) UPLOADNOW=1 ; SIGN=1 ; UPDATES=1 ;;
    n) NOCHECK=1; ;;
    o) NOSOURCE=1; ;;
    z) export USE_LEGACY_COMPRESSION=1;
       ;;
    d) DELETENOW=1 ;;
    +?) 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=$@

}

81 82 83 84 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 114 115 116 117 118 119 120 121 122
# TODO: include in sisyphus_check
# ,       MENV
function release_check()
{
	if [ "$MENV" = "SS" ] || [ "$MENV" = "DD" ] ; then
		for i in $@ ; do
			if [ -z "${i/*alt[0-9].M[0-9][0-9]*/}" ] ; then
				#    
				fatal "Incorrect release in $i package: was prepared for Sisyphus"
			fi
		done
		return
	fi
	for i in $@ ; do
		if [ -n "${i/*alt[0-9].$MENV*/}" ] ; then
			#    
			fatal "Incorrect release in $i package: was prepared for $MENV"
		fi
	done
}

# create tag according to package release
check_gear_and_tag()
{
	local SPECDIR=$1
	local GEARCTAG=gear-create-tag

	# set SPECDIR from LISTNAMES if empty
	if [ -r "$LISTNAMES" ] ; then
		[ -n "$SPECDIR" ] || SPECDIR=`dirname $LISTNAMES`
	fi

	if is_gear $SPECDIR ; then
		# needed correct user.name/user.email for get GPG id
		pushd $SPECDIR
		$GEARCTAG --force
		popd >/dev/null
		# git push ?
	fi
}


123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
parse_cmd_pre "$@"
# quotes brokes option handling
mygetopts $LISTARGS

#############################
LISTBUILT=""
CURDIR=`pwd`

if [ -n "$NOSOURCE" ] ; then
	$RPMBUILD -bs --nosource 0 $LISTNAMES
	exit $?
fi

#    src.rpm
# FIXME: -s can be in name... (but not in option!)
#LISTRPMARGS=
#LISTRPMARGS=${LISTRPMARGS/-m/}
#echo "@@ - $LISTRPMARGS - '$MENV'"
141 142 143 144 145 146 147 148 149 150 151 152 153 154

# set SPECDIR from LISTNAMES if empty
if [ -r "$LISTNAMES" ] ; then
	[ -n "$SPECDIR" ] || SPECDIR=`dirname $LISTNAMES`
fi

# If we build from gear repo, run task
if [ -n "$UPLOADNOW" ] && is_gear $SPECDIR ; then
	echo "Run with gear repo..."
	build_rpms_name "$LISTNAMES"
	release_check
	check_gear_and_tag
	$ETERBUILDBIN/gpush || fatal "Git push failed. Possibly you need to run ginit for create remote repo."
	TAG=$VERSION-$RELEASE
155 156 157
	ssh $GIRARHOST task new
	ssh $GIRARHOST task add repo $BASENAME $TAG || ssh $GIRARHOST task rm
	ssh $GIRARHOST task run
158
	echo "run task $BASENAME with tag $TAG at $GIRARHOST ($MENV) at `date "+%c"`" >>$RPMDIR/uploaded.log
159 160 161
	exit
fi

162 163 164 165 166 167 168 169 170 171 172 173 174 175
pack_src_rpm ${LISTRPMARGS}

#LISTARGS=${LISTARGS/-s/}
if  [ -n "$REMOTEBUILD" ] ; then
	fatal "Do not realized yet"
	check_key
	REMCOM="ssh $BUILDSERVER"

	echo
	echog "############ Build at build server `$BUILDSERVER` ############"
	echo
	echog "==== Copying to build server ====="
	#echog "It is recommended to rename old version at server for save traffic during rsync"
	rsync -vay --partial --progress --checksum \
176
	 	-e ssh $LISTBUILT $BUILDSERVER:/$RPMTOPDIR/SRPMS/ || exit 1
177 178 179 180 181
	$REMCOM rpmbs --helper $MENVARG $LISTRPMARGS $LISTBUILT
	exit 0
fi


182 183
#set_incoming $MENV
set_binaryrepo $MENV
184 185

if [ -n "${DELETENOW}" ]; then
186 187
	echog "Removing did not realized yet"
	exit 1
188 189 190 191 192 193 194 195 196 197 198
	echog "Removing from '$RSYNCINCOMING/$INCOMING/'"
	check_key
	for i in $LISTBUILT ; do
		> $i
	done
	rsync -vay --partial --progress --delete \
	 	-e ssh $LISTBUILT $RSYNCINCOMING/$INCOMING/
	echo "$i REMOVED from Incoming/$INCOMING ($MENV) at `date "+%c"`" >>$RPMDIR/uploaded.log
	exit 0
fi

199 200
if [ -n "$SIGN" ]; then
	release_check $LISTBUILT
201 202

	if [ -r "$LISTBUILT" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
203
		check_gear_and_tag
204
	fi
205

206 207 208 209
	echog "Will try to sign follow packages with GPG: \$LISTBUILT"
	# 1. only rpm command has --addsign 2. do 3 retries
	rpm --addsign $LISTBUILT || rpm --addsign $LISTBUILT || rpm --addsign $LISTBUILT
	RET=$?
210

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
	############################################
	echog "Changing permissions..."
	chmod 644 -- $LISTBUILT || fatal "can't chmod"
	echog -n "Checking with sisyphus_check..."
	test -n "$NOCHECK" || sisyphus_check --files $LISTBUILT || fatal "sisyphus check failed"
	echog "OK"
	# rpm's find-req do not find rpmlint :)
	RPMLINT=rpmlint
	if which $RPMLINT >/dev/null ; then
		echog -n "Checking with rpmlint..."
	echo
		$RPMLINT $LISTBUILT
	else
		echog "It is recommended to install rpmlint package for additional checking"
	fi
	test -n "$CHECKONLY" && exit 0
	############################################
	
	if [ "$RET" = "0" ]
	then
		if [ -n "${UPLOADNOW}" ] ; then
232
			echog "Uploading to $GIRARHOST"
233
			check_key
234 235
			# TODO:  rsync foo.src.rpm git.alt: && ssh git.alt build srpm foo.src.rpm
			# git.alt build -b 4.0 srpm foo.src.rpm
236
			rsync -vay --partial --progress $CHECKSUM \
237
			 	-e ssh $LISTBUILT $GIRARHOST: && \
238 239
			echo "---------------------" && \
			echog "All files synced" || fatal "Error during rsync"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
240

241 242 243 244 245 246 247
			TASKLIST=""
			for i in $LISTBUILT ; do
				TASKLIST="$TASKLIST srpm $(basename $i)"
			done
			echo "Create task for $TASKLIST"
			ssh $GIRARHOST build -b $BINARYREPO $TASKLIST

248 249 250 251 252
			for i in $LISTBUILT ; do
				LOGFILE="$LOGDIR/`basename $i .src.rpm`$MENVARG.log"
				echo >>$LOGFILE
				date >>$LOGFILE
				echo "uploaded">>$LOGFILE
253
				echo "$(basename $i) run build src.rpm at $GIRARHOST ($MENV) at `date "+%c"`" >>$RPMDIR/uploaded.log
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
			done

		else
			test -z "$ETERDESTSRPM" && ETERDESTSRPM=$UPLOADDIR${MENVARG/-/.}
			mkdir -p $ETERDESTSRPM || echog "Error mkdir $ETERDESTSRPM"
			echog "Copying package(s) in \$ETERDESTSRPM"
			cp -fv $LISTBUILT $ETERDESTSRPM || echog "Error during copying"
		fi

		echog "Removing buildroot after upload..."
		for i in $LISTNAMES ; do
			if [ -z ${i/*.src.rpm/} ] ; then
				echo "  skipping for $i"
				continue
			fi
			#DDIR=$BUILDROOT/${i/.spec/-buildroot}
			# Hack about paths
			test -f "$i" && NAME=$i || NAME=$CURDIR/$i
			build_rpms_name $NAME
			echo -n "    $BUILDROOT "
			if [ -d "$BUILDROOT" ] ; then
275
				rm -rf "$BUILDROOT" && echog "DONE" || echog "failed"
276
			else
277
				echog "missed"
278 279 280 281 282 283 284 285 286 287
			fi
		done


	else
		echog "Impossible to sign package. Check your password and try again."
		echog "Wait for ten seconds."
		sleep 10
		exit 1
	fi
288 289 290 291 292 293 294
else
	if [ -n "$ETERDESTSRPM" ] ; then
		mkdir -p $ETERDESTSRPM || echog "Error mkdir $ETERDESTSRPM"
		echog "Copying package(s) in \$ETERDESTSRPM"
		cp -fv $LISTBUILT $ETERDESTSRPM || echog "Error during copying"
	fi

295
fi