Browse Source

Don't write config file if curl returns something else than 200

pull/3/head
Julien Escario 3 years ago
parent
commit
e51aebf967
  1. 15
      wireguard/wgportal_peer_install.sh

15
wireguard/wgportal_peer_install.sh

@ -139,18 +139,23 @@ _download() {
WGPORTAL_APIURL=$WGPORTAL_URL"api/v1/provisioning/peer" WGPORTAL_APIURL=$WGPORTAL_URL"api/v1/provisioning/peer"
_debug "GET request to $WGPORTAL_APIURL" _debug "GET request to $WGPORTAL_APIURL"
HTTP_STATUS=$(curl -w "%{http_code}" -G -s -o $WG_CONFFILE --user $username:$password --data-urlencode "PublicKey=$wgpubkey" -X GET $WGPORTAL_APIURL -H "accept: text/plain")
HTTP_RESPONSE=$(curl -G -s --write-out "HTTPSTATUS:%{http_code}" --user $username:$password --data-urlencode "PublicKey=$wgpubkey" -X GET $WGPORTAL_APIURL -H "accept: text/plain")
res=$? res=$?
if [ "$res" != "0" ]; then if [ "$res" != "0" ]; then
echo "the curl command failed with: $res" echo "the curl command failed with: $res"
fi fi
if [ $HTTP_STATUS -ne 200 ]; then
printf "Curl returned HTTP code %s\n" "$HTTP_STATUS"
exit 1;
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -E 's/HTTPSTATUS\:[0-9]{3}$//')
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/')
if [ $HTTP_STATUS = "200" ]; then
echo "$HTTP_BODY" > $WG_CONFFILE
printf "WG config successfully downloaded at %s\n" "$WG_CONFFILE"
return
fi fi
printf "WG config successfully download at %s\n" "$WG_CONFFILE"
printf "Curl returned HTTP code %s\n" "$HTTP_STATUS"
exit 1;
} }
_install() { _install() {

Loading…
Cancel
Save