-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvlp
executable file
·161 lines (151 loc) · 4.16 KB
/
vlp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
DIR=`dirname $0`
VLPHOME="$(cd $DIR; pwd)"
. $VLPHOME/vlp.env
VLPCFG="$VLPHOME/.vpn-launchpad"
VLPDKDIR="$VLPHOME/vpnlaunchpad"
ARCH=`uname -m`
DKUID=`id -u`
DKGID=`id -g`
VLPUSER="vlp"
VLPGROUP="vlp"
IMGNAME="samuelhbne/vpnlaunchpad"
CTNNAME="vpnlaunchpad"
if [ "$DKUID" = "0" ]; then
echo "Non-root user required."
echo "Abort."
exit 255
fi
DOCKERVER=`docker -v 2>/dev/null|awk '{print $3}'`
if [ "$DOCKERVER" = "" ]; then
echo "Docker executable not found.."
echo "Abort."
exit 255
fi
DKVERMAJOR=`echo $DOCKERVER|cut -d. -f1`
DKVERMINOR=`echo $DOCKERVER|cut -d. -f2`
if (("$DKVERMAJOR" < 18)); then
echo "Unsupported Docker version $DOCKERVER, please upgrade to Docker version 18.09 at least"
exit
fi
case $ARCH in
armv6l|armv7l)
TARGET=arm
;;
x86_64|i686|i386)
TARGET=amd64
;;
aarch64)
TARGET=arm64
;;
*)
echo "Unsupported arch"
exit
;;
esac
VLPOPT="$1"
case "$VLPOPT" in
--from-src)
shift
echo "Building vpnlaunchpad image..."
docker build -t $IMGNAME:$TARGET -f $VLPDKDIR/Dockerfile.$TARGET $VLPDKDIR/
docker stop $CTNNAME 2>/dev/null
echo "Done."
;;
*)
;;
esac
BEXIST=`docker ps| grep $CTNNAME|wc -l`
if [ $BEXIST -eq 0 ]; then
docker stop $CTNNAME 2>/dev/null
docker rm $CTNNAME 2>/dev/null
echo "Start vpnlaunchpad container..."
docker run --name=$CTNNAME -v $VLPHOME:/vlp -itd $IMGNAME:$TARGET /bin/bash
docker exec -it $CTNNAME groupmod -g $DKGID $VLPGROUP
docker exec -it $CTNNAME usermod -u $DKUID -g $DKGID $VLPUSER
echo "Done."
echo
fi
DOCKERCMD="docker exec --user $DKUID:$DKGID -it $CTNNAME"
subcmd="$1"
case $subcmd in
init)
shift
mkdir -p $VLPHOME/.vpn-launchpad $VLPHOME/.aws
BPROFILE=`grep "\[profile $PROFILE\]" $VLPHOME/.aws/config 2>/dev/null`
if [ "$BPROFILE" = "" ]; then
echo -e "[profile $PROFILE]\nregion = ap-northeast-1\noutput = json">>$VLPHOME/.aws/config
fi
$DOCKERCMD bash -c "while read -r -t 0; do read -r; done; /usr/bin/aws --profile $PROFILE configure"
exit $?
;;
build)
shift
$DOCKERCMD bash -c "/vlp/bin/vlp-random $*; /vlp/bin/vlp-build $*; /vlp/bin/vlp-status --all"
exit $?
;;
status)
shift
$DOCKERCMD /vlp/bin/vlp-status "$*"
exit $?
;;
purge)
shift
$DOCKERCMD /vlp/bin/vlp-purge
echo
echo "Stop vpnlaunchpad sandbox..."
docker stop $CTNNAME 2>/dev/null
docker rm $CTNNAME 2>/dev/null
echo "Done."
exit 0
;;
random)
shift
$DOCKERCMD /vlp/bin/vlp-random
exit $?
;;
ssh)
shift
$DOCKERCMD /vlp/bin/vlp-ssh
RETCODE="$?"
if [ $RETCODE = "0" ]; then
. $VLPCFG/ssh.env
if [ "$VPSKEY" != "" ] || [ "$VPSADDR" != "" ]; then
echo "ssh -i $VLPCFG/$VPSKEY ubuntu@$VPSADDR" "$@"
echo
exec ssh -i $VLPCFG/$VPSKEY ubuntu@$VPSADDR "$@"
else
echo "Failed reading ssh env. Read only folder?"
exit 254
fi
else
exit $RETCODE
fi
;;
menu)
shift
$DOCKERCMD /vlp/bin/vlp-menu
exit $?
;;
*)
shift
echo "vlp [--from-src] <command> [options]"
echo " --from-src -- Build dependency container from source rather than docker image downloading"
echo " init -- Init aws account credential."
echo " build -- Build VPN server."
echo " --from-src -- Build VPN server from source rather than docker image downloading"
echo " --with-brook -- Build VPN server with Brook services installed"
echo " --with-l2tp -- Build VPN server with L2TP services installed"
echo " --with-v2ray -- Build VPN server with V2Ray services installed"
echo " --with-trojan -- Build VPN server with Trojan services installed"
echo " --with-sslibev -- Build VPN server with Shadowsocks services installed"
echo " --with-random -- Build VPN server with VPN passwords randomisation."
echo " --without-random -- Build VPN server without VPN passwords randomisation."
echo " status -- Check VPN server status."
echo " --with-qrcode -- Print Shadowsocks and V2Ray connection QR Code."
echo " purge -- Destory VPN server instance."
echo " random -- Randomise VPN passwords."
echo " ssh -- SSH login into VPN server instance."
exit 0;
;;
esac