From 3a3aab73b2f5cff31cc304d8979b8366d0e2e591 Mon Sep 17 00:00:00 2001 From: hndrk <51416554+hendriknielaender@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:20:37 +0200 Subject: [PATCH 1/3] feat: add powershell install script --- install.ps1 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 install.ps1 diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..c55fa98 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,76 @@ +# Define constants and variables +$zvmBaseUrl = "https://github.com/hendriknielaender/zvm/releases/latest/download" +$zvmInstallDir = "$HOME\.zm" +$architecture = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "x86" } +$zvmFileName = "$architecture-windows-zvm.zip" +$zvmExeFileName = "$architecture-windows-zvm.exe" +$zvmZipPath = "$zvmInstallDir\$zvmFileName" +$zvmExePath = "$zvmInstallDir\$zvmExeFileName" +$zvmRenamedExePath = "$zvmInstallDir\zvm.exe" +$zvmUrl = "$zvmBaseUrl/$zvmFileName" + +# Create the installation directory if it doesn't exist +if (-not (Test-Path -Path $zvmInstallDir)) { + Write-Output "Creating installation directory at $zvmInstallDir..." + New-Item -Path $zvmInstallDir -ItemType Directory | Out-Null +} + +# Download the latest release +Write-Output "Downloading zvm from $zvmUrl..." +try { + Invoke-WebRequest -Uri $zvmUrl -OutFile $zvmZipPath + Write-Output "Download complete." +} catch { + Write-Output "Error: Failed to download zvm. Please check your internet connection and URL." + exit 1 +} + +# Unzip the downloaded file +Write-Output "Extracting zvm..." +try { + Expand-Archive -Path $zvmZipPath -DestinationPath $zvmInstallDir -Force + Write-Output "Extraction complete." +} catch { + Write-Output "Error: Failed to extract $zvmFileName. Please check the file and try again." + Remove-Item -Path $zvmZipPath + exit 1 +} + +# Remove the downloaded zip file +Remove-Item -Path $zvmZipPath + +# Check if the existing zvm.exe exists and remove it +if (Test-Path -Path $zvmRenamedExePath) { + Remove-Item -Path $zvmRenamedExePath -Force + Write-Output "Removed existing zvm.exe." +} + +# Rename the new executable +if (Test-Path -Path $zvmExePath) { + Rename-Item -Path $zvmExePath -NewName "zvm.exe" + Write-Output "Renamed $zvmExeFileName to zvm.exe" + + try { + # Set the user environment variable + Write-Output "Setting ZVM_HOME environment variable..." + [System.Environment]::SetEnvironmentVariable("ZVM_HOME", $zvmInstallDir, [System.EnvironmentVariableTarget]::User) + Write-Output "ZVM_HOME has been set to $zvmInstallDir for the current user." + + # Add the zvm directory to the user PATH + $currentPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) + if ($currentPath -notlike "*$zvmInstallDir*") { + $newPath = "$currentPath;$zvmInstallDir" + [System.Environment]::SetEnvironmentVariable("Path", $newPath, [System.EnvironmentVariableTarget]::User) + Write-Output "Added $zvmInstallDir to PATH for the current user." + } else { + Write-Output "$zvmInstallDir is already in the user PATH." + } + } catch { + Write-Output "Error: Unable to set environment variable or update PATH. Please run the script as an administrator." + } +} else { + Write-Output "Error: zvm executable not found after extraction. Please check the downloaded files." + exit 1 +} + +Write-Output "Installation complete. Please restart your terminal or computer to apply changes." From 0cd1aa6d78e32967a229ef5cd626a5e828c68a1f Mon Sep 17 00:00:00 2001 From: hndrk <51416554+hendriknielaender@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:24:34 +0200 Subject: [PATCH 2/3] chore: add windows install script to README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 391c9ed..6a73c83 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,20 @@ brew tap hendriknielaender/zvm brew install zvm ``` +### Windows + +#### PowerShell + +```ps1 +irm https://raw.githubusercontent.com/hendriknielaender/zvm/master/install.ps1 | iex +``` + +#### Command Prompt + +```cmd +powershell -c "irm https://raw.githubusercontent.com/hendriknielaender/zvm/master/install.ps1 | iex" +``` + Now add this line to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file. ```bash From 8ee53f155ca607fd49c745acd9011a0ce85eef3d Mon Sep 17 00:00:00 2001 From: hndrk <51416554+hendriknielaender@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:25:09 +0200 Subject: [PATCH 3/3] chore: update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6a73c83..fd2abba 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ brew tap hendriknielaender/zvm brew install zvm ``` +Now add this line to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file. + +```bash +export PATH="$HOME/.zm/current:$PATH" +``` + ### Windows #### PowerShell @@ -38,12 +44,6 @@ irm https://raw.githubusercontent.com/hendriknielaender/zvm/master/install.ps1 | powershell -c "irm https://raw.githubusercontent.com/hendriknielaender/zvm/master/install.ps1 | iex" ``` -Now add this line to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file. - -```bash -export PATH="$HOME/.zm/current:$PATH" -``` - ## Usage ```bash zvm list # List all available Zig versions