diff --git a/scripts/quicktinc.sh b/scripts/quicktinc.sh deleted file mode 100755 index 2f433f5..0000000 --- a/scripts/quicktinc.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash - -# from https://github.com/j3k0/quicktinc - -set -e - -IMAGE="fschl/tinc" - -function usage() { - echo " -Usage: - $0 run --net= - start a container for $network with existing configuration - -or create configuration with: - - $0 init [OPTIONS] - -Options: - --net=NET_NAME Network name (required) - --node=NODE_NAME Node name (required) - --public-ip=PUBLIC_IP Node's public IP (required) - --private-ip=PRIVATE_IP Node's private IP (required) - --connect-to=HOST Name of another node (optional, repeatable) - --interface=tun0 Network interface to create (optional, default=tun0) - --config=/etc/tinc Where to save tinc networks (optional, default=/etc/tinc) - --up Also start the daemon - -Example: - $0 --net=demonet --node=node23 --public-ip=8.9.10.11 --private-ip=10.0.0.23 --connect-to=node1 --connect-to=node2 - $0 -n=demonet -o=node23 -p=8.9.10.11 -v=10.0.0.23 -c=node1 -c=node2 - -Report bugs to -" - exit 1 -} - -function parse_args() { - for i in "$@" - do - case $i in - -n=*|--net=*) - NET_NAME="${i#*=}" - shift # past argument=value - ;; - -o=*|--node=*) - NODE_NAME="${i#*=}" - shift # past argument=value - ;; - -v=*|--private-ip=*) - PRIVATE_IP="${i#*=}" - shift # past argument=value - ;; - -p=*|--public-ip=*) - PUBLIC_IP="${i#*=}" - shift # past argument=value - ;; - -c=*|--connect-to=*) - CONNECT_TO="$CONNECT_TO ${i#*=}" - shift # past argument=value - ;; - -i=*|--interface=*) - INTERFACE="${i#*=}" - shift # past argument=value - ;; - -C=*|--config=*) - TINC_HOME="${i#*=}" - shift # past argument=value - ;; - *) - # unknown option - usage - ;; - esac - done - - if [ "_$NET_NAME" = "_" ]; then usage; fi - if [ "_$NODE_NAME" = "_" ]; then usage; fi - if [ "_$PRIVATE_IP" = "_" ]; then usage; fi - if [ "_$PUBLIC_IP" = "_" ]; then usage; fi - - if [ "_$INTERFACE" = "_" ]; then - INTERFACE=tun0 - fi - - if [ "_$TINC_HOME" = "_" ]; then - TINC_HOME=/etc/tinc - fi -} - -function tinc() { - docker run --rm --net=host --device=/dev/net/tun --cap-add NET_ADMIN --volume $TINC_HOME:/etc/tinc $IMAGE -n $NET_NAME "$@" -} - -init_node() { - # Initialize configuration file - tinc init $NODE_NAME - - # Setup host file - # Declare public and private IPs in the host file, CONFIG/NET/hosts/HOST - echo "Address = $PUBLIC_IP" >> $TINC_HOME/$NET_NAME/hosts/$NODE_NAME - echo "Subnet = $PRIVATE_IP/32" >> $TINC_HOME/$NET_NAME/hosts/$NODE_NAME - - # Tweak the config to add our particular setup - tinc add AddressFamily ipv4 - tinc add Device /dev/net/tun - tinc add Interface $INTERFACE - if [ "_$CONNECT_TO" != "_" ]; then - for i in $CONNECT_TO; do - tinc add ConnectTo $i - done - fi - - # Edit the tinc-up script - cat << EOF > $TINC_HOME/$NET_NAME/tinc-up -#!/bin/sh -ifconfig \$INTERFACE $PRIVATE_IP netmask 255.255.255.0 -EOF - - cat << EOF > $TINC_HOME/$NET_NAME/tinc-down -#!/bin/sh -ifconfig \$INTERFACE down -EOF - - chmod +x $TINC_HOME/$NET_NAME/tinc-up - chmod +x $TINC_HOME/$NET_NAME/tinc-down -} - -run_container() { - NAME=tinc_$NET_NAME_$NODE_NAME - docker run -d --restart=always --name=$NAME --net=host --device=/dev/net/tun --cap-add NET_ADMIN --volume $TINC_HOME:/etc/tinc $IMAGE -n $NET_NAME start -D - echo "Docker container started with name: $NAME" -} - - -main() { - local cmd=$1 - shift - - if [[ -z "$cmd" ]]; then - usage - fi - - case "$cmd" in - init) - parse_args $@ - init_node - ;; - run) - parse_args $@ - run_container - ;; - esac -} - -main "$@"