mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-17 06:11:21 +08:00
updating windows script
This commit is contained in:
@@ -1,27 +1,30 @@
|
||||
param ($version='latest', $token)
|
||||
|
||||
function Quit {
|
||||
new-module -name netclient-install -scriptblock {
|
||||
function Quit {
|
||||
param(
|
||||
$Text
|
||||
)
|
||||
Write-Host "Exiting: " $Text
|
||||
Break Script
|
||||
}
|
||||
}
|
||||
Function Netclient-Install() {
|
||||
param ($version='latest', $token)
|
||||
|
||||
if($token -eq $null -or $token -eq ""){
|
||||
|
||||
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
|
||||
$software = "WireGuard";
|
||||
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
|
||||
|
||||
If(-Not $installed) {
|
||||
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"
|
||||
$outpath = "$env:userprofile\Downloads\wireguard-installer.exe"
|
||||
Invoke-WebRequest -Uri $url -OutFile $outpath
|
||||
$args = @("Comma","Separated","Arguments")
|
||||
Start-Process -Filepath "$PSScriptRoot/wireguard-installer.exe" -ArgumentList $args
|
||||
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) {
|
||||
@@ -29,34 +32,41 @@ If(-Not $installed) {
|
||||
} else {
|
||||
Write-Host "'$software' is installed."
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
Write-Host "'$software' is installed."
|
||||
}
|
||||
$outpath = "";
|
||||
if (Test-Path -Path "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 = "$PSScriptRoot/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
|
||||
}
|
||||
$NetArgs = @("join","-t",$token)
|
||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
||||
}
|
||||
$NetArgs = @("join","-t",$token)
|
||||
Start-Process -Filepath $outpath -ArgumentList $NetArgs
|
||||
Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
|
||||
|
||||
if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
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"
|
||||
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 executable from powershell:
|
||||
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, paste the following: %USERPROFILE%\AppData\Netclient\bin
|
||||
3. On a new line, add the following: C:\ProgramData\Netclient\bin
|
||||
4. Click "Ok"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "'netclient' is installed."
|
||||
Write-Host "'netclient' is installed."
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user