-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathentrypoint.sh
49 lines (37 loc) · 996 Bytes
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Ensure that the following env variables are set
# VPN_SERVER_IP
# VPN_USERNAME
# VPN_PASSWORD
# VPN_SERVER_CERT
# AUTH_GROUP
# SSH_KEY
# REMOTE_IP
# REMOTE_USERNAME
# ENV_PATH
set -e
# Logging in to the VPN Client
echo -e $VPN_PASSWORD | openconnect $VPN_SERVER_IP \
-u $VPN_USERNAME \
--servercert $VPN_SERVER_CERT \
--authgroup $AUTH_GROUP \
--passwd-on-stdin \
-b
# Add ssh keys
# deleting if there exists
mkdir -p ~/.ssh/
rm -rf ~/.ssh/some_secret_file
touch ~/.ssh/some_secret_file
echo "$SSH_KEY" >> ~/.ssh/some_secret_file
chmod 400 ~/.ssh/some_secret_file
# Add ssh keys to agent
eval $(ssh-agent -s)
ssh-add ~/.ssh/some_secret_file
chmod +x remote_leader.sh
# waiting for 5 seconds
sleep 5
echo "Connecting to remote server..."
# ssh into the server
ssh -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no "$REMOTE_USERNAME@$REMOTE_IP" env ENV_PATH="$ENV_PATH" "/bin/bash -s " < remote_leader.sh
# TODO: Push the logs file
echo "Terminating Entrypoint..."