diff --git a/shm_actions_script.sh b/shm_actions_script.sh index 99ca3eb..59582c7 100755 --- a/shm_actions_script.sh +++ b/shm_actions_script.sh @@ -25,6 +25,7 @@ case $EVENT in exit 1 fi + echo "Check domain: $API_URL" HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" $API_URL/shm/v1/test) if [ $HTTP_CODE -ne '200' ]; then echo "ERROR: incorrect API URL: $API_URL" @@ -32,6 +33,7 @@ case $EVENT in exit 1 fi + echo "Install required packages" apt update apt install -y \ iproute2 \ @@ -42,14 +44,18 @@ case $EVENT in wget if [[ $CURL_REPO && ! -f $CURL ]]; then + echo "Install modern curl" mkdir -p /opt/curl cd /opt/curl wget $CURL_REPO chmod 755 $CURL fi + echo "Download wg-manager.sh" cd /etc/wireguard $CURL -s --fail-with-body https://danuk.github.io/wg-manager/wg-manager.sh > $WG_MANAGER + + echo "Init server" chmod 700 $WG_MANAGER if [ $SERVER_INTERFACE ]; then $WG_MANAGER -i -s $SERVER_HOST -I $SERVER_INTERFACE @@ -58,8 +64,10 @@ case $EVENT in fi ;; CREATE) + echo "Create new user" USER_CFG=$($WG_MANAGER -u "{{ us.id }}" -c -p) + echo "Upload user key to SHM" $CURL -s --fail-with-body -XPUT \ -H "session-id: $SESSION_ID" \ -H "Content-Type: text/plain" \ @@ -68,15 +76,20 @@ case $EVENT in echo "done" ;; ACTIVATE) + echo "Activate user" $WG_MANAGER -u "{{ us.id }}" -U echo "done" ;; BLOCK) + echo "Block user" $WG_MANAGER -u "{{ us.id }}" -L echo "done" ;; REMOVE) + echo "Remove user" $WG_MANAGER -u "{{ us.id }}" -d + + echo "Remove user key from SHM" $CURL -s --fail-with-body -XDELETE \ -H "session-id: $SESSION_ID" \ $API_URL/shm/v1/storage/manage/vpn{{ us.id }}