Blob Blame History Raw
usage()
{
cat << EOF
usage: $0 [-t <tag(s)>]

This script generate mash repo from all SIG tags.

OPTIONS:
   -t          tag(s) : storage7-release, storage7-testing etc...
EOF
}

# Global config
# mash binary
MASH="/usr/bin/mash"
# mash config containing mash.conf
MASH_CONF="/etc/mash"
# repos destination
MASH_DEST="/mnt/kojishare/repos"
# repoviewurl in mash config
MASH_VIEWURL="http://cbs.centos.org/repos"
# log directory
LOG_DIR="/var/log/mash"
# End Global

optiont=false
optionv=false
while getopts ":hvt:" OPTION
do
	case ${OPTION} in
        h)
             usage
             exit 0
             ;;
	t)
             optiont=true
             TAGS="${OPTARG}"
             ;;
	v)
	     optionv=true
	     ;;
        ?)
             exit 0
             ;;
        :)
             echo "Option -${OPTARG} requires an argument."
             exit 1
             ;;
        esac
done

shift $((${OPTIND} - 1))

if ( ! ${optiont} )
then
	# 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
	TEST_TAGS=`koji list-tags | grep "\-testing"`
	RELEASE_TAGS=`koji list-tags | grep "\-release"`
	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 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"
	mash_prepare "${TAG}" "${LOG}"
	mash_run "${TAG}" "${LOG}" &
done

wait
rm $pidfile
exit 0