netclient-install.ps1 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. new-module -name netclient-install -scriptblock {
  2. $ErrorActionPreference = "Stop"
  3. function Quit {
  4. param(
  5. $Text
  6. )
  7. Write-Host "Exiting: " $Text
  8. Break Script
  9. }
  10. Function Netclient-Install() {
  11. param ($version='latest', $token)
  12. if($token -eq $null -or $token -eq ""){
  13. Quit "-token required"
  14. }
  15. $software = "WireGuard";
  16. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  17. If(-Not $installed) {
  18. Write-Host "'$software' is NOT installed. installing...";
  19. $url = "https://download.wireguard.com/windows-client/wireguard-installer.exe"
  20. $outpath = "$env:userprofile\Downloads\wireguard-installer.exe"
  21. Invoke-WebRequest -Uri $url -OutFile $outpath
  22. $args = @("Comma","Separated","Arguments")
  23. Start-Process -Filepath "$env:userprofile\Downloads\wireguard-installer.exe" -ArgumentList $args -Wait
  24. $software = "WireGuard";
  25. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  26. If(-Not $installed) {
  27. Quit "Could not install WireGuard"
  28. } else {
  29. Write-Host "'$software' is installed."
  30. }
  31. } else {
  32. Write-Host "'$software' is installed."
  33. }
  34. $outpath = "";
  35. if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
  36. $outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
  37. } else {
  38. $outpath = "$env:userprofile\Downloads\netclient.exe"
  39. Write-Host "'netclient.exe' is NOT installed. installing...";
  40. Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
  41. $url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
  42. Invoke-WebRequest -Uri $url -OutFile $outpath
  43. $loc = Get-Location
  44. Copy-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "$loc\netclient.exe"
  45. }
  46. echo "env: $env:userprofile"
  47. echo "outpath: $outpath"
  48. $NetArgs = @("join","-t",$token)
  49. echo "netargs: $NetArgs"
  50. Start-Process -Filepath $outpath -ArgumentList $NetArgs -Wait
  51. Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
  52. if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
  53. if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
  54. New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
  55. Move-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
  56. $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
  57. $newpath = "$oldpath;C:\ProgramData\Netclient\bin"
  58. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  59. $env:Path += ";C:\ProgramData\Netclient\bin"
  60. }
  61. '''
  62. Please add netclient.exe to your path to make it permanently executable from powershell:
  63. 1. Open "Edit environment variables for your account"
  64. 2. Double click on "Path"
  65. 3. On a new line, add the following: C:\ProgramData\Netclient\bin
  66. 4. Click "Ok"
  67. '''
  68. }
  69. Write-Host "'netclient' is installed."
  70. }
  71. }