mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 00:24:37 +08:00
fixed openwrt/windows scripts
This commit is contained in:
parent
e02ace0698
commit
bdd1c8fc38
4 changed files with 169 additions and 58 deletions
11
README.md
11
README.md
|
@ -88,6 +88,17 @@ After installing Netmaker, check out the [Walkthrough](https://itnext.io/getting
|
||||||
|
|
||||||
- [Learning Resources](https://gravitl.com/resources)
|
- [Learning Resources](https://gravitl.com/resources)
|
||||||
|
|
||||||
|
# Community Projects
|
||||||
|
|
||||||
|
- [Netmaker + Traefik Proxy](https://github.com/bsherman/netmaker-traefik)
|
||||||
|
|
||||||
|
- [OpenWRT Netclient Packager](https://github.com/sbilly/netmaker-openwrt)
|
||||||
|
|
||||||
|
- [Golang GUI](https://github.com/mattkasun/netmaker-gui)
|
||||||
|
|
||||||
|
- [CoreDNS Plugin](https://github.com/SekoiaLab/netmaker-coredns)
|
||||||
|
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
[WireGuard](https://wireguard.com/) is a registered trademark of Jason A. Donenfeld.
|
[WireGuard](https://wireguard.com/) is a registered trademark of Jason A. Donenfeld.
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ new-module -name netclient-install -scriptblock {
|
||||||
Function Netclient-Install() {
|
Function Netclient-Install() {
|
||||||
param ($version='latest', $token)
|
param ($version='latest', $token)
|
||||||
|
|
||||||
|
|
||||||
if($token -eq $null -or $token -eq ""){
|
if($token -eq $null -or $token -eq ""){
|
||||||
Quit "-token required"
|
Quit "-token required"
|
||||||
}
|
}
|
||||||
|
@ -48,6 +47,9 @@ new-module -name netclient-install -scriptblock {
|
||||||
$loc = Get-Location
|
$loc = Get-Location
|
||||||
Copy-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "$loc\netclient.exe"
|
Copy-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "$loc\netclient.exe"
|
||||||
}
|
}
|
||||||
|
$runNum = "one","two"
|
||||||
|
foreach ($run in $runNum) {
|
||||||
|
|
||||||
$NetArgs = @("join","-t",$token)
|
$NetArgs = @("join","-t",$token)
|
||||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs -Wait
|
Start-Process -Filepath $outpath -ArgumentList $NetArgs -Wait
|
||||||
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
||||||
|
@ -62,6 +64,12 @@ new-module -name netclient-install -scriptblock {
|
||||||
$env:Path += ";C:\ProgramData\Netclient\bin"
|
$env:Path += ";C:\ProgramData\Netclient\bin"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($run -eq "one"){
|
||||||
|
Write-Host "re-running setup to confirm all components are installed."
|
||||||
|
Start-Sleep -s 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Write-Host "'netclient' is installed."
|
Write-Host "'netclient' is installed."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,30 @@ echo "checking dependencies..."
|
||||||
OS=$(uname)
|
OS=$(uname)
|
||||||
|
|
||||||
if [ -f /etc/debian_version ]; then
|
if [ -f /etc/debian_version ]; then
|
||||||
|
dependencies="wireguard wireguard-tools"
|
||||||
|
update_cmd='apt update'
|
||||||
install_cmd='apt-get install -y'
|
install_cmd='apt-get install -y'
|
||||||
elif [ -f /etc/alpine-release ]; then
|
elif [ -f /etc/alpine-release ]; then
|
||||||
|
dependencies="wireguard"
|
||||||
|
update_cmd='apk update'
|
||||||
install_cmd='apk --update add'
|
install_cmd='apk --update add'
|
||||||
elif [ -f /etc/centos-release ]; then
|
elif [ -f /etc/centos-release ]; then
|
||||||
|
dependencies="wireguard"
|
||||||
|
update_cmd='yum update'
|
||||||
install_cmd='yum install -y'
|
install_cmd='yum install -y'
|
||||||
elif [ -f /etc/fedora-release ]; then
|
elif [ -f /etc/fedora-release ]; then
|
||||||
|
dependencies="wireguard"
|
||||||
|
update_cmd='dnf update'
|
||||||
install_cmd='dnf install -y'
|
install_cmd='dnf install -y'
|
||||||
elif [ "${OS}" = "FreeBSD" ]; then
|
elif [ "${OS}" = "FreeBSD" ]; then
|
||||||
|
dependencies="wireguard"
|
||||||
|
update_cmd='pkg update'
|
||||||
install_cmd='pkg install -y'
|
install_cmd='pkg install -y'
|
||||||
|
elif [ -f /etc/openwrt_release ]; then
|
||||||
|
dependencies="wireguard-tools"
|
||||||
|
OS="OpenWRT"
|
||||||
|
update_cmd='opkg update'
|
||||||
|
install_cmd='opkg install'
|
||||||
else
|
else
|
||||||
install_cmd=''
|
install_cmd=''
|
||||||
fi
|
fi
|
||||||
|
@ -27,7 +42,7 @@ if [ -z "${install_cmd}" ]; then
|
||||||
echo "OS unsupported for automatic dependency install"
|
echo "OS unsupported for automatic dependency install"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
dependencies="wireguard"
|
|
||||||
set -- $dependencies
|
set -- $dependencies
|
||||||
while [ -n "$1" ]; do
|
while [ -n "$1" ]; do
|
||||||
echo $1
|
echo $1
|
||||||
|
@ -49,16 +64,24 @@ while [ -n "$1" ]; do
|
||||||
echo " " This may break functionality.
|
echo " " This may break functionality.
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
if [ "${OS}" = "OpenWRT" ]; then
|
||||||
|
is_installed=$(opkg list-installed $1 | grep $1)
|
||||||
else
|
else
|
||||||
is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
||||||
if [ "${is_installed}" = "install ok installed" ]; then
|
fi
|
||||||
|
if [ "${is_installed}" != "" ]; then
|
||||||
echo " " $1 is installed
|
echo " " $1 is installed
|
||||||
else
|
else
|
||||||
echo " " $1 is not installed. Attempting install.
|
echo " " $1 is not installed. Attempting install.
|
||||||
${install_cmd} $1
|
${install_cmd} $1
|
||||||
sleep 5
|
sleep 5
|
||||||
|
if [ "${OS}" = "OpenWRT" ]; then
|
||||||
|
is_installed=$(opkg list-installed $1 | grep $1)
|
||||||
|
else
|
||||||
is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
||||||
if [ "${is_installed}" = "install ok installed" ]; then
|
fi
|
||||||
|
if [ "${is_installed}" != "" ]; then
|
||||||
echo " " $1 is installed
|
echo " " $1 is installed
|
||||||
elif [ -x "$(command -v $1)" ]; then
|
elif [ -x "$(command -v $1)" ]; then
|
||||||
echo " " $1 is installed
|
echo " " $1 is installed
|
||||||
|
@ -155,18 +178,23 @@ esac
|
||||||
echo "Binary = $dist"
|
echo "Binary = $dist"
|
||||||
|
|
||||||
url="https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist"
|
url="https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist"
|
||||||
|
curl_opts='-nv'
|
||||||
|
if [ "${OS}" = "OpenWRT" ]; then
|
||||||
|
curl_opts='-q'
|
||||||
|
fi
|
||||||
|
|
||||||
if curl --output /dev/null --silent --head --fail "$url"; then
|
if curl --output /dev/null --silent --head --fail "$url"; then
|
||||||
echo "Downloading $dist $VERSION"
|
echo "Downloading $dist $VERSION"
|
||||||
wget -nv -O netclient $url
|
wget $curl_opts -O netclient $url
|
||||||
else
|
else
|
||||||
echo "Downloading $dist latest"
|
echo "Downloading $dist latest"
|
||||||
wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
|
wget $curl_opts -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x netclient
|
chmod +x netclient
|
||||||
|
|
||||||
EXTRA_ARGS=""
|
EXTRA_ARGS=""
|
||||||
if [ "${OS}" = "FreeBSD" ]; then
|
if [ "${OS}" = "FreeBSD" ] || [ "${OS}" = "OpenWRT" ]; then
|
||||||
EXTRA_ARGS="--daemon=off"
|
EXTRA_ARGS="--daemon=off"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -201,6 +229,58 @@ END_OF_FILE
|
||||||
sudo chmod +x /usr/local/etc/rc.d/netclient
|
sudo chmod +x /usr/local/etc/rc.d/netclient
|
||||||
sudo /usr/local/etc/rc.d/netclient enable
|
sudo /usr/local/etc/rc.d/netclient enable
|
||||||
sudo /usr/local/etc/rc.d/netclient start
|
sudo /usr/local/etc/rc.d/netclient start
|
||||||
|
|
||||||
|
elif [ "${OS}" = "OpenWRT" ]; then
|
||||||
|
mv ./netclient /etc/netclient/netclient
|
||||||
|
cat << 'END_OF_FILE' > ./netclient.service.tmp
|
||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
EXTRA_COMMANDS="status"
|
||||||
|
EXTRA_HELP=" status Check service is running"
|
||||||
|
START=99
|
||||||
|
|
||||||
|
LOG_FILE="/tmp/netclient.logs"
|
||||||
|
|
||||||
|
start() {
|
||||||
|
if [ ! -f "${LOG_FILE}" ];then
|
||||||
|
touch "${LOG_FILE}"
|
||||||
|
fi
|
||||||
|
local PID=$(ps|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
|
||||||
|
if [ "${PID}" ];then
|
||||||
|
echo "service is running"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> ${LOG_FILE} 2>&1;sleep 15;\
|
||||||
|
if [ $(ls -l ${LOG_FILE}|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs" && > $LOG_FILE;fi;done &"
|
||||||
|
echo "start"
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
pids=$(ps|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
|
||||||
|
for i in "${pids[@]}"
|
||||||
|
do
|
||||||
|
if [ "${i}" ];then
|
||||||
|
kill "${i}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "stop"
|
||||||
|
}
|
||||||
|
|
||||||
|
status() {
|
||||||
|
local PID=$(ps|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
|
||||||
|
if [ "${PID}" ];then
|
||||||
|
echo -e "netclient[${PID}] is running \n"
|
||||||
|
else
|
||||||
|
echo -e "netclient is not running \n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
END_OF_FILE
|
||||||
|
mv ./netclient.service.tmp /etc/init.d/netclient
|
||||||
|
chmod +x /etc/init.d/netclient
|
||||||
|
/etc/init.d/netclient enable
|
||||||
|
/etc/init.d/netclient start
|
||||||
else
|
else
|
||||||
rm -f netclient
|
rm -f netclient
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ fi
|
||||||
echo "checking dependencies..."
|
echo "checking dependencies..."
|
||||||
|
|
||||||
declare -A osInfo;
|
declare -A osInfo;
|
||||||
osInfo[/etc/debian_version]="apt-get install -y"
|
osInfo[/etc/debian_version]="apt-get install -y"u
|
||||||
osInfo[/etc/alpine-release]="apk --update add"
|
osInfo[/etc/alpine-release]="apk --update add"
|
||||||
osInfo[/etc/centos-release]="yum install -y"
|
osInfo[/etc/centos-release]="yum install -y"
|
||||||
osInfo[/etc/fedora-release]="dnf install -y"
|
osInfo[/etc/fedora-release]="dnf install -y"
|
||||||
|
@ -40,8 +40,20 @@ do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -f /etc/debian_version ]; then
|
||||||
|
apt update
|
||||||
|
elif [ -f /etc/alpine-release ]; then
|
||||||
|
apk update
|
||||||
|
elif [ -f /etc/centos-release ]; then
|
||||||
|
yum update
|
||||||
|
elif [ -f /etc/fedora-release ]; then
|
||||||
|
dnf update
|
||||||
|
fi
|
||||||
|
|
||||||
dependencies=("docker.io" "docker-compose" "wireguard" "jq")
|
dependencies=("docker.io" "docker-compose" "wireguard" "jq")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for dependency in ${dependencies[@]}; do
|
for dependency in ${dependencies[@]}; do
|
||||||
is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
|
is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue