From b9c2519184bb75a9ad594062b70a695360272d3d Mon Sep 17 00:00:00 2001 From: kev Date: Fri, 8 Jul 2016 02:07:37 +0800 Subject: [PATCH] add peer.sh to generate profile for tinc-vpn --- ffmpeg/README.md | 3 +- tinc/Dockerfile | 1 + tinc/client.sh | 4 --- tinc/docker-compose.yml | 2 +- tinc/peer.sh | 76 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 6 deletions(-) delete mode 100755 tinc/client.sh create mode 100755 tinc/peer.sh diff --git a/ffmpeg/README.md b/ffmpeg/README.md index f746564..586fac8 100644 --- a/ffmpeg/README.md +++ b/ffmpeg/README.md @@ -17,6 +17,7 @@ $ ffmpeg -i video.mov video.mp4 ## 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/ +[2]: https://einar.slaskete.net/2011/09/05/adding-time-stamp-overlay-to-video-stream-using-ffmpeg/ diff --git a/tinc/Dockerfile b/tinc/Dockerfile index 448aa99..f011875 100644 --- a/tinc/Dockerfile +++ b/tinc/Dockerfile @@ -9,6 +9,7 @@ RUN apk add --no-cache iptables tinc COPY init.sh /init.sh COPY docker-entrypoint.sh /entrypoint.sh +COPY peer.sh /usr/local/bin/peer.sh VOLUME /etc/tinc diff --git a/tinc/client.sh b/tinc/client.sh deleted file mode 100755 index 26dc85d..0000000 --- a/tinc/client.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# -# generate client profile -# diff --git a/tinc/docker-compose.yml b/tinc/docker-compose.yml index e99be8e..4159daa 100644 --- a/tinc/docker-compose.yml +++ b/tinc/docker-compose.yml @@ -6,7 +6,7 @@ tinc: volumes: - ./tinc:/etc/tinc environment: - - IP_ADDR=45.32.57.113 + - IP_ADDR=1.2.3.4 cap_add: - NET_ADMIN dns: 8.8.8.8 diff --git a/tinc/peer.sh b/tinc/peer.sh new file mode 100755 index 0000000..1deb899 --- /dev/null +++ b/tinc/peer.sh @@ -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'"