Blame scripts/create_sig.sh

Thomas Oulevey 79d958
#!/bin/bash
Thomas Oulevey 79d958
Thomas Oulevey 79d958
usage()
Thomas Oulevey 79d958
{
Thomas Oulevey 79d958
cat << EOF
Thomas Oulevey 79d958
usage: $0 -d <distribution> -s <signame(s)> -t <tag(s)>
Thomas Oulevey 79d958
Thomas Oulevey 79d958
This script generate new build target in koji for SIGS.
Thomas Oulevey 79d958
Thomas Oulevey 79d958
OPTIONS:
Thomas Oulevey b45599
   -a   ARCHES             	     : Force arches e.g : "x86_64","aarch64 i686", etc...
Thomas Oulevey b6e300
   -b                            : Enable non public bootstrap repo (SCLO SIG only)
Thomas Oulevey b45599
   -c   COLLECTION               : Enable collection in the buildroot e.g : mariadb100
Thomas Oulevey b6e300
   -d   DISTRIBUTION             : 5 6 7
Thomas Oulevey b6e300
   -p   SIG PROJECT NAME         : cloud6-<openstack>, sclo-<mariadb100>, etc...
Thomas Oulevey b6e300
   -r   SIG PROJECT RELEASE NAME : cloud6-openstack-<juno>
Thomas Oulevey b6e300
   -s   SIG NAME                 : cloud
Thomas Oulevey b6e300
   -t   DISTTAGS                 : "el7 el7.centos el7_0"
Thomas Oulevey b6e300
   -x                            : delete old -build tag and then recreate.
Thomas Oulevey 79d958
EOF
Thomas Oulevey 79d958
}
Thomas Oulevey 79d958
Thomas Oulevey 6beb7b
optiona=false
Thomas Oulevey c8919e
optionb=false
Thomas Oulevey 79d958
optiond=false
Thomas Oulevey 79d958
options=false
Thomas Oulevey 79d958
optiont=false
Thomas Oulevey 3946d6
optionc=false
Thomas Oulevey 83c282
optionp=false
Thomas Oulevey 83c282
optionr=false
Thomas Oulevey cac957
optionx=false
Thomas Oulevey 79d958
Thomas Oulevey 6beb7b
while getopts ":hxba:d:s:t:c:p:r:" OPTION
Thomas Oulevey 79d958
do
Thomas Oulevey 79d958
        case $OPTION in
Thomas Oulevey 79d958
        h)
Thomas Oulevey 79d958
             usage
Thomas Oulevey 79d958
             exit 0
Thomas Oulevey 79d958
             ;;
Thomas Oulevey 6beb7b
	a)
Thomas Oulevey 6beb7b
	     optiona=true
Thomas Oulevey 6beb7b
	     ARCHES="${OPTARG}"
Thomas Oulevey 6beb7b
	     ;;
Thomas Oulevey c8919e
	b)
Thomas Oulevey c8919e
	     optionb=true
Thomas Oulevey c8919e
	     ;;
Thomas Oulevey 79d958
	d)
Thomas Oulevey 79d958
	     optiond=true
Thomas Oulevey 79d958
	     DISTS="${OPTARG}"
Thomas Oulevey 79d958
	     ;;
Thomas Oulevey 79d958
	s)
Thomas Oulevey 79d958
	     options=true
Thomas Oulevey 79d958
	     SIGS="${OPTARG}"
Thomas Oulevey 79d958
	     ;;
Thomas Oulevey 83c282
	r)
Thomas Oulevey 83c282
	     optionr=true
Thomas Oulevey 83c282
	     RELEASES="${OPTARG}"
Thomas Oulevey 83c282
	     ;;
Thomas Oulevey 83c282
	p)
Thomas Oulevey 83c282
	     optionp=true
Thomas Oulevey 83c282
	     PROJECTS="${OPTARG}"
Thomas Oulevey 83c282
	     ;;
Thomas Oulevey 79d958
	t)
Thomas Oulevey 79d958
	     optiont=true
Thomas Oulevey 79d958
	     TAGS="${OPTARG}"
Thomas Oulevey 79d958
	     ;;
