remi / centos / cbs-tools

Forked from centos/cbs-tools 5 years ago
Clone
Blob Blame History Raw
#!/bin/bash

usage()
{
cat << EOF
usage: $0 -d <distribution> -s <signame(s)> -t <tag(s)>

This script generate new build target in koji for SIGS.

OPTIONS:
   -d           Distribution : 5 6 7
   -s		SIG name : bananas, storage 
   -t		DISTTAGS : "el7 el7.centos el7_0"
   -c		COLLECTION : mariadb100 (a single collection can be used at this time)
EOF
}

optiond=false
options=false
optiont=false
optionc=false

while getopts ":hd:s:t:c:" OPTION
do
        case $OPTION in
        h)
             usage
             exit 0
             ;;
	d)
	     optiond=true
	     DISTS="${OPTARG}"
	     ;;
	s)
	     options=true
	     SIGS="${OPTARG}"
	     ;;
	t)
	     optiont=true
	     TAGS="${OPTARG}"
	     ;;
	c)
	     optionc=true
	     COLLECTIONS="${OPTARG}"
	     ;;
        ?)
             exit 0
             ;;
        :)
             echo "Option -$OPTARG requires an argument."
             exit 1
             ;;
        esac
done

shift $(($OPTIND - 1))

if ! ( $optiond && $options && $optiont  )
then
	usage
	exit 0	
fi

# Check if user is allowed to send command to koji and has 'admin' permission
KOJI=`which koji`
PERM=`$KOJI list-permissions --mine`
if [ "$PERM" != "admin"  ]
then
	echo "[ERROR] Koji misconfigure/missing admin privilege for creating SIG tags"
	exit 1
fi

for DIST in $DISTS
do

	case $DIST in
		5) echo "* Checking distribution el$DIST configuration..."; ARCHES="i386 x86_64"; DEFAULT_DISTTAG="el5"
		;;
		6) echo "* Checking distribution el$DIST configuration..."; ARCHES="i686 x86_64"; DEFAULT_DISTTAG="el6"
		;;
		7) echo "* Checking distribution el$DIST configuration..."; ARCHES="x86_64"; DEFAULT_DISTTAG="el7.centos"
		;;
		*) echo "It seems your distribution el${DIST} is unsupported" && continue
		;;
	esac

	$KOJI list-tags | grep buildsys${DIST} &> /dev/null
	[ $? -gt 0 ] && echo " -> [ERROR] Something is wrong buildsys${DIST} tag not found." && continue

	$KOJI list-external-repos | grep ^centos${DIST}-os &> /dev/null
	[ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-os external repo not configured in koji." && continue

	$KOJI list-external-repos | grep ^centos${DIST}-updates &> /dev/null
	[ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-updates external repo not configured in koji." && continue

	for SIG in $SIGS
	do
		echo " -> Checking $SIG config..."
		$KOJI add-user $SIG &> /dev/null
		[ $? -eq 0 ] && echo "Creating user : ${SIG}"
		SIG="${SIG}${DIST}"
		$KOJI list-tags | grep $SIG-testing &> /dev/null
		[ $? -gt 0 ] && echo "Creating tag  : ${SIG}-testing" && $KOJI add-tag $SIG-testing 
		$KOJI list-tags | grep $SIG-release &> /dev/null
		[ $? -gt 0 ] && echo "Creating tag  : ${SIG}-release" && $KOJI add-tag $SIG-release

		for TAG in $TAGS
		do
			# Add collection support abuse TAG variable
			REALTAG=$TAG
			if ( $optionc )
			then
				TAG="$TAG-$COLLECTIONS"
			fi
			$KOJI list-tags | grep $SIG-$TAG-build &> /dev/null 
			[ $? -eq 0 ] && echo " -> $SIG-$TAG target already exists. skipping." && continue
			echo " -> creating $SIG-$TAG"
			$KOJI add-tag --arches "$ARCHES" $SIG-$TAG-build
			$KOJI add-target $SIG-$TAG $SIG-$TAG-build $SIG-testing
			$KOJI add-external-repo --tag=$SIG-$TAG-build centos${DIST}-updates
			$KOJI add-external-repo --tag=$SIG-$TAG-build centos${DIST}-os
			$KOJI add-group $SIG-$TAG-build build
			$KOJI add-group $SIG-$TAG-build srpm-build
			# Add <collection>-build to the buildroot if collection enabled
			if ( $optionc )
                        then
				$KOJI add-group-pkg $SIG-$TAG-build build 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-macros-$REALTAG tar buildsys-tools $COLLECTIONS-build
				$KOJI add-group-pkg $SIG-$TAG-build srpm-build bash buildsys-macros curl cvs redhat-release gnupg make redhat-rpm-config rpm-build shadow-utils buildsys-macros-$REALTAG tar buildsys-tools $COLLECTIONS-build
			else
				$KOJI add-group-pkg $SIG-$TAG-build build 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-macros-$REALTAG tar buildsys-tools
                                $KOJI add-group-pkg $SIG-$TAG-build srpm-build bash buildsys-macros curl cvs redhat-release gnupg make redhat-rpm-config rpm-build shadow-utils buildsys-macros-$REALTAG tar buildsys-tools
			fi
			$KOJI add-tag-inheritance --priority 1 $SIG-$TAG-build buildsys${DIST}
			$KOJI add-tag-inheritance --priority 2 $SIG-$TAG-build $SIG-testing
			$KOJI list-tagged buildsys${DIST} | grep buildsys-macros-$REALTAG &> /dev/null
			if [ $? -gt 0 ] 
			then
				if [ "x$REALTAG" != "x$DEFAULT_DISTTAG" ]
				then
					echo " -> [WARN] buildsys-macros-$REALTAG rpm not found. Please build it within koji."
					[ -f $PWD/etc/buildsys.spec.template ] && echo " -> Generating buildsys-macros-$TAG.spec"
				fi
			fi
		done
	done
done