hhorak / centos / cbs-tools

Forked from centos/cbs-tools 4 years ago
Clone

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 9df7b3
   -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 9df7b3
    a)
Thomas Oulevey 9df7b3
         optiona=true
Thomas Oulevey 9df7b3
         ARCHES="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    b)
Thomas Oulevey 9df7b3
         optionb=true
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    d)
Thomas Oulevey 9df7b3
         optiond=true
Thomas Oulevey 9df7b3
         DISTS="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    s)
Thomas Oulevey 9df7b3
         options=true
Thomas Oulevey 9df7b3
         SIGS="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    r)
Thomas Oulevey 9df7b3
         optionr=true
Thomas Oulevey 9df7b3
         RELEASES="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    p)
Thomas Oulevey 9df7b3
         optionp=true
Thomas Oulevey 9df7b3
         PROJECTS="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    t)
Thomas Oulevey 9df7b3
         optiont=true
Thomas Oulevey 9df7b3
         TAGS="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    c)
Thomas Oulevey 9df7b3
         optionc=true
Thomas Oulevey 9df7b3
         COLLECTIONS="${OPTARG}"
Thomas Oulevey 9df7b3
         ;;
Thomas Oulevey 9df7b3
    x)
Thomas Oulevey 9df7b3
         optionx=true
Thomas Oulevey 9df7b3
         ;;
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 9df7b3
    usage
Thomas Oulevey 9df7b3
    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 9df7b3
    echo "[ERROR] Koji misconfigure/missing admin privilege for creating SIG tags"
Thomas Oulevey 9df7b3
    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 9df7b3
    case $DIST in
Thomas Oulevey 9df7b3
        5) echo "* Checking distribution el$DIST configuration..."; ( ! $optiona ) && ARCHES="i386 x86_64"; DEFAULT_DISTTAG="el5"
Thomas Oulevey 9df7b3
        ;;
Thomas Oulevey 9df7b3
        6) echo "* Checking distribution el$DIST configuration...";  ( ! $optiona ) &&  ARCHES="i686 x86_64"; DEFAULT_DISTTAG="el6"
Thomas Oulevey 9df7b3
        ;;
Thomas Oulevey 9df7b3
        7) echo "* Checking distribution el$DIST configuration...";  ( ! $optiona ) && ARCHES="x86_64"; DEFAULT_DISTTAG="el7.centos"
Thomas Oulevey 9df7b3
        ;;
Thomas Oulevey 9df7b3
        *) echo "It seems your distribution el${DIST} is unsupported" && continue
Thomas Oulevey 9df7b3
        ;;
Thomas Oulevey 9df7b3
    esac
Thomas Oulevey 79d958
Thomas Oulevey 9df7b3
    $KOJI list-tags | grep buildsys${DIST} &> /dev/null
Thomas Oulevey 9df7b3
    [ $? -gt 0 ] && echo " -> [ERROR] Something is wrong buildsys${DIST} tag not found." && continue
Thomas Oulevey 79d958
Thomas Oulevey 9df7b3
    $KOJI list-external-repos | grep ^centos${DIST}-extras &> /dev/null
