Blame cron.d/mash_run.sh

Thomas Oulevey 79d958
usage()
Thomas Oulevey 79d958
{
Thomas Oulevey 79d958
cat << EOF
Thomas Oulevey 79d958
usage: $0 [-t <tag(s)>]
Thomas Oulevey 79d958
Thomas Oulevey 79d958
This script generate mash repo from all SIG tags.
Thomas Oulevey 79d958
Thomas Oulevey 79d958
OPTIONS:
Thomas Oulevey 79d958
   -t          tag(s) : storage7-release, storage7-testing etc...
Thomas Oulevey 79d958
EOF
Thomas Oulevey 79d958
}
Thomas Oulevey 79d958
Thomas Oulevey 79d958
# Global config
Thomas Oulevey 79d958
# mash binary
Thomas Oulevey 79d958
MASH="/usr/bin/mash"
Thomas Oulevey 79d958
# mash config containing mash.conf
Thomas Oulevey 79d958
MASH_CONF="/etc/mash"
Thomas Oulevey 79d958
# repos destination
Thomas Oulevey 79d958
MASH_DEST="/mnt/kojishare/repos"
Thomas Oulevey 79d958
# repoviewurl in mash config
Thomas Oulevey 79d958
MASH_VIEWURL="http://cbs.centos.org/repos"
Thomas Oulevey 79d958
# log directory
Thomas Oulevey 79d958
LOG_DIR="/var/log/mash"
Thomas Oulevey 79d958
# End Global
Thomas Oulevey 79d958
Thomas Oulevey 79d958
optiont=false
Thomas Oulevey 79d958
optionv=false
Thomas Oulevey 79d958
while getopts ":hvt:" 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 79d958
	t)
Thomas Oulevey 79d958
             optiont=true
Thomas Oulevey 79d958
             TAGS="${OPTARG}"
Thomas Oulevey 79d958
             ;;
Thomas Oulevey 79d958
	v)
Thomas Oulevey 79d958
	     optionv=true
Thomas Oulevey 79d958
	     ;;
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 ( ! ${optiont} )
Thomas Oulevey 79d958
then
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 79d958
	PERM=`${KOJI} list-permissions --mine`
Thomas Oulevey 79d958
	if [ "${PERM}" != "admin"  ]
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
	TEST_TAGS=`koji list-tags | grep "\-testing"`
Thomas Oulevey 79d958
	RELEASE_TAGS=`koji list-tags | grep "\-release"`
Thomas Oulevey 79d958
	TAGS="${TEST_TAGS} ${RELEASE_TAGS}"
Thomas Oulevey 79d958
fi
Thomas Oulevey 79d958
Thomas Oulevey 79d958
print_mash_template()
Thomas Oulevey 79d958
{
Thomas Oulevey 79d958
	local tag=$1
Thomas Oulevey 79d958
cat << EOF
Thomas Oulevey 79d958
[${tag}]
Thomas Oulevey 79d958
rpm_path = ${MASH_DEST}/${tag}/%(arch)s/os/Packages
Thomas Oulevey 79d958
repodata_path = ${MASH_DEST}/${tag}/%(arch)s/os/
Thomas Oulevey 79d958
source_path = source/SRPMS
Thomas Oulevey 79d958
debuginfo = True
Thomas Oulevey 79d958
multilib = True
Thomas Oulevey 79d958
multilib_method = devel
Thomas Oulevey 79d958
tag = ${tag}
Thomas Oulevey 79d958
inherit = False
Thomas Oulevey 79d958
strict_keys = False
Thomas Oulevey 79d958
repoviewurl = ${MASH_VIEWURL}/${tag}/%(arch)s/os/
Thomas Oulevey 79d958
repoviewtitle = "${tag^^}"
Thomas Oulevey 79d958
arches = i386 x86_64
Thomas Oulevey 79d958
delta = True
Thomas Oulevey 79d958
EOF
Thomas Oulevey 79d958
}
Thomas Oulevey 79d958
Thomas Oulevey 79d958
mash_prepare ()
Thomas Oulevey 79d958
{
Thomas Oulevey 79d958
	local tag=$1
Thomas Oulevey 79d958
	local log=$2
Thomas Oulevey 79d958
	( $optionv ) && echo "* Checking ${tag} mash config..."
Thomas Oulevey 79d958
	# config mash already ok 
Thomas Oulevey 79d958
	[ -f ${MASH_CONF}/${tag}.mash ] && return
Thomas Oulevey 79d958
	( $optionv ) && echo " -> [INFO] creating mash config: ${tag}.mash..."
Thomas Oulevey 79d958
	print_mash_template "${tag}" > ${MASH_CONF}/${tag}.mash
Thomas Oulevey 79d958
}
Thomas Oulevey 79d958
Thomas Oulevey 79d958
mash_run () {
Thomas Oulevey 79d958
	local tag=$1
Thomas Oulevey 79d958
	local log=$2
Thomas Oulevey 79d958
	${MASH} -p ${MASH_DEST}/ -o ${MASH_DEST}/ ${tag} &> ${log}
Thomas Oulevey 79d958
	[ $? -gt 0 ] && echo " -> [ERROR] mash run failed ${log} "
Thomas Oulevey 79d958
	( $optionv ) && echo " -> [INFO] mash run succeeded ${log}"
Thomas Oulevey 79d958
}
Thomas Oulevey 79d958
Thomas Oulevey 79d958
# Ensure we do not have parallel runs
Thomas Oulevey 79d958
pidfile=/var/run/mash-run.pid
Thomas Oulevey 79d958
if [ -e $pidfile ]; then
Thomas Oulevey 79d958
    pid=`cat $pidfile`
Thomas Oulevey 79d958
    if kill -0 &> /dev/null $pid; then
Thomas Oulevey 79d958
        ( $optionv ) && echo "Mash is already running PID:$pid"
Thomas Oulevey 79d958
        exit 1
Thomas Oulevey 79d958
    else
Thomas Oulevey 79d958
        rm $pidfile &>/dev/null
Thomas Oulevey 79d958
    fi
Thomas Oulevey 79d958
fi
Thomas Oulevey 79d958
Thomas Oulevey 79d958
echo $$ > $pidfile
Thomas Oulevey 79d958
Thomas Oulevey 79d958
for TAG in ${TAGS}
Thomas Oulevey 79d958
do
Thomas Oulevey 79d958
	LOG="${LOG_DIR}/mash.${TAG}.log"
Thomas Oulevey 79d958
	mash_prepare "${TAG}" "${LOG}"
Thomas Oulevey 79d958
	mash_run "${TAG}" "${LOG}" &
Thomas Oulevey 79d958
done
Thomas Oulevey 79d958
Thomas Oulevey 79d958
wait
Thomas Oulevey 79d958
rm $pidfile
Thomas Oulevey 79d958
exit 0