Thomas Oulevey 3946d6
	c)
Thomas Oulevey 3946d6
	     optionc=true
Thomas Oulevey 3946d6
	     COLLECTIONS="${OPTARG}"
Thomas Oulevey 3946d6
	     ;;
Thomas Oulevey cac957
	x)
Thomas Oulevey cac957
	     optionx=true
Thomas Oulevey cac957
	     ;;
Thomas Oulevey 79d958
        ?)
Thomas Oulevey 79d958
             exit 0
Thomas Oulevey 79d958
             ;;
Thomas Oulevey 79d958
        :)
Thomas Oulevey 79d958
             echo "Option -$OPTARG requires an argument."
Thomas Oulevey 79d958
             exit 1
Thomas Oulevey 79d958
             ;;
Thomas Oulevey 79d958
        esac
Thomas Oulevey 79d958
done
Thomas Oulevey 79d958
Thomas Oulevey 79d958
shift $(($OPTIND - 1))
Thomas Oulevey 79d958
Thomas Oulevey 79d958
if ! ( $optiond && $options && $optiont  )
Thomas Oulevey 79d958
then
Thomas Oulevey 79d958
	usage
Thomas Oulevey 05da88
	exit 0
Thomas Oulevey 79d958
fi
Thomas Oulevey 79d958
Thomas Oulevey 79d958
# Check if user is allowed to send command to koji and has 'admin' permission
Thomas Oulevey 79d958
KOJI=`which koji`
Thomas Oulevey 9f5c13
PERMS=`$KOJI list-permissions --mine`
Thomas Oulevey 9f5c13
ADMIN=false
Thomas Oulevey 899051
CONFIG_PATH="$(dirname $BASH_SOURCE)/sigs"
Thomas Oulevey 9f5c13
Thomas Oulevey 9f5c13
for P in $PERMS
Thomas Oulevey 9f5c13
do
Thomas Oulevey 07fbc4
    [[ $P == 'admin' ]] && ADMIN=true && break
Thomas Oulevey 9f5c13
done
Thomas Oulevey 9f5c13
Thomas Oulevey 9f5c13
if [ "$ADMIN" != true ]
Thomas Oulevey 79d958
then
Thomas Oulevey 79d958
	echo "[ERROR] Koji misconfigure/missing admin privilege for creating SIG tags"
Thomas Oulevey 79d958
	exit 1
Thomas Oulevey 79d958
fi
Thomas Oulevey 79d958
Thomas Oulevey 79d958
for DIST in $DISTS
Thomas Oulevey 79d958
do
Thomas Oulevey 79d958
Thomas Oulevey 79d958
	case $DIST in
Thomas Oulevey 6beb7b
		5) echo "* Checking distribution el$DIST configuration..."; ( ! $optiona ) && ARCHES="i386 x86_64"; DEFAULT_DISTTAG="el5"
Thomas Oulevey 79d958
		;;
Thomas Oulevey 6beb7b
		6) echo "* Checking distribution el$DIST configuration...";  ( ! $optiona ) &&  ARCHES="i686 x86_64"; DEFAULT_DISTTAG="el6"
Thomas Oulevey 79d958
		;;
Thomas Oulevey 6beb7b
		7) echo "* Checking distribution el$DIST configuration...";  ( ! $optiona ) && ARCHES="x86_64"; DEFAULT_DISTTAG="el7.centos"
Thomas Oulevey 79d958
		;;
Thomas Oulevey 79d958
		*) echo "It seems your distribution el${DIST} is unsupported" && continue
Thomas Oulevey 79d958
		;;
Thomas Oulevey 79d958
	esac
Thomas Oulevey 79d958
Thomas Oulevey 79d958
	$KOJI list-tags | grep buildsys${DIST} &> /dev/null
Thomas Oulevey 79d958
	[ $? -gt 0 ] && echo " -> [ERROR] Something is wrong buildsys${DIST} tag not found." && continue
Thomas Oulevey 79d958
Thomas Oulevey 05da88
	$KOJI list-external-repos | grep ^centos${DIST}-extras &> /dev/null
