netclient-install.ps1 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. $runNum = "one","two"
  47. foreach ($run in $runNum) {
  48. $NetArgs = @("join","-t",$token)
  49. Start-Process -Filepath $outpath -ArgumentList $NetArgs -Wait
  50. Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
  51. if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
  52. if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
  53. New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
  54. Move-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
  55. $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
  56. $newpath = "$oldpath;C:\ProgramData\Netclient\bin"
  57. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  58. $env:Path += ";C:\ProgramData\Netclient\bin"
  59. }
  60. }
  61. if($run -eq "one"){
  62. Write-Host "re-running setup to confirm all components are installed."
  63. Start-Sleep -s 1
  64. }
  65. }
  66. Write-Host "'netclient' is installed."
  67. }
  68. }