#!/usr/bin/env bash warpstatus=$(warp-cli status | grep "Status update: " | awk '{ print $3 }') if [ $warpstatus == "Connected" ]; then echo -e "\t>>> Cloudflare Warp is $warpstatus\n\t>>> Disconnecting from Cloudflare Warp" warp-cli disconnect && { exit 0 } || exit 1 else echo "\t>>> trying to connect to cloudflare warp" warp-cli -vv connect warpstatus=$(warp-cli status | grep "Status update: " | awk '{ print $3 }') if [ $? -a $warpstatus == "Connecting" ]; then echo "\t>>> Cloudflare Warp is $warpstatus, waiting for connection" sleep 5 warpstatus=$(warp-cli status | grep "Status update: " | awk '{ print $3 }') echo -e "\t>>> Cloudflare Warp is $warpstatus\n\t>>> Exiting with success" exit 0 elif [ $? -a $warpstatus == "Connected" ]; then echo -e "\t>>> Cloudflare Warp is $warpstatus\n\t>>> Exiting with success" exit 0 else echo -e "\t>>> Cloudflare Warp is $warpstatus\n\t>>> Exiting with failure" exit 1 fi fi