mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-04 05:25:37 +01:00
OTS stamping and upgrading fixes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user