#!/bin/bash #server='https://did.ix.tc' server='http://localhost:3000' status=$(curl --write-out %{http_code} -s -o /dev/null "${server}/console" -b $HOME/cookies.did) if [[ "$status" -ne 200 ]] ; then echo "Got HTTP $status, have to login:" token=$(curl -L "${server}/users/sign_in" -s -c $HOME/cookies.did -b $HOME/cookies.did | sed -nr 's/^.+authenticity_token\" value="(.+)" autocomplete.+/\1/p') echo $token echo -n Username: read username echo -n Password: read -s password curl "${server}/users/sign_in" \ --data-urlencode "user[email]=${username}" \ --data-urlencode "user[password]=${password}" \ --data-urlencode "user[remember_me]=1" \ --data-urlencode "user[commit]=Log+in" \ --data-urlencode "authenticity_token=${token}" \ -b $HOME/cookies.did \ -c $HOME/cookies.did \ -s fi argv=""; for arg; do argv=$(printf '%s"%s"' "$argv", "$arg"); done; argv=${argv#,} curl -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d "{\"argv\":[${argv}]}" \ -b $HOME/cookies.did \ "${server}/api/console"