Skip to content

Instantly share code, notes, and snippets.

@NathanAlcantara
Created July 14, 2021 20:45
Show Gist options
  • Save NathanAlcantara/d1c1518c52ffdc9c1840fa87571910e4 to your computer and use it in GitHub Desktop.
Save NathanAlcantara/d1c1518c52ffdc9c1840fa87571910e4 to your computer and use it in GitHub Desktop.
Script to start a vpn via openconnect;
#! /bin/bash
#####
#
# Script to start a vpn via openconnect;
#
#####
PORTAL="<DNS_OR_IP>"
USER="<USER>"
CONTINER_NAME="vpn"
IMAGE_NAME="openconnect"
DIR=~/Documents/openconnect
echo "[x] Preparing to enter on a vpn via openconnect"
if [ "$(docker image inspect $IMAGE_NAME | jq 'isempty(.[])')" == "true" ]; then
if [ ! -d "$DIR" ]; then
echo -e "\n[x] Directory $DIR not found, cloning the project from github"
git clone --single-branch -b globalprotect https://github.com/dlenski/openconnect.git "$DIR"
cd "$DIR"
git reset --hard 2d2da4771acb5acad31102c343372cb1390bbec3
else
cd "$DIR"
fi
echo -e "\n[x] Image $IMAGE_NAME not found, build a new one"
docker build -t "$IMAGE_NAME" .
rm -rf $DIR
fi
if [ "$(docker ps -q -f name=$CONTINER_NAME)" ]; then
echo -e "\n[x] Container with a name $CONTINER_NAME already created, let's clean this up"
docker rm "$CONTINER_NAME" -f
fi
echo -e "\n[x] Finnaly, running the $CONTAINER_NAME with image of $IMAGE_NAME, pointing to portal: $PORTAL, using the user: $USER, just type your password"
docker run -ti --rm --privileged --net=host --name $CONTINER_NAME "$IMAGE_NAME" ./openconnect --protocol=gp $PORTAL -u $USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment