-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·69 lines (59 loc) · 1.45 KB
/
run.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash -e
USE_HOST=${USE_HOST:-0}
KEEP_CONTAINER=${KEEP_CONTAINER:-0}
. ./config/app_config.sh
cleanup_container() {
docker rm -f $APP_NAME
}
if [[ $USE_HOST != 0 ]]; then
./scripts/run/vpn.sh
exit 0
else
cleanup_container 2>> /dev/null
# Start container
docker run \
--name $APP_NAME \
--privileged \
--env APPUSER_PASSWD=$APPUSER_PASSWD \
--env APP_READY_FILE=$APP_READY_FILE \
--env VPN_SERVER=$VPN_SERVER \
--net=bridge \
-p 53:53/udp \
-p $DOCKER_SSH_PORT:22/tcp \
-d \
$FULL_TAG $@
# Attach to container
attach() {
docker exec -u root -it $APP_NAME bash
}
fi
# Setup DNS forwarding
. ./scripts/host/config_dns.sh
cleanup ()
{
echo "Interrupt caught... Cleaning up DNS and container"
unset_vpnshuttle_dns || true
if [[ $KEEP_CONTAINER == 0 ]]; then
cleanup_container
fi
exit 2
}
trap cleanup EXIT
check_vpn_connected() {
docker exec $APP_NAME bash -c "cat ${APP_READY_FILE} 2> /dev/null"
}
ceol=$(tput el)
while [[ ! $(check_vpn_connected) ]]; do
echo -ne "\r${ceol}Waiting for ${APP_NAME} to become ready..."
sleep 5
done
set_vpnshuttle_dns
# Start sshuttle
cmd="sshuttle -r \
appuser:$APPUSER_PASSWD@localhost:$DOCKER_SSH_PORT \
-v $REDIRECT_SUBNETS\
--auto-nets \
--auto-hosts \
-e 'ssh -o \"StrictHostKeyChecking no\" -o \"UserKnownHostsFile /dev/null\"'"
echo $cmd
eval $cmd