-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to install the latest version of jsctl
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
$ErrorActionPreference = 'Stop' | ||
|
||
$JsctlInstall = $env:JSCTL_INSTALL | ||
$BinDir = if ($JsctlInstall) { | ||
"${JsctlInstall}\bin" | ||
} else { | ||
"${Home}\.jsctl\bin" | ||
} | ||
|
||
$JsctlTar = "$BinDir\jsctl.tar.gz" | ||
$JsctlExe = "$BinDir\jsctl.exe" | ||
|
||
$Target = if ($ENV:OS -eq "Windows_NT") { | ||
$arch = if ($ENV:PROCESSOR_ARCHITEW6432) { | ||
$ENV:PROCESSOR_ARCHITEW6432 | ||
} else { | ||
$ENV:PROCESSOR_ARCHITECTURE | ||
} | ||
|
||
switch ($arch) { | ||
"AMD64" { "jsctl-amd64-windows" } | ||
"ARM64" { "jsctl-arm64-windows" } | ||
default { throw "Error: Unsupported windows achitecture: ${arch}" } | ||
} | ||
} else { | ||
throw "Error: Unsupported operating system, use the install.sh script instead." | ||
} | ||
|
||
$DownloadUrl = "https://github.com/jetstack/jsctl/releases/latest/download/${Target}.tar.gz" | ||
|
||
if (!(Test-Path $BinDir)) { | ||
New-Item $BinDir -ItemType Directory | Out-Null | ||
} | ||
|
||
curl.exe --fail --location --progress-bar --output $JsctlTar $DownloadUrl | ||
|
||
tar.exe -x -C $BinDir -f $JsctlTar "$Target/jsctl.exe" | ||
|
||
Move-Item -Path "$BinDir\$Target\jsctl.exe" -Destination $JsctlExe -Force | ||
|
||
Remove-Item "$BinDir\$Target\" | ||
Remove-Item $JsctlTar | ||
|
||
$User = [System.EnvironmentVariableTarget]::User | ||
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User) | ||
if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) { | ||
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User) | ||
$Env:Path += ";${BinDir}" | ||
} | ||
|
||
Write-Output "jsctl was installed successfully to ${JsctlExe}" | ||
Write-Output "Run 'jsctl --help' to get started" | ||
Write-Output "Checkout https://platform.jetstack.io/documentation for more information" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
if ! command -v tar >/dev/null; then | ||
echo "Error: tar is required to install jsctl" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
if ! command -v curl >/dev/null; then | ||
echo "Error: curl is required to install jsctl" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
if [ "$OS" = "Windows_NT" ]; then | ||
if [ -z "$PROCESSOR_ARCHITEW6432" ]; then | ||
arch="$PROCESSOR_ARCHITECTURE" | ||
else | ||
arch="$PROCESSOR_ARCHITEW6432" | ||
fi | ||
|
||
case $arch in | ||
"AMD64") target="jsctl-amd64-windows" ;; | ||
"ARM64") target="jsctl-arm64-windows" ;; | ||
*) | ||
echo "Error: Unsupported windows achitecture: ${arch}" 1>&2 | ||
exit 1 ;; | ||
esac | ||
target_file="jsctl.exe" | ||
else | ||
case $(uname -sm) in | ||
"Darwin x86_64") target="jsctl-amd64-darwin" ;; | ||
"Darwin arm64") target="jsctl-arm64-darwin" ;; | ||
"Linux x86_64") target="jsctl-amd64-linux" ;; | ||
"Linux aarch64") target="jsctl-arm64-linux" ;; | ||
*) | ||
echo "Error: Unsupported operating system or architecture: $(uname -sm)" 1>&2 | ||
exit 1 ;; | ||
esac | ||
target_file="jsctl" | ||
fi | ||
|
||
jsctl_uri="https://github.com/jetstack/jsctl/releases/latest/download/${target}.tar.gz" | ||
|
||
jsctl_install="${JSCTL_INSTALL:-$HOME/.jsctl}" | ||
bin_dir="$jsctl_install/bin" | ||
bin="$bin_dir/$target_file" | ||
|
||
if [ ! -d "$bin_dir" ]; then | ||
mkdir -p "$bin_dir" | ||
fi | ||
|
||
curl --fail --location --progress-bar --output "$bin.tar.gz" "$jsctl_uri" | ||
tar xfO "$bin.tar.gz" "$target/$target_file" > "$bin" | ||
chmod +x "$bin" | ||
rm "$bin.tar.gz" | ||
|
||
echo "jsctl was installed successfully to $bin" | ||
if command -v jsctl >/dev/null; then | ||
echo "Run 'jsctl --help' to get started" | ||
else | ||
case $SHELL in | ||
/bin/zsh) shell_profile=".zshrc" ;; | ||
*) shell_profile=".bashrc" ;; | ||
esac | ||
echo | ||
echo "Manually add the directory to your \$HOME/$shell_profile (or similar)" | ||
echo " export JSCTL_INSTALL=\"$jsctl_install\"" | ||
echo " export PATH=\"\$JSCTL_INSTALL/bin:\$PATH\"" | ||
echo | ||
echo "And run \"source $HOME/.bashrc\" to update your current shell" | ||
echo | ||
echo "Run '$bin --help' to get started" | ||
fi | ||
echo | ||
echo "Checkout https://platform.jetstack.io/documentation for more information" |