-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeworld_upload.sh
More file actions
executable file
·68 lines (60 loc) · 1.67 KB
/
codeworld_upload.sh
File metadata and controls
executable file
·68 lines (60 loc) · 1.67 KB
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
#!/bin/bash
# Uploads one or more source files to a code.world installation
#set -e
mode=""
url=""
if [ "x$1" = "x-s" ]; then
url="https://blackeyepeas.phys.lsu.edu/cw/"
mode=codeworld
shift
fi
if [ -z "$url" -a "x$1" != "x" ]; then
url="$1"
shift
fi
if [ -z "$mode" -a "x$1" != "x" ]; then
mode="$1"
shift
fi
if [ -z "$url" -o -z "$mode" ]; then
echo "Usage: $0 http://code.world.url/ [haskell|codeworld] [source.hs ...]"
echo " $0 -s [source.txt ...]"
exit 1
fi
for file in "$@"; do
echo "Uploading $file ..."
#echo "curl -S -s -F \"mode=$mode\" -F \"source=<$file\" ${url}compile"
json="$(curl -S -s -F "mode=$mode" -F "source=<$file" ${url}compile)"
dhash="$(echo "$json" | jq -r .dhash)"
hash="$(echo "$json" | jq -r .hash)"
errormsg="$(curl -S -s -F "mode=$mode" -F "hash=$hash" ${url}runMsg)"
if [ "$mode" = "codeworld" ]; then
curl="$url#$hash"
else
curl="$url$mode#$hash"
fi
if [ -z "$errormsg" ] || [[ $errormsg == *"warning"* ]]; then
durl="${url}run.html?mode=$mode&dhash=$dhash"
echo -e "\e[92mSuccessfully uploaded files!\e[0m"
echo "Source at: $curl"
echo "Runnable at: $durl"
if [ ! -z "$errormsg" ]; then
echo -e "\e[33mCompiled with warnings:"
echo ${errormsg}
echo -e "\e[0m"
fi
if [ ! -z "${DISPLAY}" ]; then
firefox $durl &
fi
echo
else
echo
echo -e "\e[91m${file} Compilation failed:"
echo ${errormsg}
echo -e "\e[0m"
echo "Source at: $curl"
firefox $curl
echo
exit 1
fi
done