netclient-install.ps1 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. param ($version='latest', $token)
  2. function Quit {
  3. param(
  4. $Text
  5. )
  6. Write-Host "Exiting: " $Text
  7. Break Script
  8. }
  9. if($token -eq $null -or $token -eq ""){
  10. Quit "-token required"
  11. }
  12. $software = "WireGuard";
  13. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  14. If(-Not $installed) {
  15. Write-Host "'$software' is NOT installed. installing...";
  16. $url = "https://download.wireguard.com/windows-client/wireguard-installer.exe"
  17. $outpath = "$PSScriptRoot/wireguard-installer.exe"
  18. Invoke-WebRequest -Uri $url -OutFile $outpath
  19. $args = @("Comma","Separated","Arguments")
  20. Start-Process -Filepath "$PSScriptRoot/wireguard-installer.exe" -ArgumentList $args
  21. $software = "WireGuard";
  22. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  23. If(-Not $installed) {
  24. Quit "Could not install WireGuard"
  25. } else {
  26. Write-Host "'$software' is installed."
  27. }
  28. } else {
  29. Write-Host "'$software' is installed."
  30. }
  31. $outpath = "";
  32. if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
  33. $outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
  34. } else {
  35. $outpath = "$PSScriptRoot/netclient.exe"
  36. Write-Host "'netclient.exe' is NOT installed. installing...";
  37. Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
  38. $url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
  39. Invoke-WebRequest -Uri $url -OutFile $outpath
  40. }
  41. $NetArgs = @("join","-t",$token)
  42. Start-Process -Filepath $outpath -ArgumentList $NetArgs
  43. if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
  44. if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
  45. New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
  46. Move-Item -Path "$PSScriptRoot/netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
  47. }
  48. '''
  49. Please add netclient.exe to your path to make it executable from powershell:
  50. 1. Open "Edit environment variables for your account"
  51. 2. Double click on "Path"
  52. 3. On a new line, paste the following: %USERPROFILE%\AppData\Netclient\bin
  53. 4. Click "Ok"
  54. '''
  55. }
  56. Write-Host "'netclient' is installed."