mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 23:36:18 +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
|
@ -399,19 +399,6 @@ func Copy(src, dst string) error {
|
|||
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
|
||||
func RunCmds(commands []string, printerr bool) 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 (
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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 ""){
|
||||
Quit "-token required"
|
||||
}
|
||||
if($token -eq $null -or $token -eq ""){
|
||||
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";
|
||||
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
||||
|
||||
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 {
|
||||
Write-Host "'$software' is installed."
|
||||
}
|
||||
} else {
|
||||
Write-Host "'$software' is installed."
|
||||
}
|
||||
$outpath = "";
|
||||
if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
|
||||
$outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
|
||||
} else {
|
||||
$outpath = "$PSScriptRoot/netclient.exe"
|
||||
Write-Host "'netclient.exe' is NOT installed. installing...";
|
||||
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"
|
||||
$outpath = "";
|
||||
if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
|
||||
$outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
|
||||
} else {
|
||||
$outpath = "$env:userprofile\Downloads\netclient.exe"
|
||||
Write-Host "'netclient.exe' is NOT installed. installing...";
|
||||
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
|
||||
}
|
||||
'''
|
||||
Please add netclient.exe to your path to make it executable from powershell:
|
||||
1. Open "Edit environment variables for your account"
|
||||
2. Double click on "Path"
|
||||
3. On a new line, paste the following: %USERPROFILE%\AppData\Netclient\bin
|
||||
4. Click "Ok"
|
||||
'''
|
||||
}
|
||||
$NetArgs = @("join","-t",$token)
|
||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
||||
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
||||
|
||||
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
|
||||
echo $1
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
is_installed=$(pkg check -d $1 | grep '100%')
|
||||
if [ "${is_installed}" = '100%' ]; then
|
||||
is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
|
||||
if [ "$is_installed" != "" ]; then
|
||||
echo " " $1 is installed
|
||||
else
|
||||
echo " " $1 is not installed. Attempting install.
|
||||
${install_cmd} $1
|
||||
sleep 5
|
||||
is_installed=$(pkg check -d $1 | grep '100%')
|
||||
if [ "${is_installed}" = '100%' ]; then
|
||||
is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
|
||||
if [ "$is_installed" != "" ]; then
|
||||
echo " " $1 is installed
|
||||
elif [ -x "$(command -v $1)" ]; then
|
||||
echo " " $1 is installed
|
||||
|
@ -159,11 +159,12 @@ else
|
|||
echo "Downloading $dist latest"
|
||||
wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
|
||||
fi
|
||||
|
||||
chmod +x netclient
|
||||
|
||||
EXTRA_ARGS=""
|
||||
if [ "${OS}" = "FreeBSD" ]; then
|
||||
EXTRA_ARGS = "--daemon=off"
|
||||
EXTRA_ARGS="--daemon=off"
|
||||
fi
|
||||
|
||||
if [ -z "${NAME}" ]; then
|
||||
|
@ -172,17 +173,15 @@ else
|
|||
./netclient join -t $KEY --name $NAME $EXTRA_ARGS
|
||||
fi
|
||||
|
||||
rm -f netclient
|
||||
|
||||
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
|
||||
|
||||
# PROVIDE: netclient
|
||||
# REQUIRE: LOGIN DAEMON NETWORKING SERVERS FILESYSTEM
|
||||
# BEFORE:
|
||||
# KEYWORD: shutdown
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
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
|
||||
run_rc_command "$1"
|
||||
|
||||
EOF
|
||||
/usr/local/etc/rc.d/netclient enable
|
||||
/usr/local/etc/rc.d/netclient start
|
||||
END_OF_FILE
|
||||
sudo mv ./netclient.service.tmp /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 start
|
||||
else
|
||||
rm -f netclient
|
||||
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…
Reference in a new issue