netclient-install.ps1 3.9 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. # $env:Path += (";" + $env:ProgramFiles + "\WireGuard")
  30. Write-Host "'$software' is installed."
  31. }
  32. } else {
  33. Write-Host "'$software' is installed."
  34. }
  35. $outpath = "";
  36. if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
  37. $outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
  38. } else {
  39. $outpath = "$env:userprofile\Downloads\netclient.exe"
  40. Write-Host "'netclient.exe' is NOT installed. installing...";
  41. Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
  42. $url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
  43. Invoke-WebRequest -Uri $url -OutFile $outpath
  44. $loc = Get-Location
  45. Copy-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "$loc\netclient.exe"
  46. }
  47. $runNum = "one"
  48. foreach ($run in $runNum) {
  49. $NetArgs = @("join","-t",$token)
  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. #if($run -eq "one"){
  63. # Write-Host "re-running setup to confirm all components are installed."
  64. # Start-Sleep -s 1
  65. #}
  66. }
  67. Start-Sleep -s 5
  68. Write-Host "'netclient' is installed."
  69. }
  70. }