83 lines
1.5 KiB
Bash
Executable file
83 lines
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
usage()
|
|
{
|
|
echo "Usage: $0 [-d] [year] <project> <submission> <login> <tarball>"
|
|
}
|
|
|
|
if [ -z "$4" ]
|
|
then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if ! which gearman > /dev/null 2> /dev/null
|
|
then
|
|
echo "gearman isn't installed on this machine. Please try another one."
|
|
exit 1
|
|
fi
|
|
|
|
if [ "x$1" = "x-d" ]
|
|
then
|
|
BACKGROUD=
|
|
shift
|
|
else
|
|
BACKGROUD="-b"
|
|
fi
|
|
|
|
if [ "x${1:0:2}" = "x20" ]
|
|
then
|
|
YEAR=" <param name=\"year\">$1</param>"
|
|
shift
|
|
else
|
|
YEAR=
|
|
fi
|
|
PROJECT_ID=$1
|
|
RENDU=$2
|
|
LOGIN=$3
|
|
|
|
if ! [ -f "$4" ]
|
|
then
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
MIME=`file -b -i "$4" | cut -d ';' -f 1`
|
|
|
|
if [ "$MIME" = "application/x-bzip2" ]
|
|
then
|
|
FILE=`bzip2 --decompress --stdout "$4" | gzip --stdout | base64`
|
|
|
|
elif [ "$MIME" = "application/x-gzip" ]
|
|
then
|
|
FILE=`gzip --decompress --stdout "$4" | gzip --stdout | base64`
|
|
|
|
elif [ "$MIME" = "application/x-xz" ]
|
|
then
|
|
FILE=`xz --decompress --stdout "$4" | gzip --stdout | base64`
|
|
|
|
elif [ "$MIME" = "application/x-tar" ]
|
|
then
|
|
FILE=`tar cz "$4" | base64`
|
|
|
|
elif [ "$MIME" = "inode/directory" ]
|
|
then
|
|
FILE=`tar xf "$4" | tar cz | base64`
|
|
|
|
else
|
|
echo "I don't know how to treat $4" >&2
|
|
exit 3
|
|
fi
|
|
|
|
cat <<EOF | gearman -h gearmand-srv -p 4730 -f moulette_get $BACKGROUD
|
|
<?xml version="1.0"?>
|
|
<process>
|
|
<param name="type">std</param>
|
|
$YEAR
|
|
<param name="id">$PROJECT_ID</param>
|
|
<param name="rendu">$RENDU</param>
|
|
<param name="login">$LOGIN</param>
|
|
<param name="file">rendu.tgz</param>
|
|
<file name="rendu.tgz">$FILE</file>
|
|
</process>
|
|
EOF
|