-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumclouddj_batch_upload.sh
executable file
·83 lines (71 loc) · 2.13 KB
/
umclouddj_batch_upload.sh
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
#!/bin/sh
if [ $# -eq 0 ]; then
echo " Please give the arguments with the script. They are: "
echo "Usage is : <sh> FILE USERNAME PASSWORD forceNew blockCourse gradeLevel category noAutoassign entryId URL"
echo " Make sure to have empty strings where no value required. Eg: \"\" "
exit 1;
fi
if [ $# -ne 10 ];then
echo " Please give all 8 arguments. Even if they are empty"
echo ""
echo "Usage is : <sh> FILE USERNAME PASSWORD forceNew blockCourse gradeLevel category noAutoassign entryId URL"
echo " Make sure to have empty strings where no value required. Eg: \"\" "
exit 1;
fi
FILE=$1
USERNAME=$2
PASSWORD=$3
forceNew=$4
blockCourse=$5
gradeLevel=$6
category=$7
noAutoassign=$8
entryId=$9
URL=$10
#URL="http://umcloud1.ustadmobile.com/uploadeXe/upload/"
FWORD="exefile"
OPFILE="op.html"
FORMPREFIX=" --form"
FORM=""
if [ ! -z "$FILE" -a "$FILE" != " " ]; then
FORM="${FORM} ${FORMPREFIX} ${FWORD}=@${FILE}"
fi
if [ ! -z "$USERNAME" -a "$USERNAME" != " " ]; then
FORM="${FORM} ${FORMPREFIX} username=${USERNAME}"
fi
if [ ! -z "$PASSWORD" -a "$PASSWORD" != " " ]; then
FORM="${FORM} ${FORMPREFIX} password=${PASSWORD}"
fi
if [ ! -z "$forceNew" -a "$forceNew" != " " ]; then
FORM="${FORM} ${FORMPREFIX} forceNew=True"
fi
if [ ! -z "$blockCourse" -a "$blockCourse" != " " ]; then
FORM="${FORM} ${FORMPREFIX} blockCourse=True"
fi
if [ ! -z "$gradeLevel" -a "$gradeLevel" != " " ]; then
FORM="${FORM} ${FORMPREFIX} gradeLevel=${gradeLevel}"
fi
if [ ! -z "$category" -a "$category" != " " ]; then
FORM="${FORM} ${FORMPREFIX} category=${category}"
fi
if [ ! -z "$noAutoassign" -a "$noAutoassign" != " " ]; then
FORM="${FORM} ${FORMPREFIX} noAutoassign=True"
fi
#entryId
if [ ! -z "$entryId" -a "$entryId" != " " ]; then
FORM="${FORM} ${FORMPREFIX} entryId=${entryId}"
fi
echo ""
echo "Running this: "
echo "curl -i -s ${FORM} -X POST ${URL} "
response=`curl -i -s ${FORM} -X POST ${URL} | grep "HTTP/1.1"`
res=`echo ${response} | grep -c "200 OK"`
echo "${res}"
if [ $res -eq 1 ]
then
echo "All good. Response was 200"
else
echo "Failure. Not 200 response. It was:"
echo "${response}"
exit 1
fi