hamlinzheng / docker-zerotier-server

44 stars 11 forks source link

Linux join network script #3

Open SozinovD opened 1 year ago

SozinovD commented 1 year ago

This script should be called with two arguments: ./zt-install-and-join-network.sh <my.server.domain> <network_id> You can use ip address instead of domain name Or you can just hardcode your data right into script for easier distribution (lines 2 and 3)

#!/bin/bash
server_ip=$1
network_id=$2
if [ `whoami` != root ]; then echo "Run as root required, abort"; exit 1; fi
if ! [ -z "systemctl  list-unit-files | grep zerotier-one" ]; then echo "Zerotier already installed, abort"; exit 1; fi
if [ -z $server_ip ]; then echo "Server ip not set, abort"; exit 1; fi
if [ -z $network_id ]; then echo "Network id not set, abort"; exit 1; fi

# get gpg keys
curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import && if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | sudo bash; fi
# get custom planet file
sudo wget http://$server_ip:4000/app/static/planet -O /var/lib/zerotier-one/planet
# restart daemon
sudo systemctl restart zerotier-one.service
# join network
sleep 10
sudo zerotier-cli join $network_id