40 lines
1.4 KiB
Bash
40 lines
1.4 KiB
Bash
#!/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 <<_EOF > $PLAGUE_CONF
|
|
[Server]
|
|
use_ssl = no
|
|
address = $PLAGUE_SERVER
|
|
allow_uploads = yes
|
|
|
|
[User]
|
|
email = $EMAIL
|
|
_EOF
|
|
|
|
PLAGUE_CLIENT_CONFIG=$PLAGUE_CONF plague-client build $NAME $SRPM $DIST
|
|
rm -f $SRPM $PLAGUE_CONF
|
|
fi
|
|
done
|