Thomas Oulevey 05da88
	[ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-extras external repo not configured in koji." && continue
Thomas Oulevey 05da88
Thomas Oulevey 79d958
	$KOJI list-external-repos | grep ^centos${DIST}-os &> /dev/null
Thomas Oulevey 79d958
	[ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-os external repo not configured in koji." && continue
Thomas Oulevey 79d958
Thomas Oulevey 79d958
	$KOJI list-external-repos | grep ^centos${DIST}-updates &> /dev/null
Thomas Oulevey 79d958
	[ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-updates external repo not configured in koji." && continue
Thomas Oulevey 79d958
Thomas Oulevey 79d958
	for SIG in $SIGS
Thomas Oulevey 79d958
	do
Thomas Oulevey 899051
		# reset values from SIG configuation file
Thomas Oulevey 899051
		BUILDROOT_DEFAULT=""
Thomas Oulevey 899051
Thomas Oulevey 79d958
		echo " -> Checking $SIG config..."
Thomas Oulevey 79d958
		$KOJI add-user $SIG &> /dev/null
Koji buildservice 373f55
		[ $? -eq 0 ] && echo "Creating user : ${SIG}" && $KOJI grant-permission --new build-${SIG} $SIG
Thomas Oulevey 1b16cb
		SIGNAME="${SIG}"
Thomas Oulevey 79d958
		SIG="${SIG}${DIST}"
Thomas Oulevey e5943c
		# Check for SIG-common and create it if not present.
Thomas Oulevey e5943c
		# $KOJI list-tags | grep $SIG-common-candidate &> /dev/null
Thomas Oulevey 83c282
		for PROJECT in $PROJECTS
Thomas Oulevey 79d958
		do
Thomas Oulevey 2844b0
            P_SIG="${SIG}-${PROJECT}"
Thomas Oulevey b6e300
            # Add sig project options here FIXME add a command line option for oneshot buildroot fixes.
Thomas Oulevey b6e300
            case ${PROJECT} in
Thomas Oulevey b6e300
                openstack)
Thomas Oulevey b6e300
                    echo "Reading ${PROJECT} additional configs..."
Haikel Guemar 92ddfe
                    BUILDROOT_PKGS_EXTRAS="openstack-macros"
Thomas Oulevey 2844b0
                    ;;
Thomas Oulevey b6e300
                *)
Thomas Oulevey b6e300
                    BUILDROOT_PKGS_EXTRAS=""
Thomas Oulevey b6e300
		        ;;
Thomas Oulevey b6e300
            esac
Thomas Oulevey b6e300
Thomas Oulevey 83c282
			# Check for -common
Thomas Oulevey 83c282
			#$KOJI list-tags | grep $P_SIG-common-candidate &> /dev/null
Thomas Oulevey 83c282
			#if [ $? -gt 0 ]
Thomas Oulevey 83c282
			#then
Thomas Oulevey 83c282
			#	echo "Creating tag  : ${P_SIG}-common"
Thomas Oulevey 83c282
			#	$KOJI add-tag $P_SIG-common-candidate
Thomas Oulevey 05da88
			#
Thomas Oulevey 05da88
			#fi
Thomas Oulevey 83c282
			for RELEASE in $RELEASES
Thomas Oulevey 83c282
			do
Thomas Oulevey 83c282
				R_SIG="${P_SIG}-${RELEASE}"
Thomas Oulevey 83c282
				$KOJI list-tags | grep $R_SIG-candidate &> /dev/null
Thomas Oulevey cde2c6
				[ $? -gt 0 ] && echo "Creating tag  : ${R_SIG}-candidate" && $KOJI add-tag $R_SIG-candidate && $KOJI edit-tag $R_SIG-candidate --perm=build-${SIGNAME}
Thomas Oulevey 83c282
				$KOJI list-tags | grep $R_SIG-testing &> /dev/null
Thomas Oulevey cde2c6
				[ $? -gt 0 ] && echo "Creating tag  : ${R_SIG}-testing" && $KOJI add-tag $R_SIG-testing && $KOJI edit-tag $R_SIG-testing --perm=build-${SIGNAME}
Thomas Oulevey 83c282
				$KOJI list-tags | grep $R_SIG-release &> /dev/null
Thomas Oulevey cde2c6
				[ $? -gt 0 ] && echo "Creating tag  : ${R_SIG}-release" && $KOJI add-tag $R_SIG-release && $KOJI edit-tag $R_SIG-release --perm=build-${SIGNAME}
Thomas Oulevey 83c282
Thomas Oulevey 83c282
				for TAG in $TAGS
Thomas Oulevey 83c282
				do
Thomas Oulevey 83c282
					# Add collection support abuse TAG variable
Thomas Oulevey 83c282
					REALTAG=$TAG
Thomas Oulevey 83c282
					if ( $optionc )
Thomas Oulevey 83c282
					then
Thomas Oulevey 574d67
						# Abandon collection in the name for the tag, not pratical
Thomas Oulevey 574d67
						# TAG="$TAG-$COLLECTIONS"
Thomas Oulevey 574d67
						TAG="$TAG"
Thomas Oulevey 83c282
					fi
Thomas Oulevey 05da88
					$KOJI list-tags | grep $R_SIG-$TAG-build &> /dev/null
Thomas Oulevey cac957
					if [ $? -eq 0 ]
Thomas Oulevey cac957
					then
Thomas Oulevey cac957
						if ( $optionx )
Thomas Oulevey cac957
						then
Thomas Oulevey cac957
							echo " -> deleting buildroot $R_SIG-$TAG-build"
Thomas Oulevey cac957
							$KOJI remove-tag $R_SIG-$TAG-build
Thomas Oulevey cac957
						else
Thomas Oulevey cac957
							echo " -> $R_SIG-$TAG-build tag already exists. skipping." && continue
Thomas Oulevey cac957
						fi
Thomas Oulevey cac957
					fi
Thomas Oulevey 83c282
					echo " -> creating $R_SIG-$TAG"
Thomas Oulevey 83c282
					$KOJI add-tag --arches "$ARCHES" $R_SIG-$TAG-build
Thomas Oulevey 83c282
					$KOJI add-target $R_SIG-$TAG $R_SIG-$TAG-build $R_SIG-candidate
Thomas Oulevey 1b16cb
					# For external repo priorites are increased by 5, Priority 5
Thomas Oulevey 05da88
					if [ "x$DIST" == "x7" ]
Thomas Oulevey 05da88
					then
Thomas Oulevey 05da88
						$KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-cr
Thomas Oulevey 05da88
					fi
Thomas Oulevey 05da88
					$KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-extras
Thomas Oulevey 83c282
					$KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-updates
Thomas Oulevey 83c282
					$KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-os
Thomas Oulevey c8919e
					# START bootstrap
Thomas Oulevey c8919e
					if ( $optionb )
Thomas Oulevey 899051
                   	then
Thomas Oulevey 1b16cb
						# START bootstrap for sclo
Thomas Oulevey 1b16cb
						if [ "x${SIGNAME}" == "xsclo" ]
Thomas Oulevey 899051
                		then
Thomas Oulevey 1b16cb
							# Priority 15
Thomas Oulevey 1b16cb
							$KOJI add-external-repo --tag=$R_SIG-$TAG-build sclo${DIST}-bootstrap
Thomas Oulevey 1b16cb
						fi
Thomas Oulevey c8919e
						# END bootstrap for scl
Thomas Oulevey c8919e
						# Other repo can be added here if needed in the future
Thomas Oulevey 1b16cb
						# if [ "x${SIGNAME}" == "xABC" ]
Koji buildservice 5925a2
						# Let's use $SIGNAME$DIST-bootstrap to be consistent
Thomas Oulevey c8919e
					fi
Thomas Oulevey c8919e
					# END bootstrap
Thomas Oulevey 83c282
					$KOJI add-group $R_SIG-$TAG-build build
Thomas Oulevey 83c282
					$KOJI add-group $R_SIG-$TAG-build srpm-build
Thomas Oulevey 83c282
					# Add <collection>-build to the buildroot if collection enabled
Thomas Oulevey 899051
					if [ -f $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh ]
Thomas Oulevey 899051
					then
Thomas Oulevey 899051
						echo "Using specific $SIGNAME/$PROJECT options: "
Thomas Oulevey 899051
						echo "###"
Thomas Oulevey 899051
						cat $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh
Thomas Oulevey 899051
						echo "###"
Thomas Oulevey 899051
						source $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh
Thomas Oulevey 899051
					else
Thomas Oulevey 899051
						BUILDROOT_DEFAULT="curl bash bzip2 coreutils cpio diffutils redhat-release findutils gawk gcc gcc-c++ grep gzip info make patch redhat-rpm-config rpm-build sed shadow-utils tar unzip util-linux-ng which buildsys-tools tar"
Thomas Oulevey 899051
					fi
Thomas Oulevey 83c282
					if ( $optionc )
Thomas Oulevey 899051
					then
Thomas Oulevey 899051
						$KOJI add-group-pkg $R_SIG-$TAG-build build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $COLLECTIONS-build scl-utils-build
Thomas Oulevey 899051
				        $KOJI add-group-pkg $R_SIG-$TAG-build srpm-build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $COLLECTIONS-build scl-utils-build
Thomas Oulevey 83c282
					else
Thomas Oulevey 899051
						$KOJI add-group-pkg $R_SIG-$TAG-build build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $BUILDROOT_PKGS_EXTRAS
Thomas Oulevey 899051
                        $KOJI add-group-pkg $R_SIG-$TAG-build srpm-build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $BUILDROOT_PKGS_EXTRAS
Thomas Oulevey 83c282
					fi
Thomas Oulevey 83c282
					$KOJI add-tag-inheritance --priority 5 $R_SIG-$TAG-build buildsys${DIST}
Thomas Oulevey 83c282
					$KOJI add-tag-inheritance --priority 10 $R_SIG-$TAG-build $R_SIG-candidate
Thomas Oulevey 83c282
					# If -common exists for the project add it
Thomas Oulevey 83c282
					if [ "x$RELEASE" != "xcommon" ]
Thomas Oulevey 83c282
					then
Thomas Oulevey 6558fb
						$KOJI list-tags | grep $P_SIG-common-candidate &> /dev/null
Thomas Oulevey 8a6c42
                                		[ $? -eq 0 ] && echo "Adding $P_SIG-common-candidate as inheritance" && $KOJI add-tag-inheritance --priority 15 $R_SIG-$TAG-build $P_SIG-common-candidate
Thomas Oulevey 83c282
					fi
Thomas Oulevey 1b16cb
					# Add SIG -common if it exists
Thomas Oulevey cac957
                                        $KOJI list-tags | grep $SIG-common-candidate &> /dev/null
Thomas Oulevey cac957
                                        [ $? -eq 0 ] && echo "Adding $SIG-common-candidate as inheritance" && $KOJI add-tag-inheritance --priority 20 $R_SIG-$TAG-build $SIG-common-candidate
Thomas Oulevey cac957
					# Check if disttag has corresponding buildsys-macros-disttag
Thomas Oulevey 83c282
					$KOJI list-tagged buildsys${DIST} | grep buildsys-macros-$REALTAG &> /dev/null
Thomas Oulevey 83c282
					if [ $? -gt 0 ] 
Thomas Oulevey 83c282
					then
Thomas Oulevey 83c282
						if [ "x$REALTAG" != "x$DEFAULT_DISTTAG" ]
Thomas Oulevey 83c282
						then
Thomas Oulevey 574d67
							echo " -> [WARN] buildsys-macros-$REALTAG rpm not found. Please build it within koji on target buildsys${DIST}"
Thomas Oulevey 1b16cb
							#TODO ; generate spec file from tempalte for overriding macros
Thomas Oulevey 83c282
							[ -f $PWD/etc/buildsys.spec.template ] && echo " -> Generating buildsys-macros-$TAG.spec"
Thomas Oulevey 83c282
						fi
Thomas Oulevey 83c282
					fi
Thomas Oulevey 83c282
				done
Thomas Oulevey 83c282
			done
Thomas Oulevey 79d958
		done
Thomas Oulevey 79d958
	done
Thomas Oulevey 79d958
done