mirror of
https://github.com/gravitl/netmaker.git
synced 2026-02-04 02:00:21 +08:00
cleaning up powershell
This commit is contained in:
parent
d4001f6a4d
commit
638cb0ec04
4 changed files with 19 additions and 31 deletions
|
|
@ -243,7 +243,9 @@ func GetNetworkIPMask(networkstring string) (string, string, error) {
|
|||
return "", "", err
|
||||
}
|
||||
ipstring := ip.String()
|
||||
maskstring := ipnet.Mask.String()
|
||||
mask := ipnet.Mask
|
||||
maskstring := fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
|
||||
//maskstring := ipnet.Mask.String()
|
||||
return ipstring, maskstring, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,7 @@
|
|||
package wireguard
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
|
@ -221,11 +222,20 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
var output string
|
||||
starttime := time.Now()
|
||||
ncutils.PrintLog("waiting for interface...", 1)
|
||||
for !strings.Contains(output, ifacename) && !(time.Now().After(starttime.Add(time.Minute))) {
|
||||
for !strings.Contains(output, ifacename) && !(time.Now().After(starttime.Add(time.Duration(10) * time.Second))) {
|
||||
output, _ = ncutils.RunCmd("wg", false)
|
||||
time.Sleep(time.Second >> 1)
|
||||
err = ApplyConf(confPath)
|
||||
}
|
||||
if !strings.Contains(output, ifacename) {
|
||||
return errors.New("could not create wg interface for " + ifacename)
|
||||
}
|
||||
ip, mask, err := ncutils.GetNetworkIPMask(nodecfg.NetworkSettings.AddressRange)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
return err
|
||||
}
|
||||
_, _ = ncutils.RunCmd("route add "+ip+" mask "+mask+" "+node.Address, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -290,13 +300,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
}
|
||||
|
||||
//extra network route setting required for freebsd and windows
|
||||
if ncutils.IsWindows() {
|
||||
ip, mask, err := ncutils.GetNetworkIPMask(nodecfg.NetworkSettings.AddressRange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = ncutils.RunCmd("route add "+ip+" mask "+mask+" "+node.Address, true)
|
||||
} else if ncutils.IsFreeBSD() {
|
||||
if ncutils.IsFreeBSD() {
|
||||
_, _ = ncutils.RunCmd("route add -net "+nodecfg.NetworkSettings.AddressRange+" -interface "+ifacename, true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,14 +25,7 @@ new-module -name netclient-install -scriptblock {
|
|||
$outpath = "$env:userprofile\Downloads\wireguard-installer.exe"
|
||||
Invoke-WebRequest -Uri $url -OutFile $outpath
|
||||
$args = @("Comma","Separated","Arguments")
|
||||
$procWG = Start-Process -Filepath "$env:userprofile\Downloads\wireguard-installer.exe" -ArgumentList $args
|
||||
if ($procWG -eq $null) {
|
||||
Start-Sleep -Seconds 5
|
||||
} else {
|
||||
$procWG.WaitForExit()
|
||||
}
|
||||
$procWG.WaitForExit()
|
||||
Start-Sleep -Seconds 5
|
||||
Start-Process -Filepath "$env:userprofile\Downloads\wireguard-installer.exe" -ArgumentList $args -Wait
|
||||
$software = "WireGuard";
|
||||
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
||||
If(-Not $installed) {
|
||||
|
|
@ -52,14 +45,11 @@ new-module -name netclient-install -scriptblock {
|
|||
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
|
||||
$loc = Get-Location
|
||||
Copy-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "$loc\netclient.exe"
|
||||
}
|
||||
$NetArgs = @("join","-t",$token)
|
||||
$procNC = Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
||||
if ($procNC -eq $null) {
|
||||
Start-Sleep -Seconds 5
|
||||
} else {
|
||||
$procNC.WaitForExit()
|
||||
}
|
||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs -Wait
|
||||
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
||||
|
||||
if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
|
|
@ -71,15 +61,7 @@ new-module -name netclient-install -scriptblock {
|
|||
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."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue