OTS stamping and upgrading fixes

This commit is contained in:
kexkey
2018-11-26 13:38:26 -05:00
parent f1b98255c0
commit a7ea9ce93c
4 changed files with 51 additions and 25 deletions

View File

@@ -79,10 +79,12 @@ request_ots_stamp()
if [ "${returncode}" -eq 0 ]; then
# jq -e will have a return code of 1 if the supplied tag is null.
errorstring=$(echo "${result}" | tr '\r\n' ' ' | jq -e ".error" | tr -d '"')
errorstring=$(echo "${result}" | tr '\r\n' ' ' | jq -e ".error")
if [ "$?" -eq "0" ]; then
# Error tag not null, so there's an error
errorstring=$(echo "${errorstring}" | tr -d '"')
# If the error message is "Already exists"
trace "[request_ots_stamp] grepping 'already exists'..."
echo "${result}" | grep "already exists" > /dev/null
@@ -161,12 +163,23 @@ serve_ots_backoffice()
returncode=$?
trace_rc ${returncode}
trace "[serve_ots_backoffice] result=${result}"
if [ "${returncode}" -eq 0 ]; then
trace "[serve_ots_backoffice] just upgraded!"
sql "UPDATE stamp SET upgraded=1 WHERE hash=\"${hash}\""
trace_rc $?
upgraded=1
if [ "${returncode}" -eq 0 ]; then
# CURL success... let's see if error in response
errorstring=$(echo "${result}" | tr '\r\n' ' ' | jq -e ".error")
if [ "$?" -eq "0" ]; then
# Error tag not null, so there's an error
trace "[serve_ots_backoffice] not upgraded!"
upgraded=0
else
# No failure, upgraded
trace "[serve_ots_backoffice] just upgraded!"
sql "UPDATE stamp SET upgraded=1 WHERE hash=\"${hash}\""
trace_rc $?
upgraded=1
fi
fi
fi
if [ "${upgraded}" -eq "1" ]; then

View File

@@ -4,37 +4,37 @@
response_to_client()
{
trace "Entering response_to_client()..."
trace "Entering response_to_client()..."
local response=${1}
local returncode=${2}
local response=${1}
local returncode=${2}
([ -z "${returncode}" ] || [ "${returncode}" -eq "0" ]) && echo -ne "HTTP/1.1 200 OK\r\n"
[ -n "${returncode}" ] && [ "${returncode}" -ne "0" ] && echo -ne "HTTP/1.1 400 Bad Request\r\n"
([ -z "${returncode}" ] || [ "${returncode}" -eq "0" ]) && echo -ne "HTTP/1.1 200 OK\r\n"
[ -n "${returncode}" ] && [ "${returncode}" -ne "0" ] && echo -ne "HTTP/1.1 400 Bad Request\r\n"
echo -en "Content-Type: application/json\r\nContent-Length: ${#response}\r\n\r\n${response}"
echo -en "Content-Type: application/json\r\nContent-Length: ${#response}\r\n\r\n${response}"
# Small delay needed for the data to be processed correctly by peer
sleep 0.2s
# Small delay needed for the data to be processed correctly by peer
sleep 0.2s
}
file_response_to_client()
{
trace "Entering bin_response_to_client()..."
trace "Entering file_response_to_client()..."
local path=${1}
local filename=${2}
local pathfile="${path}${filename}"
local returncode
local path=${1}
local filename=${2}
local pathfile="${path}${filename}"
local returncode
[ -r "${pathfile}" ] \
&& echo -ne "HTTP/1.1 200 OK\r\nContent-Disposition: inline; filename=\"${filename}\"\r\nContent-Length: $(stat -c'%s' ${pathfile})\r\n\r\n" \
&& cat ${pathfile}
[ -r "${pathfile}" ] \
&& echo -ne "HTTP/1.1 200 OK\r\nContent-Disposition: inline; filename=\"${filename}\"\r\nContent-Length: $(stat -c'%s' ${pathfile})\r\n\r\n" \
&& cat ${pathfile}
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
# Small delay needed for the data to be processed correctly by peer
sleep 0.2s
# Small delay needed for the data to be processed correctly by peer
sleep 0.2s
}
case "${0}" in *responsetoclient.sh) response_to_client $@;; esac