Thomas Oulevey 9df7b3
    [ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-extras external repo not configured in koji." && continue
Thomas Oulevey 05da88
Thomas Oulevey 9df7b3
    $KOJI list-external-repos | grep ^centos${DIST}-os &> /dev/null
Thomas Oulevey 9df7b3
    [ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-os external repo not configured in koji." && continue
Thomas Oulevey 79d958
Thomas Oulevey 9df7b3
    $KOJI list-external-repos | grep ^centos${DIST}-updates &> /dev/null
Thomas Oulevey 9df7b3
    [ $? -gt 0 ] && echo " -> [ERROR] centos${DIST}-updates external repo not configured in koji." && continue
Thomas Oulevey 79d958
Thomas Oulevey 9df7b3
    for SIG in $SIGS
Thomas Oulevey 9df7b3
    do
Thomas Oulevey 9df7b3
        # reset values from SIG configuation file
Thomas Oulevey 9df7b3
        BUILDROOT_DEFAULT=""
Thomas Oulevey 899051
Thomas Oulevey 9df7b3
        echo " -> Checking $SIG config..."
Thomas Oulevey 9df7b3
        $KOJI add-user $SIG &> /dev/null
Thomas Oulevey 9df7b3
        [ $? -eq 0 ] && echo "Creating user : ${SIG}" && $KOJI grant-permission --new build-${SIG} $SIG
Thomas Oulevey 9df7b3
        SIGNAME="${SIG}"
Thomas Oulevey 9df7b3
        SIG="${SIG}${DIST}"
Thomas Oulevey 9df7b3
        # Check for SIG-common and create it if not present.
Thomas Oulevey 9df7b3
        # $KOJI list-tags | grep $SIG-common-candidate &> /dev/null
Thomas Oulevey 9df7b3
        for PROJECT in $PROJECTS
Thomas Oulevey 9df7b3
        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 9df7b3
                ;;
Thomas Oulevey b6e300
            esac
Thomas Oulevey b6e300
Thomas Oulevey 9df7b3
            # Check for -common
Thomas Oulevey 9df7b3
            #$KOJI list-tags | grep $P_SIG-common-candidate &> /dev/null
Thomas Oulevey 9df7b3
            #if [ $? -gt 0 ]
Thomas Oulevey 9df7b3
            #then
Thomas Oulevey 9df7b3
            #   echo "Creating tag  : ${P_SIG}-common"
Thomas Oulevey 9df7b3
            #   $KOJI add-tag $P_SIG-common-candidate
Thomas Oulevey 9df7b3
            #
Thomas Oulevey 9df7b3
            #fi
Thomas Oulevey 9df7b3
            for RELEASE in $RELEASES
Thomas Oulevey 9df7b3
            do
Thomas Oulevey 9df7b3
                R_SIG="${P_SIG}-${RELEASE}"
Thomas Oulevey 9df7b3
                $KOJI list-tags | grep $R_SIG-candidate &> /dev/null
Thomas Oulevey 9df7b3
                [ $? -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 9df7b3
                $KOJI list-tags | grep $R_SIG-testing &> /dev/null
Thomas Oulevey 9df7b3
                [ $? -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 9df7b3
                $KOJI list-tags | grep $R_SIG-release &> /dev/null
Thomas Oulevey 9df7b3
                [ $? -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 9df7b3
                for TAG in $TAGS
Thomas Oulevey 9df7b3
                do
Thomas Oulevey 9df7b3
                    # Add collection support abuse TAG variable
Thomas Oulevey 9df7b3
                    REALTAG=$TAG
Thomas Oulevey 9df7b3
                    if ( $optionc )
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        # Abandon collection in the name for the tag, not pratical
Thomas Oulevey 9df7b3
                        # TAG="$TAG-$COLLECTIONS"
Thomas Oulevey 9df7b3
                        TAG="$TAG"
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    $KOJI list-tags | grep $R_SIG-$TAG-build &> /dev/null
Thomas Oulevey 9df7b3
                    if [ $? -eq 0 ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        if ( $optionx )
Thomas Oulevey 9df7b3
                        then
Thomas Oulevey 9df7b3
                            echo " -> deleting buildroot $R_SIG-$TAG-build"
Thomas Oulevey 9df7b3
                            $KOJI remove-tag $R_SIG-$TAG-build
Thomas Oulevey 9df7b3
                        else
Thomas Oulevey 9df7b3
                            echo " -> $R_SIG-$TAG-build tag already exists. skipping." && continue
Thomas Oulevey 9df7b3
                        fi
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    echo " -> creating $R_SIG-$TAG"
Thomas Oulevey 9df7b3
                    $KOJI add-tag --arches "$ARCHES" $R_SIG-$TAG-build
Thomas Oulevey 9df7b3
                    $KOJI add-target $R_SIG-$TAG $R_SIG-$TAG-build $R_SIG-candidate
Thomas Oulevey 9df7b3
                    # For external repo priorites are increased by 5, Priority 5
Thomas Oulevey 9df7b3
                    if [ "x$DIST" == "x7" ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        $KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-cr
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    $KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-extras
Thomas Oulevey 9df7b3
                    $KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-updates
Thomas Oulevey 9df7b3
                    $KOJI add-external-repo --tag=$R_SIG-$TAG-build centos${DIST}-os
Thomas Oulevey 9df7b3
                    # START bootstrap
Thomas Oulevey 9df7b3
                    if ( $optionb )
Thomas Oulevey 9df7b3
                                        then
Thomas Oulevey 9df7b3
                        # START bootstrap for sclo
Thomas Oulevey 9df7b3
                        if [ "x${SIGNAME}" == "xsclo" ]
Thomas Oulevey 9df7b3
                                                then
Thomas Oulevey 9df7b3
                            # Priority 15
Thomas Oulevey 9df7b3
                            $KOJI add-external-repo --tag=$R_SIG-$TAG-build sclo${DIST}-bootstrap
Thomas Oulevey 9df7b3
                        fi
Thomas Oulevey 9df7b3
                        # END bootstrap for scl
Thomas Oulevey 9df7b3
                        # Other repo can be added here if needed in the future
Thomas Oulevey 9df7b3
                        # if [ "x${SIGNAME}" == "xABC" ]
Thomas Oulevey 9df7b3
                        # Let's use $SIGNAME$DIST-bootstrap to be consistent
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    # END bootstrap
Thomas Oulevey 9df7b3
                    $KOJI add-group $R_SIG-$TAG-build build
Thomas Oulevey 9df7b3
                    $KOJI add-group $R_SIG-$TAG-build srpm-build
Thomas Oulevey 9df7b3
                    # Add <collection>-build to the buildroot if collection enabled
Thomas Oulevey 9df7b3
                    if [ -f $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        echo "Using specific $SIGNAME/$PROJECT options: "
Thomas Oulevey 9df7b3
                        echo "###"
Thomas Oulevey 9df7b3
                        cat $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh
Thomas Oulevey 9df7b3
                        echo "###"
Thomas Oulevey 9df7b3
                        source $CONFIG_PATH/$SIGNAME/$PROJECT/config.sh
Thomas Oulevey 9df7b3
                    else
Thomas Oulevey 9df7b3
                        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 9df7b3
                                                COMMON_INHERITANCE=true
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    if ( $optionc )
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        $KOJI add-group-pkg $R_SIG-$TAG-build build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $COLLECTIONS-build scl-utils-build
Thomas Oulevey 9df7b3
                        $KOJI add-group-pkg $R_SIG-$TAG-build srpm-build $BUILDROOT_DEFAULT buildsys-macros-$REALTAG $COLLECTIONS-build scl-utils-build
Thomas Oulevey 9df7b3
                    else
Thomas Oulevey 9df7b3
                        $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 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    $KOJI add-tag-inheritance --priority 5 $R_SIG-$TAG-build buildsys${DIST}
Thomas Oulevey 9df7b3
                    $KOJI add-tag-inheritance --priority 10 $R_SIG-$TAG-build $R_SIG-candidate
Thomas Oulevey 9df7b3
                    # If -common exists for the project add it
Thomas Oulevey 9df7b3
                    if [ "x$RELEASE" != "xcommon" ] && [ "x$COMMON_INHERITANCE" != "xfalse" ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        $KOJI list-tags | grep $P_SIG-common-candidate &> /dev/null
Thomas Oulevey 9df7b3
                                                [ $? -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 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    # Add SIG -common if it exists
Thomas Oulevey 9df7b3
                    if [ "x$COMMON_INHERITANCE" != "xfalse" ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        $KOJI list-tags | grep $SIG-common-candidate &> /dev/null
Thomas Oulevey 9df7b3
                        [ $? -eq 0 ] && echo "Adding $SIG-common-candidate as inheritance" && $KOJI add-tag-inheritance --priority 20 $R_SIG-$TAG-build $SIG-common-candidate
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                    # Check if disttag has corresponding buildsys-macros-disttag
Thomas Oulevey 9df7b3
                    $KOJI list-tagged buildsys${DIST} | grep buildsys-macros-$REALTAG &> /dev/null
Thomas Oulevey 9df7b3
                    if [ $? -gt 0 ]
Thomas Oulevey 9df7b3
                    then
Thomas Oulevey 9df7b3
                        if [ "x$REALTAG" != "x$DEFAULT_DISTTAG" ]
Thomas Oulevey 9df7b3
                        then
Thomas Oulevey 9df7b3
                            echo " -> [WARN] buildsys-macros-$REALTAG rpm not found. Please build it within koji on target buildsys${DIST}"
Thomas Oulevey 9df7b3
                            #TODO ; generate spec file from template for overriding macros
Thomas Oulevey 9df7b3
                            [ -f $PWD/etc/buildsys.spec.template ] && echo " -> Generating buildsys-macros-$TAG.spec"
Thomas Oulevey 9df7b3
                        fi
Thomas Oulevey 9df7b3
                    fi
Thomas Oulevey 9df7b3
                done
Thomas Oulevey 9df7b3
            done
Thomas Oulevey 9df7b3
        done
Thomas Oulevey 9df7b3
    done
Thomas Oulevey 79d958
done