Skip to content

Instantly share code, notes, and snippets.

@KPCCoiL
Last active December 12, 2019 11:28
Show Gist options
  • Save KPCCoiL/0c0ab58837e8e2fae7a9dc142b5e2220 to your computer and use it in GitHub Desktop.
Save KPCCoiL/0c0ab58837e8e2fae7a9dc142b5e2220 to your computer and use it in GitHub Desktop.
better one
#!/bin/bash
temporary='.topprover-tool'
cookie="$temporary/cookie.txt"
problem="$temporary/id.txt"
curl="curl -b $cookie"
topprover='https://top-prover.top'
function make_tmpdir() {
if [ ! -d $temporary ]; then
mkdir $temporary
fi
}
function problem_id() {
make_tmpdir
if [ ! -f $problem ]; then
read -p 'Problem ID: ' -r id
echo $id > $problem
fi
cat $problem
}
function ensure_cookie() {
make_tmpdir
if [ ! -f $cookie ]; then
read -p 'Username: ' -r user
read -s -p 'Password: ' -r password
local response=$(curl -X POST -F "user=$user" -F "password=$password" $topprover/login -c $cookie)
local wrong=$(echo $response | grep -o 'Bad Request')
if [ "$wrong" != '' ]; then
echo 'login failed'
exit 1
fi
fi
}
function retrieve() {
ensure_cookie
$curl $topprover/problem_content/$(problem_id) > Problem.v
coqc Problem.v &
$curl $topprover/example_content/$(problem_id) > Solution.v
$curl $topprover/checker_content/$(problem_id) > Checker.v
}
function submit() {
ensure_cookie
coqc Solution.v || return 1
coqc Checker.v || return 1
$curl -X POST -F 'solution=<Solution.v' $topprover/submit/$(problem_id)
}
if [ $1 = retrieve ]; then
retrieve
fi
if [ $1 = submit ]; then
submit
fi
if [ $1 = clean ]; then
rm -rf $temporary
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment