1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-23 01:39:27 +02:00

add peer.sh to generate profile for tinc-vpn

This commit is contained in:
kev 2016-07-08 02:07:37 +08:00
parent 1b84e71180
commit b9c2519184
5 changed files with 80 additions and 6 deletions

View File

@ -17,6 +17,7 @@ $ ffmpeg -i video.mov video.mp4
## Todo List ## Todo List
- [ ] Re-compile with fontconfig/freetype enabled to support text overlay. - [ ] Re-compile with fontconfig/freetype enabled to support [timestamp][2] overlay.
[1]: http://ffmpeg.org/ [1]: http://ffmpeg.org/
[2]: https://einar.slaskete.net/2011/09/05/adding-time-stamp-overlay-to-video-stream-using-ffmpeg/

View File

@ -9,6 +9,7 @@ RUN apk add --no-cache iptables tinc
COPY init.sh /init.sh COPY init.sh /init.sh
COPY docker-entrypoint.sh /entrypoint.sh COPY docker-entrypoint.sh /entrypoint.sh
COPY peer.sh /usr/local/bin/peer.sh
VOLUME /etc/tinc VOLUME /etc/tinc

View File

@ -1,4 +0,0 @@
#!/bin/sh
#
# generate client profile
#

View File

@ -6,7 +6,7 @@ tinc:
volumes: volumes:
- ./tinc:/etc/tinc - ./tinc:/etc/tinc
environment: environment:
- IP_ADDR=45.32.57.113 - IP_ADDR=1.2.3.4
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
dns: 8.8.8.8 dns: 8.8.8.8

76
tinc/peer.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/sh -e
#
# generate peer profile
#
PEER_NAME=${1:?peer name is empty}
PEER_ADDR=${2:?peer addr is empty}
if [ -f /etc/tinc/${NETNAME}/hosts/${PEER_NAME} ]
then
echo 'Peer name was taken!'
exit 1
elif fgrep -qr ${PEER_ADDR} /etc/tinc/${NETNAME}/hosts/
then
echo 'Peer addr was taken!'
exit 2
else
echo 'Generating...'
fi
mkdir -p /etc/tinc/${NETNAME}/peers/${PEER_NAME}/tinc/${NETNAME}/hosts
cd /etc/tinc/${NETNAME}/peers/${PEER_NAME}/tinc/${NETNAME}
cp /etc/tinc/${NETNAME}/hosts/server hosts/server
cat > tinc.conf <<_EOF_
Name = ${PEER_NAME}
Interface = tun0
ConnectTo = server
_EOF_
cat > hosts/${PEER_NAME} <<_EOF_
Subnet = ${PEER_ADDR}
_EOF_
tincd -c. -K${KEYSIZE} < /dev/null
cp /etc/tinc/${NETNAME}/peers/${PEER_NAME}/tinc/${NETNAME}/hosts/${PEER_NAME} \
/etc/tinc/${NETNAME}/hosts/${PEER_NAME}
cat > tinc-up <<_EOF_
#!/bin/sh
ip link set \$INTERFACE up
ip addr add ${PEER_ADDR}/${NETMASK} dev \$INTERFACE
_EOF_
cat > tinc-down <<_EOF_
#!/bin/sh
ip addr del ${PEER_ADDR}/${NETMASK} dev \$INTERFACE
ip link set \$INTERFACE down
_EOF_
cat > hosts/server-up <<"_EOF_"
#!/bin/sh
ORIGINAL_GATEWAY=$(ip route show | grep ^default | cut -d ' ' -f 2-3)
ip route add $REMOTEADDRESS $ORIGINAL_GATEWAY
ip route add 0.0.0.0/1 dev $INTERFACE
ip route add 128.0.0.0/1 dev $INTERFACE
_EOF_
cat > hosts/server-down <<"_EOF_"
#!/bin/sh
ORIGINAL_GATEWAY=$(ip route show | grep ^default | cut -d ' ' -f 2-3)
ip route del $REMOTEADDRESS $ORIGINAL_GATEWAY
ip route del 0.0.0.0/1 dev $INTERFACE
ip route del 128.0.0.0/1 dev $INTERFACE
_EOF_
chmod +x tinc-up tinc-down hosts/server-up hosts/server-down
cd /etc/tinc/${NETNAME}/peers
tar czf ${PEER_NAME}.tar.gz ${PEER_NAME}
rm -rf ${PEER_NAME}
echo "'${PEER_NAME}' => '${PWD}/${PEER_NAME}.tar.gz'"