From 77941e497c9398dbe75be7bad1f7610862ba5b5f Mon Sep 17 00:00:00 2001 From: Frieder Schlesier Date: Fri, 1 Feb 2019 13:57:36 +0100 Subject: [PATCH] update quicktinc --- scripts/install.sh | 1 + scripts/quicktinc.sh | 108 +++++++++++++++++++++---------------------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 8bdc98f..b8295e5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -212,6 +212,7 @@ install_i3() { libreoffice-l10n-en-gb \ network-manager-gnome \ ntfs-3g \ + nmap \ pulseaudio \ rxvt-unicode-256color \ scrot \ diff --git a/scripts/quicktinc.sh b/scripts/quicktinc.sh index 2f9f500..2f433f5 100755 --- a/scripts/quicktinc.sh +++ b/scripts/quicktinc.sh @@ -26,67 +26,66 @@ Options: --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 --up - $0 --n=demonet --o=node23 --p=8.9.10.11 --v=10.0.0.23 --c=node1 --connect-to=node2 --up + $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 } -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 - ;; - --up) - TINC_UP=YES - ;; - *) - # unknown option - usage - ;; - esac -done +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 [ "_$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 [ "_$INTERFACE" = "_" ]; then + INTERFACE=tun0 + fi -if [ "_$TINC_HOME" = "_" ]; then - TINC_HOME=/etc/tinc -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 "$@" @@ -127,16 +126,15 @@ EOF } run_container() { - # if [ "_$TINC_UP" != "_" ]; then 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" - # fi } main() { local cmd=$1 + shift if [[ -z "$cmd" ]]; then usage @@ -144,9 +142,11 @@ main() { case "$cmd" in init) + parse_args $@ init_node ;; run) + parse_args $@ run_container ;; esac