aboutsummaryrefslogtreecommitdiffstats
path: root/modules/buildsystem/templates/binrepo/upload-bin
blob: 7cad58380c99975e62ed32b0fd32d819fee7094c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
set -e

binrepodir=<%= scope.lookupvar('buildsystem::var::binrepo::repodir') %>
uploadinfosdir=<%= scope.lookupvar('buildsystem::var::binrepo::uploadinfosdir') %>
tmpfile=$(mktemp)
mail_from="<%= scope.lookupvar('buildsystem::var::binrepo::uploadmail_from') %>"
mail_dest="<%= scope.lookupvar('buildsystem::var::binrepo::uploadmail_to') %>"

test $# = 2 || exit 3
username="$1"
comment="$2"

/bin/cat > "$tmpfile"
sha1sum=$(/usr/bin/sha1sum "$tmpfile" | sed 's/ .*$//')
test -n "$sha1sum"
if [ -f "$binrepodir/$sha1sum" ]
then
    echo "File $sha1sum already exists." >&2
    /bin/rm -f "$tmpfile"
    exit 2
fi
/bin/mv "$tmpfile" "$binrepodir/$sha1sum"
/bin/chmod 644 "$binrepodir/$sha1sum"
echo "$username:$comment" > "$uploadinfosdir/$sha1sum"
echo "User $username uploaded file $sha1sum: $comment"

echo "User $username uploaded file $sha1sum: $comment" | \
    /usr/bin/mailx -s "New file uploaded: $sha1sum - $comment" -S "from=$username <$mail_from>" "$mail_dest"

exit 0