-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmolior-build-upload
executable file
·98 lines (83 loc) · 2.24 KB
/
molior-build-upload
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
usage()
{
echo "Usage: $0 [options] <project> <version> [pkg_0.1.dsc pkg_0.1.tar.xz] pkg_0.1_amd64.changes pkg_0.1_amd64.buildinfo pkg_0.1_amd64.deb..."
echo
echo "Options:"
echo " -m, --molior-server molior server URL (overrides MOLIOR_SERVER from ~/.moliorrc)"
echo
echo "Example: molior-build-upload -m http://10.0.0.1 test-build-upload 0.1 ../molior-tools-doc_1.4.1~rc10_all.deb ../molior-tools_1.4.1~rc10_all.deb ../molior-tools_1.4.1~rc10_amd64.buildinfo ../molior-tools_1.4.1~rc10_amd64.changes"
echo
if [ -n "$1" ]; then
echo "Error: $1"
echo
fi
exit 1
}
if [ ! -e ~/.molior-token ]; then
echo "Error: no ~/.molior-token found"
exit 2
fi
if [ `stat -c %A ~/.molior-token` != "-r--------" ]; then
echo "Error: wrong permissions on ~/.molior-token, run chmod 400 ~/.molior-token"
exit 3
fi
if ! echo "$@" | grep -q ".changes"; then
usage "No debian .changes file provided"
fi
if ! echo "$@" | grep -q ".buildinfo"; then
usage "No debian .buildinfo file provided"
fi
if ! echo "$@" | grep -q ".deb"; then
usage "No debian package (*.deb) provided"
fi
OPTS=$(getopt -o m: --long "molior-server:" -n $(basename $0) -- "$@")
eval set -- "$OPTS"
MOLIOR_SERVER=""
if [ -e ~/.moliorrc ]; then
. ~/.moliorrc
fi
while true; do
case "$1" in
-m | --molior-server) MOLIOR_SERVER="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ -z "$MOLIOR_SERVER" ]; then
usage "No molior server specified"
fi
PROJECT=$1; shift
if [ -z "$PROJECT" ]; then
usage "No project specified"
fi
VERSION=$1; shift
if [ -z "$VERSION" ]; then
usage "No version specified"
fi
args=""
for f in $@
do
args="$args -F \"files=@$f\""
done
old_umask=`umask`
umask 0044
tmptoken=`mktemp`
echo -n "X-MoliorToken: " > $tmptoken
cat ~/.molior-token >> $tmptoken
umask $old_umask
errmsg=`mktemp`
httpret=`echo $args | xargs curl -w "%{http_code}" -o $errmsg -H @$tmptoken $MOLIOR_SERVER/api2/project/$PROJECT/$VERSION/extbuild 2>/dev/null`
ret=$?
rm -f $tmptoken
if [ $ret -eq 0 -a $httpret != "201" ]; then
ret=1
fi
msg=`sed -e 's/^"//' -e 's/"$//' $errmsg`
if [ $ret -ne 0 ]; then
echo "Error: $msg" >&2
else
echo "Response: $msg"
fi
rm -f $errmsg
exit $ret