From 935eed349f54c7b26f11331e18ebec390a65ea84 Mon Sep 17 00:00:00 2001 From: Daniil Firsov Date: Tue, 24 Jan 2023 21:14:00 +0300 Subject: [PATCH] dnk: check API URL before INIT --- shm_actions_script.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shm_actions_script.sh b/shm_actions_script.sh index 6763cef..2af7441 100755 --- a/shm_actions_script.sh +++ b/shm_actions_script.sh @@ -5,6 +5,7 @@ set -e EVENT="{{ event_name }}" WG_MANAGER="/etc/wireguard/wg-manager.sh" SESSION_ID="{{ user.gen_session.id }}" +API_URL="{{ config.api.url }}" # We need the --fail-with-body option for curl. # It has been added since curl 7.76.0, but almost all Linux distributions do not support it yet. @@ -24,6 +25,13 @@ case $EVENT in exit 1 fi + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" $API_URL/shm/v1/test) + if [ $CODE -ne '200' ]; then + echo "ERROR: incorrect API URL: $API_URL" + echo "Got status: $CODE" + exit 1 + fi + apt update apt install -y \ iproute2 \ @@ -55,7 +63,7 @@ case $EVENT in $CURL -s --fail-with-body -XPUT \ -H "session-id: $SESSION_ID" \ -H "Content-Type: text/plain" \ - {{ config.api.url }}/shm/v1/storage/manage/vpn{{ us.id }} \ + $API_URL/shm/v1/storage/manage/vpn{{ us.id }} \ --data-binary "$USER_CFG" echo "done" ;; @@ -71,7 +79,7 @@ case $EVENT in $WG_MANAGER -u "{{ us.id }}" -d $CURL -s --fail-with-body -XDELETE \ -H "session-id: $SESSION_ID" \ - {{ config.api.url }}/shm/v1/storage/manage/vpn{{ us.id }} + $API_URL/shm/v1/storage/manage/vpn{{ us.id }} echo "done" ;; *)