save port and paylaod_signature to files to be used elsewhere than by reading terminal output

This commit is contained in:
StudioEtrange 2021-01-31 03:24:00 +01:00
parent 2e29ad2d8d
commit 4156832879

View File

@ -81,6 +81,12 @@ fi
# If you already have a signature, and you would like to re-use that port,
# save the payload_and_signature received from your previous request
# in the env var PAYLOAD_AND_SIGNATURE, and that will be used instead.
mkdir -p /opt/piavpn-manual
# remove previous stored port before obtaining a new one
rm -f /opt/piavpn-manual/port
if [[ ! $PAYLOAD_AND_SIGNATURE ]]; then
echo
echo -n "Getting new signature... "
@ -99,10 +105,15 @@ export payload_and_signature
# If they are not OK, just stop the script.
if [ "$(echo "$payload_and_signature" | jq -r '.status')" != "OK" ]; then
echo -e "${RED}The payload_and_signature variable does not contain an OK status.${NC}"
# deleve invalid payload and signature
rm -f /opt/piavpn-manual/payload_and_signature
exit 1
fi
echo -e "${GREEN}OK!${NC}"
# store last valid payload and signature
echo $payload_and_signature > /opt/piavpn-manual/payload_and_signature || exit 1
# We need to get the signature out of the previous response.
# The signature will allow the us to bind the port on the server.
signature="$(echo "$payload_and_signature" | jq -r '.signature')"
@ -118,6 +129,11 @@ port="$(echo "$payload" | base64 -d | jq -r '.port')"
# 2 months is not enough for your setup, please open a ticket.
expires_at="$(echo "$payload" | base64 -d | jq -r '.expires_at')"
# store port
echo $port > /opt/piavpn-manual/port || exit 1
# store port expiration
echo $expires_at >> /opt/piavpn-manual/port
echo -ne "
Signature ${GREEN}$signature${NC}
Payload ${GREEN}$payload${NC}