mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-12 16:14:37 +08:00
Merge pull request #466 from gravitl/feature_v0.9.0_cleanup
Feature v0.9.0 cleanup
This commit is contained in:
commit
fef3f5e206
8 changed files with 194 additions and 93 deletions
|
@ -399,19 +399,6 @@ func Copy(src, dst string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCmd - runs a local command
|
|
||||||
func RunCmd(command string, printerr bool) (string, error) {
|
|
||||||
args := strings.Fields(command)
|
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
|
||||||
cmd.Wait()
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
if err != nil && printerr {
|
|
||||||
log.Println("error running command:", command)
|
|
||||||
log.Println(strings.TrimSuffix(string(out), "\n"))
|
|
||||||
}
|
|
||||||
return string(out), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunsCmds - runs cmds
|
// RunsCmds - runs cmds
|
||||||
func RunCmds(commands []string, printerr bool) error {
|
func RunCmds(commands []string, printerr bool) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
22
netclient/ncutils/netclientutils_darwin.go
Normal file
22
netclient/ncutils/netclientutils_darwin.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package ncutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunCmd - runs a local command
|
||||||
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
|
args := strings.Fields(command)
|
||||||
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
cmd.Wait()
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil && printerr {
|
||||||
|
log.Println("error running command:", command)
|
||||||
|
log.Println(strings.TrimSuffix(string(out), "\n"))
|
||||||
|
}
|
||||||
|
return string(out), err
|
||||||
|
}
|
||||||
|
turn string(out), err
|
||||||
|
}
|
|
@ -2,28 +2,11 @@ package ncutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/credentials"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Runs Commands for FreeBSD
|
// Runs Commands for FreeBSD
|
||||||
|
|
20
netclient/ncutils/netclientutils_linux.go
Normal file
20
netclient/ncutils/netclientutils_linux.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package ncutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunCmd - runs a local command
|
||||||
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
|
args := strings.Fields(command)
|
||||||
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
cmd.Wait()
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil && printerr {
|
||||||
|
log.Println("error running command:", command)
|
||||||
|
log.Println(strings.TrimSuffix(string(out), "\n"))
|
||||||
|
}
|
||||||
|
return string(out), err
|
||||||
|
}
|
40
netclient/ncutils/netclientutils_windows.go
Normal file
40
netclient/ncutils/netclientutils_windows.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package ncutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunCmd - runs a local command
|
||||||
|
func RunCmd(command string, printerr bool) (string, error) {
|
||||||
|
args := strings.Fields(command)
|
||||||
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
cmd.Wait()
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil && printerr {
|
||||||
|
log.Println("error running command:", command)
|
||||||
|
log.Println(strings.TrimSuffix(string(out), "\n"))
|
||||||
|
}
|
||||||
|
return string(out), err
|
||||||
|
}
|
|
@ -1,62 +1,72 @@
|
||||||
param ($version='latest', $token)
|
new-module -name netclient-install -scriptblock {
|
||||||
|
function Quit {
|
||||||
|
param(
|
||||||
|
$Text
|
||||||
|
)
|
||||||
|
Write-Host "Exiting: " $Text
|
||||||
|
Break Script
|
||||||
|
}
|
||||||
|
Function Netclient-Install() {
|
||||||
|
param ($version='latest', $token)
|
||||||
|
|
||||||
function Quit {
|
|
||||||
param(
|
|
||||||
$Text
|
|
||||||
)
|
|
||||||
Write-Host "Exiting: " $Text
|
|
||||||
Break Script
|
|
||||||
}
|
|
||||||
|
|
||||||
if($token -eq $null -or $token -eq ""){
|
if($token -eq $null -or $token -eq ""){
|
||||||
Quit "-token required"
|
Quit "-token required"
|
||||||
}
|
}
|
||||||
|
|
||||||
$software = "WireGuard";
|
|
||||||
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
|
||||||
|
|
||||||
If(-Not $installed) {
|
|
||||||
Write-Host "'$software' is NOT installed. installing...";
|
|
||||||
$url = "https://download.wireguard.com/windows-client/wireguard-installer.exe"
|
|
||||||
$outpath = "$PSScriptRoot/wireguard-installer.exe"
|
|
||||||
Invoke-WebRequest -Uri $url -OutFile $outpath
|
|
||||||
$args = @("Comma","Separated","Arguments")
|
|
||||||
Start-Process -Filepath "$PSScriptRoot/wireguard-installer.exe" -ArgumentList $args
|
|
||||||
$software = "WireGuard";
|
$software = "WireGuard";
|
||||||
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
||||||
|
|
||||||
If(-Not $installed) {
|
If(-Not $installed) {
|
||||||
Quit "Could not install WireGuard"
|
Write-Host "'$software' is NOT installed. installing...";
|
||||||
|
$url = "https://download.wireguard.com/windows-client/wireguard-installer.exe"
|
||||||
|
$outpath = "$env:userprofile\Downloads\wireguard-installer.exe"
|
||||||
|
Invoke-WebRequest -Uri $url -OutFile $outpath
|
||||||
|
$args = @("Comma","Separated","Arguments")
|
||||||
|
Start-Process -Filepath "$env:userprofile\Downloads\wireguard-installer.exe" -ArgumentList $args
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
$software = "WireGuard";
|
||||||
|
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
||||||
|
If(-Not $installed) {
|
||||||
|
Quit "Could not install WireGuard"
|
||||||
|
} else {
|
||||||
|
Write-Host "'$software' is installed."
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "'$software' is installed."
|
Write-Host "'$software' is installed."
|
||||||
}
|
}
|
||||||
} else {
|
$outpath = "";
|
||||||
Write-Host "'$software' is installed."
|
if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
|
||||||
}
|
$outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
|
||||||
$outpath = "";
|
} else {
|
||||||
if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
|
$outpath = "$env:userprofile\Downloads\netclient.exe"
|
||||||
$outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
|
Write-Host "'netclient.exe' is NOT installed. installing...";
|
||||||
} else {
|
Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
|
||||||
$outpath = "$PSScriptRoot/netclient.exe"
|
$url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
|
||||||
Write-Host "'netclient.exe' is NOT installed. installing...";
|
Invoke-WebRequest -Uri $url -OutFile $outpath
|
||||||
Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
|
|
||||||
$url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
|
|
||||||
Invoke-WebRequest -Uri $url -OutFile $outpath
|
|
||||||
}
|
|
||||||
$NetArgs = @("join","-t",$token)
|
|
||||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
|
||||||
|
|
||||||
if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
|
|
||||||
if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
|
|
||||||
New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
|
|
||||||
Move-Item -Path "$PSScriptRoot/netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
|
|
||||||
}
|
}
|
||||||
'''
|
$NetArgs = @("join","-t",$token)
|
||||||
Please add netclient.exe to your path to make it executable from powershell:
|
Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
||||||
1. Open "Edit environment variables for your account"
|
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
||||||
2. Double click on "Path"
|
|
||||||
3. On a new line, paste the following: %USERPROFILE%\AppData\Netclient\bin
|
|
||||||
4. Click "Ok"
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "'netclient' is installed."
|
if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
|
||||||
|
if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
|
||||||
|
New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
|
||||||
|
Move-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
|
||||||
|
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
|
||||||
|
$newpath = "$oldpath;C:\ProgramData\Netclient\bin"
|
||||||
|
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
|
||||||
|
$env:Path += ";C:\ProgramData\Netclient\bin"
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
Please add netclient.exe to your path to make it permanently executable from powershell:
|
||||||
|
1. Open "Edit environment variables for your account"
|
||||||
|
2. Double click on "Path"
|
||||||
|
3. On a new line, add the following: C:\ProgramData\Netclient\bin
|
||||||
|
4. Click "Ok"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "'netclient' is installed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -32,15 +32,15 @@ set -- $dependencies
|
||||||
while [ -n "$1" ]; do
|
while [ -n "$1" ]; do
|
||||||
echo $1
|
echo $1
|
||||||
if [ "${OS}" = "FreeBSD" ]; then
|
if [ "${OS}" = "FreeBSD" ]; then
|
||||||
is_installed=$(pkg check -d $1 | grep '100%')
|
is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
|
||||||
if [ "${is_installed}" = '100%' ]; then
|
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
|
||||||
is_installed=$(pkg check -d $1 | grep '100%')
|
is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
|
||||||
if [ "${is_installed}" = '100%' ]; then
|
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
|
||||||
|
@ -159,11 +159,12 @@ else
|
||||||
echo "Downloading $dist latest"
|
echo "Downloading $dist latest"
|
||||||
wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
|
wget -nv -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" ]; then
|
||||||
EXTRA_ARGS = "--daemon=off"
|
EXTRA_ARGS="--daemon=off"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${NAME}" ]; then
|
if [ -z "${NAME}" ]; then
|
||||||
|
@ -172,17 +173,15 @@ else
|
||||||
./netclient join -t $KEY --name $NAME $EXTRA_ARGS
|
./netclient join -t $KEY --name $NAME $EXTRA_ARGS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f netclient
|
|
||||||
|
|
||||||
if [ "${OS}" = "FreeBSD" ]; then
|
if [ "${OS}" = "FreeBSD" ]; then
|
||||||
tee /usr/local/etc/rc.d/netclient <<'EOF' >/dev/null
|
mv ./netclient /etc/netclient/netclient
|
||||||
|
cat << 'END_OF_FILE' > ./netclient.service.tmp
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# PROVIDE: netclient
|
# PROVIDE: netclient
|
||||||
# REQUIRE: LOGIN DAEMON NETWORKING SERVERS FILESYSTEM
|
# REQUIRE: LOGIN DAEMON NETWORKING SERVERS FILESYSTEM
|
||||||
# BEFORE:
|
# BEFORE:
|
||||||
# KEYWORD: shutdown
|
# KEYWORD: shutdown
|
||||||
|
|
||||||
. /etc/rc.subr
|
. /etc/rc.subr
|
||||||
|
|
||||||
name="netclient"
|
name="netclient"
|
||||||
|
@ -194,7 +193,11 @@ command_args="-c -f -P ${pidfile} -R 10 -t "Netclient" -u root -o /etc/netclient
|
||||||
load_rc_config $name
|
load_rc_config $name
|
||||||
run_rc_command "$1"
|
run_rc_command "$1"
|
||||||
|
|
||||||
EOF
|
END_OF_FILE
|
||||||
/usr/local/etc/rc.d/netclient enable
|
sudo mv ./netclient.service.tmp /usr/local/etc/rc.d/netclient
|
||||||
/usr/local/etc/rc.d/netclient start
|
sudo chmod +x /usr/local/etc/rc.d/netclient
|
||||||
|
sudo /usr/local/etc/rc.d/netclient enable
|
||||||
|
sudo /usr/local/etc/rc.d/netclient start
|
||||||
|
else
|
||||||
|
rm -f netclient
|
||||||
fi
|
fi
|
||||||
|
|
36
scripts/netmaker-server.sh
Normal file
36
scripts/netmaker-server.sh
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
mkdir -p /etc/netmaker/config/environments
|
||||||
|
wget -O /etc/netmaker/netmaker https://github.com/gravitl/netmaker/releases/download/latest/netmaker
|
||||||
|
chmod +x /etc/netmaker/netmaker
|
||||||
|
|
||||||
|
cat >/etc/netmaker/config/environments/dev.yaml<<EOL
|
||||||
|
server:
|
||||||
|
host:
|
||||||
|
apiport: "8081"
|
||||||
|
grpcport: "50051"
|
||||||
|
masterkey: "secretkey"
|
||||||
|
allowedorigin: "*"
|
||||||
|
restbackend: true
|
||||||
|
agentbackend: true
|
||||||
|
dnsmode: "on"
|
||||||
|
EOL
|
||||||
|
|
||||||
|
cat >/etc/systemd/system/netmaker.service<<EOL
|
||||||
|
[Unit]
|
||||||
|
Description=Netmaker Server
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
WorkingDirectory=/etc/netmaker
|
||||||
|
ExecStart=/etc/netmaker/netmaker
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOL
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl start netmaker.service
|
Loading…
Add table
Reference in a new issue