Add makefile and simpler startup.
This commit is contained in:
parent
8ab77a16a6
commit
7ca9b5016e
8 changed files with 50 additions and 17 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
config.ovpn
|
||||
auth.txt
|
||||
start
|
||||
build-docker
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
FROM alpine:latest
|
||||
|
||||
RUN apk add bash openvpn openresolv aria2
|
||||
ADD https://raw.githubusercontent.com/alfredopalhares/openvpn-update-resolv-conf/master/update-resolv-conf.sh \
|
||||
/etc/openvpn/update-resolv-conf
|
||||
COPY start-openvpn.sh /usr/local/bin/start-openvpn.sh
|
||||
RUN chmod +x /etc/openvpn/update-resolv-conf \
|
||||
&& chmod +x /usr/local/bin/start-openvpn.sh
|
||||
RUN chmod +x /usr/local/bin/start-openvpn.sh
|
||||
ENTRYPOINT [ "start-openvpn.sh" ]
|
||||
|
|
22
Makefile
Normal file
22
Makefile
Normal file
|
@ -0,0 +1,22 @@
|
|||
START_SCRIPT := start
|
||||
START_SCRIPT_SRC := start.tmpl
|
||||
INSTALLATION_NAME := openvpn-aria2
|
||||
DOCKERFILE := Dockerfile
|
||||
TAG = openvpn-aria2
|
||||
|
||||
build: build-docker $(START_SCRIPT)
|
||||
|
||||
build-docker: $(DOCKERFILE) start-openvpn.sh
|
||||
docker build --tag=$(TAG) .
|
||||
echo "This is a marker for the docker build." > $@
|
||||
|
||||
$(START_SCRIPT): $(START_SCRIPT_SRC)
|
||||
sed -e "s/{TAG}/$(TAG)/g" -e "s/{INSTALLATION_NAME}/$(INSTALLATION_NAME)/g" $< > $@
|
||||
chmod +x $@
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) build-docker $(START_SCRIPT)
|
||||
|
||||
install:
|
||||
install -D --mode=755 $(START_SCRIPT) /usr/local/bin/$(INSTALLATION_NAME)
|
|
@ -1 +0,0 @@
|
|||
OVPN_CONFIGURATION_FILE=/opt/config.ovpn
|
|
@ -1,4 +1,4 @@
|
|||
version: '3.3'
|
||||
version: '2.0'
|
||||
services:
|
||||
openvpn:
|
||||
restart: never
|
||||
|
@ -7,6 +7,7 @@ services:
|
|||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- ./config.ovpn:/opt/config.ovpn
|
||||
- ./ovpn_config:/opt/ovpn_config
|
||||
- ./auth.txt:/opt/auth.txt
|
||||
- /etc/passwd:/etc/passwd
|
||||
cap_add:
|
||||
|
|
7
start
7
start
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
docker-compose run \
|
||||
-e OVPN_USER="$USER" \
|
||||
-e OVPN_HOME="$HOME" \
|
||||
-v "$HOME:$HOME" \
|
||||
openvpn sh
|
|
@ -17,7 +17,7 @@ connect_vpn() {
|
|||
}
|
||||
|
||||
get_ip() {
|
||||
nsout="$(nslookup myip.opendns.com resolver1.opendns.com)"
|
||||
nsout="$(nslookup -timeout=1 myip.opendns.com resolver1.opendns.com)"
|
||||
if [ "$?" != 0 ]; then
|
||||
echo "WARN: Failed to run nslookup" >&2
|
||||
fi
|
||||
|
@ -35,12 +35,16 @@ switch_user() {
|
|||
|
||||
own_ip="$(get_ip)"
|
||||
echo "OWN IP: $own_ip"
|
||||
if [ "$own_ip" = "" ]; then
|
||||
echo "ERROR: Failed to lookup own ip, aborting" >&2
|
||||
exit 1
|
||||
fi
|
||||
change_hostname
|
||||
create_net_dev
|
||||
connect_vpn
|
||||
for _ in {1..50}; do
|
||||
vpn_ip="$(get_ip)"
|
||||
if [ "$vpn_ip" = "$own_ip" ]; then
|
||||
if [ "$vpn_ip" = "$own_ip" ] || [ "$vpn_ip" = "" ]; then
|
||||
sleep .1
|
||||
else
|
||||
break
|
||||
|
|
17
start.tmpl
Executable file
17
start.tmpl
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
INSTALLATION_NAME='{INSTALLATION_NAME}'
|
||||
TAG='{TAG}'
|
||||
|
||||
|
||||
source "/etc/$INSTALLATION_NAME.conf"
|
||||
|
||||
|
||||
docker run -it --cap-add NET_ADMIN \
|
||||
-v /etc/passwd:/etc/passwd \
|
||||
-v /etc/openvpn/client:/etc/openvpn/client \
|
||||
-v "$HOME:$HOME" \
|
||||
-e OVPN_USER="$USER" \
|
||||
-e OVPN_HOME="$HOME" \
|
||||
-e OVPN_CONFIGURATION_FILE="/etc/openvpn/client/$OVPN_CONFIGURATION_FILE" \
|
||||
"$TAG" sh
|
Loading…
Reference in a new issue