dnk: add verbose messages

This commit is contained in:
Daniil Firsov 2023-02-10 16:27:08 +03:00
parent 93dd8bca46
commit 5ca9e52a9f

View File

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