From 4f1e2a5e0bea41a413b8f70ccc2429275a6e93a8 Mon Sep 17 00:00:00 2001 From: Fabian Arrotin Date: Sep 09 2015 08:09:48 +0000 Subject: Moved the mash_run script to scripts directory (will be called directly from cron job configured by puppet) --- diff --git a/cron.d/mash_run.sh b/cron.d/mash_run.sh deleted file mode 100755 index 70efd65..0000000 --- a/cron.d/mash_run.sh +++ /dev/null @@ -1,180 +0,0 @@ -usage() -{ -cat << EOF -usage: $0 [-t ] - -This script generate mash repo from all SIG tags. - -OPTIONS: - -d mash repo destination : default to $MASH_DEST - -f koji instance fqdn : default to $KOJI_FQDN - -t tag(s) : storage7-release, storage7-testing etc... -EOF -} - -# Global config -# koji binary -KOJI="/usr/bin/koji" -# mash binary -MASH="/usr/bin/mash" -# default fqdn -KOJI_FQDN="cbs.centos.org" -# mash config containing mash.conf -MASH_CONF="/etc/mash" -# repos destination -MASH_DEST="/mnt/kojishare/repos" -#cache -MASH_CACHE="/var/cache/cbs-mash" -# log directory -LOG_DIR="/var/log/mash" -# End Global - -optiond=false -optionf=false -optiont=false -optionv=false - -while getopts ":hvd:f:t:" OPTION -do - case ${OPTION} in - h) - usage - exit 0 - ;; - t) - optiont=true - TAGS="${OPTARG}" - ;; - d) - optiond=true - MASH_DEST="${OPTARG}" - ;; - f) - optionf=true - KOJI_FQDN="${OPTARG}" - ;; - v) - optionv=true - ;; - ?) - exit 0 - ;; - :) - echo "Option -${OPTARG} requires an argument." - exit 1 - ;; - esac -done - -shift $((${OPTIND} - 1)) - -# Repoviewurl in mash config -MASH_VIEWURL="http://$KOJI_FQDN/repos" - -# Check if user is allowed to send command to koji and has 'admin' permission -PERMS=`${KOJI} list-permissions --mine` - -for P in $PERMS -do - [[ $P == 'admin' ]] && ADMIN=true; break -done - -if [ "$ADMIN" != true ] -then - echo "[ERROR] Koji misconfigure/missing admin privilege for creating SIG tags" - exit 1 -fi - -if ( ! ${optiont} ) -then - CANDIDATE_TAGS=`${KOJI} list-tags | grep "\-candidate"` - TEST_TAGS=`${KOJI} list-tags | grep "\-testing"` - RELEASE_TAGS=`${KOJI} list-tags | grep "\-release"` - TAGS="${CANDIDATE_TAGS} ${TEST_TAGS} ${RELEASE_TAGS}" -fi - -print_mash_template() -{ - local tag=$1 -cat << EOF -[${tag}] -rpm_path = ${MASH_DEST}/${tag}/%(arch)s/os/Packages -repodata_path = ${MASH_DEST}/${tag}/%(arch)s/os/ -source_path = source/SRPMS -debuginfo = True -multilib = True -multilib_method = devel -tag = ${tag} -inherit = False -strict_keys = False -repoviewurl = ${MASH_VIEWURL}/${tag}/%(arch)s/os/ -repoviewtitle = "${tag^^}" -arches = i386 x86_64 -delta = True -EOF -} - -mash_prepare () -{ - local tag=$1 - local log=$2 - ( $optionv ) && echo "* Checking ${tag} mash config..." - # config mash already ok - [ -f ${MASH_CONF}/${tag}.mash ] && return - ( $optionv ) && echo " -> [INFO] creating mash config: ${tag}.mash..." - print_mash_template "${tag}" > ${MASH_CONF}/${tag}.mash -} - -mash_run () { - local tag=$1 - local log=$2 - ${MASH} -p ${MASH_DEST}/ -o ${MASH_DEST}/ ${tag} &> ${log} - [ $? -gt 0 ] && echo " -> [ERROR] mash run failed ${log} " - ( $optionv ) && echo " -> [INFO] mash run succeeded ${log}" -} - -# Ensure the cache directory is available -[ ! -d $MASH_CACHE ] && mkdir -p $MASH_CACHE - -# Ensure we do not have parallel runs -pidfile=/var/run/mash-run.pid -if [ -e $pidfile ]; then - pid=`cat $pidfile` - if kill -0 &> /dev/null $pid; then - ( $optionv ) && echo "Mash is already running PID:$pid" - exit 1 - else - rm $pidfile &>/dev/null - fi -fi - -echo $$ > $pidfile - -for TAG in ${TAGS} -do - LOG="${LOG_DIR}/mash.${TAG}.log" - if [ ! -f $MASH_CACHE/$TAG.buildlist ] - then - ${KOJI} list-tagged $TAG > $MASH_CACHE/$TAG.buildlist - else - BUILDLIST=`mktemp` - ${KOJI} list-tagged $TAG > $BUILDLIST - diff $BUILDLIST $MASH_CACHE/$TAG.buildlist &>> $LOG - if [ $? -eq 0 ] - then - echo " -> skipping. No new build in $TAG" &>> $LOG - rm -rf $BUILDLIST - continue - else - echo " -> updating cache for $TAG" &>> $LOG - cp $BUILDLIST $MASH_CACHE/$TAG.buildlist - fi - rm -rf $BUILDLIST - fi - mash_prepare "${TAG}" "${LOG}" - mash_run "${TAG}" "${LOG}" & -done - -wait -rm $pidfile -exit 0 diff --git a/scripts/mash_run.sh b/scripts/mash_run.sh new file mode 100755 index 0000000..70efd65 --- /dev/null +++ b/scripts/mash_run.sh @@ -0,0 +1,180 @@ +usage() +{ +cat << EOF +usage: $0 [-t ] + +This script generate mash repo from all SIG tags. + +OPTIONS: + -d mash repo destination : default to $MASH_DEST + -f koji instance fqdn : default to $KOJI_FQDN + -t tag(s) : storage7-release, storage7-testing etc... +EOF +} + +# Global config +# koji binary +KOJI="/usr/bin/koji" +# mash binary +MASH="/usr/bin/mash" +# default fqdn +KOJI_FQDN="cbs.centos.org" +# mash config containing mash.conf +MASH_CONF="/etc/mash" +# repos destination +MASH_DEST="/mnt/kojishare/repos" +#cache +MASH_CACHE="/var/cache/cbs-mash" +# log directory +LOG_DIR="/var/log/mash" +# End Global + +optiond=false +optionf=false +optiont=false +optionv=false + +while getopts ":hvd:f:t:" OPTION +do + case ${OPTION} in + h) + usage + exit 0 + ;; + t) + optiont=true + TAGS="${OPTARG}" + ;; + d) + optiond=true + MASH_DEST="${OPTARG}" + ;; + f) + optionf=true + KOJI_FQDN="${OPTARG}" + ;; + v) + optionv=true + ;; + ?) + exit 0 + ;; + :) + echo "Option -${OPTARG} requires an argument." + exit 1 + ;; + esac +done + +shift $((${OPTIND} - 1)) + +# Repoviewurl in mash config +MASH_VIEWURL="http://$KOJI_FQDN/repos" + +# Check if user is allowed to send command to koji and has 'admin' permission +PERMS=`${KOJI} list-permissions --mine` + +for P in $PERMS +do + [[ $P == 'admin' ]] && ADMIN=true; break +done + +if [ "$ADMIN" != true ] +then + echo "[ERROR] Koji misconfigure/missing admin privilege for creating SIG tags" + exit 1 +fi + +if ( ! ${optiont} ) +then + CANDIDATE_TAGS=`${KOJI} list-tags | grep "\-candidate"` + TEST_TAGS=`${KOJI} list-tags | grep "\-testing"` + RELEASE_TAGS=`${KOJI} list-tags | grep "\-release"` + TAGS="${CANDIDATE_TAGS} ${TEST_TAGS} ${RELEASE_TAGS}" +fi + +print_mash_template() +{ + local tag=$1 +cat << EOF +[${tag}] +rpm_path = ${MASH_DEST}/${tag}/%(arch)s/os/Packages +repodata_path = ${MASH_DEST}/${tag}/%(arch)s/os/ +source_path = source/SRPMS +debuginfo = True +multilib = True +multilib_method = devel +tag = ${tag} +inherit = False +strict_keys = False +repoviewurl = ${MASH_VIEWURL}/${tag}/%(arch)s/os/ +repoviewtitle = "${tag^^}" +arches = i386 x86_64 +delta = True +EOF +} + +mash_prepare () +{ + local tag=$1 + local log=$2 + ( $optionv ) && echo "* Checking ${tag} mash config..." + # config mash already ok + [ -f ${MASH_CONF}/${tag}.mash ] && return + ( $optionv ) && echo " -> [INFO] creating mash config: ${tag}.mash..." + print_mash_template "${tag}" > ${MASH_CONF}/${tag}.mash +} + +mash_run () { + local tag=$1 + local log=$2 + ${MASH} -p ${MASH_DEST}/ -o ${MASH_DEST}/ ${tag} &> ${log} + [ $? -gt 0 ] && echo " -> [ERROR] mash run failed ${log} " + ( $optionv ) && echo " -> [INFO] mash run succeeded ${log}" +} + +# Ensure the cache directory is available +[ ! -d $MASH_CACHE ] && mkdir -p $MASH_CACHE + +# Ensure we do not have parallel runs +pidfile=/var/run/mash-run.pid +if [ -e $pidfile ]; then + pid=`cat $pidfile` + if kill -0 &> /dev/null $pid; then + ( $optionv ) && echo "Mash is already running PID:$pid" + exit 1 + else + rm $pidfile &>/dev/null + fi +fi + +echo $$ > $pidfile + +for TAG in ${TAGS} +do + LOG="${LOG_DIR}/mash.${TAG}.log" + if [ ! -f $MASH_CACHE/$TAG.buildlist ] + then + ${KOJI} list-tagged $TAG > $MASH_CACHE/$TAG.buildlist + else + BUILDLIST=`mktemp` + ${KOJI} list-tagged $TAG > $BUILDLIST + diff $BUILDLIST $MASH_CACHE/$TAG.buildlist &>> $LOG + if [ $? -eq 0 ] + then + echo " -> skipping. No new build in $TAG" &>> $LOG + rm -rf $BUILDLIST + continue + else + echo " -> updating cache for $TAG" &>> $LOG + cp $BUILDLIST $MASH_CACHE/$TAG.buildlist + fi + rm -rf $BUILDLIST + fi + mash_prepare "${TAG}" "${LOG}" + mash_run "${TAG}" "${LOG}" & +done + +wait +rm $pidfile +exit 0