rpmbs 6.69 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 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

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=$@

}

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'"
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 \
113
	 	-e ssh $LISTBUILT $BUILDSERVER:/$RPMTOPDIR/SRPMS/ || exit 1
114 115 116 117 118 119 120 121 122 123
	$REMCOM rpmbs --helper $MENVARG $LISTRPMARGS $LISTBUILT
	exit 0
fi

# TODO: include in sisyphus_check
# ,       MENV
function release_check()
{
	if [ "$MENV" = "SS" ] || [ "$MENV" = "DD" ] ; then
		for i in $@ ; do
124
			if [ -z "${i/*alt[0-9].M[0-9][0-9]*/}" ] ; then
125 126 127 128 129 130 131
				#    
				fatal "Incorrect release in $i package: was prepared for Sisyphus"
			fi
		done
		return
	fi
	for i in $@ ; do
132
		if [ -n "${i/*alt[0-9].$MENV*/}" ] ; then
133 134 135 136 137 138
			#    
			fatal "Incorrect release in $i package: was prepared for $MENV"
		fi
	done
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
139
set_incoming $MENV
140 141 142 143 144 145 146 147 148 149 150 151 152

if [ -n "${DELETENOW}" ]; then
	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

153 154
# create tag according to package release
check_gear_and_tag()
155
{
156
	local SPECDIR=$1
157
	local GEARCTAG=gear-create-tag
158 159 160

	# set SPECDIR from LISTNAMES if empty
	if [ -r "$LISTNAMES" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
161 162
		[ -n "$SPECDIR" ] || SPECDIR=`dirname $LISTNAMES`
	fi
163

164
	if is_gear $SPECDIR ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
165
		# needed correct user.name/user.email for get GPG id
Vitaly Lipatov's avatar
Vitaly Lipatov committed
166
		pushd $SPECDIR
167
		$GEARCTAG --force
168
		popd >/dev/null
Vitaly Lipatov's avatar
Vitaly Lipatov committed
169 170
		# git push ?
	fi
171 172 173 174
}

if [ -n "$SIGN" ]; then
	release_check $LISTBUILT
175 176

	if [ -r "$LISTBUILT" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
177
		echo if one spec, check gear
Vitaly Lipatov's avatar
Vitaly Lipatov committed
178
		[ -n "$SPECDIR" ] || SPECDIR=`dirname $LISTNAMES`
179
		check_gear_and_tag $SPECDIR
180
	fi
181

182 183 184 185
	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=$?
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	############################################
	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
			echog "Uploading to '$RSYNCINCOMING/$INCOMING/'"
			check_key
			rsync -vay --partial --progress $CHECKSUM \
			 	-e ssh $LISTBUILT $RSYNCINCOMING/$INCOMING/ && \
			echo "---------------------" && \
			echog "All files synced" || fatal "Error during rsync"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
214

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
			for i in $LISTBUILT ; do
				LOGFILE="$LOGDIR/`basename $i .src.rpm`$MENVARG.log"
				echo >>$LOGFILE
				date >>$LOGFILE
				echo "uploaded">>$LOGFILE
				echo "$i uploaded to Incoming/$INCOMING ($MENV) at `date "+%c"`" >>$RPMDIR/uploaded.log
			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
242
				rm -rf "$BUILDROOT" && echog "DONE" || echog "failed"
243
			else
244
				echog "missed"
245 246 247 248 249 250 251 252 253 254
			fi
		done


	else
		echog "Impossible to sign package. Check your password and try again."
		echog "Wait for ten seconds."
		sleep 10
		exit 1
	fi
255 256 257 258 259 260 261
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

262
fi