diff --git a/scripts/netclient-install.sh b/scripts/netclient-install.sh index e9abcacb..4322c5d0 100755 --- a/scripts/netclient-install.sh +++ b/scripts/netclient-install.sh @@ -1,11 +1,54 @@ -#!/bin/bash -set -e +#!/bin/sh -if [ "$EUID" -ne 0 ]; then +if [ $(id -u) -ne 0 ]; then echo "This script must be run as root" exit 1 fi +echo "checking dependencies..." + +if [ -f /etc/debian_version ]; then + install_cmd='apt-get install -y' +elif [ -f /etc/alpine-release ]; then + install_cmd='apk --update add' +elif [ -f /etc/centos-release ]; then + install_cmd='yum install -y' +elif [ -f /etc/fedora-release ]; then + install_cmd='dnf install -y' +else + install_cmd='' +fi + +if [ -z "${install_cmd}" ]; then + echo "OS unsupported for automatic dependency install" + exit 1 +fi +dependencies="wireguard resolvectl" +set -- $dependencies +while [ -n "$1" ]; do + echo $1 + is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed") + if [ "${is_installed}" = "install ok installed" ]; then + echo " " $1 is installed + else + echo " " $1 is not installed. Attempting install. + ${install_cmd} $1 + sleep 5 + is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed") + if [ "${is_installed}" = "install ok installed" ]; then + echo " " $1 is installed + elif [ -x "$(command -v $1)" ]; then + echo " " $1 is installed + else + echo " " FAILED TO INSTALL $1 + echo " " This may break functionality. + fi + fi + shift +done + +set -e + [ -z "$KEY" ] && KEY=nokey; [ -z "$VERSION" ] && echo "no \$VERSION provided, fallback to latest" && VERSION=latest; @@ -14,28 +57,42 @@ dist=netclient echo "OS Version = $(uname)" echo "Netclient Version = $VERSION" -if [[ "$(uname)" == "Linux"* ]]; then - arch=$(uname -i) - echo "CPU ARCH = $arch" - if [ "$arch" == 'x86_64' ]; - then - dist=netclient - fi - if [ "$arch" == 'x86_32' ]; - then - dist=netclient-32 - fi - if [ "$arch" == 'armv*' ]; - then - dist=netclient-arm64 - fi -elif [[ "$(uname)" == "Darwin"* ]]; then - dist=netclient-darwin -fi +case $(uname | tr '[:upper:]' '[:lower:]') in + linux*) + if [ -z "$CPU_ARCH" ]; then + CPU_ARCH=$(uname -m) + fi + case $CPU_ARCH in + amd64) + dist=netclient + ;; + x86_64) + dist=netclient + ;; + x86_32) + dist=netclient-32 + ;; + arm64) + dist=netclient-arm64 + ;; + aarch64) + dist=netclient-arm64 + ;; + arm*) + dist=netclient-$CPU_ARCH + ;; + *) + fatal "$CPU_ARCH : cpu architecture not supported" + esac + ;; + darwin) + dist=netclient-darwin + ;; +esac echo "Binary = $dist" -wget -O netclient https://github.com/gravitl/netmaker/releases/download/$VERSION/netclient +wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist chmod +x netclient sudo ./netclient join -t $KEY rm -f netclient diff --git a/scripts/nm-quick-server.sh b/scripts/nm-quick-server.sh new file mode 100644 index 00000000..00045a61 --- /dev/null +++ b/scripts/nm-quick-server.sh @@ -0,0 +1,109 @@ +#!/bin/bash +echo "checking for root permissions..." + +if [ $EUID -ne 0 ]; then + echo "This script must be run as root" + exit 1 +fi + + +echo "checking dependencies..." + +declare -A osInfo; +osInfo[/etc/debian_version]="apt-get install -y" +osInfo[/etc/alpine-release]="apk --update add" +osInfo[/etc/centos-release]="yum install -y" +osInfo[/etc/fedora-release]="dnf install -y" + +for f in ${!osInfo[@]} +do + if [[ -f $f ]];then + install_cmd=${osInfo[$f]} + fi +done + +dependencies=("docker.io" "docker-compose" "wireguard") + +for dependency in ${dependencies[@]}; do + is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed") + + if [ "${is_installed}" == "install ok installed" ]; then + echo " " ${dependency} is installed + else + echo " " ${dependency} is not installed. Attempting install. + ${install_cmd} ${dependency} + sleep 5 + is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed") + if [ "${is_installed}" == "install ok installed" ]; then + echo " " ${dependency} is installed + elif [ -x "$(command -v ${dependency})" ]; then + echo " " ${dependency} is installed + else + echo " " failed to install ${dependency}. Exiting. + exit 1 + fi + fi +done + + + + +set -e + +echo "setting public ip values..." + +NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io +COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p') +SERVER_PUBLIC_IP=$(curl -s ifconfig.me) +REPLACE_MASTER_KEY=$(tr -dc A-Za-z0-9