Skip to content

Commit

Permalink
add script to install the latest version of jsctl
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Jan 17, 2023
1 parent ad2d06a commit 5db8928
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 17 deletions.
21 changes: 4 additions & 17 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ builds:
- linux
goarch:
- amd64
- arm
- arm64
- id: "darwin"
env:
Expand Down Expand Up @@ -45,41 +44,29 @@ builds:
- windows
goarch:
- amd64
- "386"
- arm64
archives:
- id: linux
format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
wrap_in_directory: true
builds:
- "linux"
replacements:
arm: armv7l
arm64: aarch64
amd64: x86_64
- id: darwin
format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
wrap_in_directory: true
builds:
- "darwin"
replacements:
arm: armv7l
amd64: x86_64
- id: windows
format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
wrap_in_directory: true
builds:
- "windows"
replacements:
arm64: Arm64
amd64: 64bit
386: 32bit

checksum:
name_template: "{{ .ProjectName }}-{{ .Version }}-SHA256SUMS"
name_template: "{{ .ProjectName }}-SHA256SUMS"
algorithm: sha256
release:
draft: true
Expand Down
55 changes: 55 additions & 0 deletions install.ps1
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"
76 changes: 76 additions & 0 deletions install.sh
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"

0 comments on commit 5db8928

Please sign in to comment.