You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.3 KiB

#!/bin/bash
[ -e /etc/buildwatcher/watcher.conf ] && . /etc/buildwatcher/watcher.conf
TOP_DIR=${TOP_DIR:-/var/lib/build/}
WATCHED_DIR=$TOP_DIR/uploads
PLAGUE_SERVER=${PLAGUE_SERVER:-http://localhost:8887}
inotifywait -e moved_to -r -m --format %w%f $WATCHED_DIR | while read SRPM; do
echo "new file arrived: $SRPM"
NAME=$(rpm -qp $SRPM --qf %{NAME})
if [ -z $NAME ]; then
echo "Error, $SRPM is not a valid srpm file. Notifying the admin ($ADMIN_EMAIL)"
mv $SRPM $TOP_DIR/errors/
echo "An error occurred with file $SRPM which wasn't recognized as a valid srpm file. It's been moved to $TOP_DIR/errors/" | \
mail -s "Build sys error" $ADMIN_EMAIL
else
DIST=$(basename $(dirname $SRPM))
OWNER=$(stat --format %U $SRPM)
# Lookup in LDAP if we have an email for this user
echo "Looking up email of user $OWNER: ldapsearch -x -LLL -H $LDAP_URI -b $LDAP_USER_BASE uid=$OWNER mail"
EMAIL=$(ldapsearch -x -LLL -H $LDAP_URI -b $LDAP_USER_BASE uid=$OWNER mail | grep mail: | head -1 | awk '{print $2}')
[ -z $EMAIL ] && EMAIL=$ADMIN_EMAIL
PLAGUE_CONF=$(mktemp)
# TODO: make the plague client config file templated
cat /etc/buildwatcher/plague-client.template | sed -e "s/__EMAIL__/$EMAIL/g" > $PLAGUE_CONF
PLAGUE_CLIENT_CONFIG=$PLAGUE_CONF plague-client build $NAME $SRPM $DIST
rm -f $SRPM $PLAGUE_CONF
fi
done