From 85fd0060bf11bfefac71c73359abb04a2ec1e63c Mon Sep 17 00:00:00 2001 From: andreszorro Date: Thu, 7 Mar 2024 19:19:30 +0000 Subject: [PATCH] Updated install script Signed-off-by: GitHub Actions Bot <41898282+github-actions[bot]@users.noreply.github.com> --- assets/install.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 assets/install.sh diff --git a/assets/install.sh b/assets/install.sh new file mode 100755 index 0000000..f3a2733 --- /dev/null +++ b/assets/install.sh @@ -0,0 +1,82 @@ +#!/bin/sh +set -eu + +info() { + echo "$@" >&2 +} + +error() { + echo "$@" >&2 + exit 1 +} + +get_os() { + os="$(uname -s)" + if [ "$os" = Darwin ]; then + echo "macos" + elif [ "$os" = Linux ]; then + echo "linux" + else + error "unsupported OS: $os" + fi +} + +get_arch() { + arch="$(uname -m)" + if [ "$arch" = x86_64 ]; then + echo "x64" + elif [ "$arch" = aarch64 ] || [ "$arch" = arm64 ]; then + echo "arm64" + else + error "unsupported architecture: $arch" + fi +} + +download_file() { + url="$1" + filename="$(basename "$url")" + cache_dir="$(mktemp -d)" + file="$cache_dir/$filename" + + info "Scaffoldizr: installing scfz..." + + if command -v curl >/dev/null 2>&1; then + curl -#fLo "$file" "$url" + else + if command -v wget >/dev/null 2>&1; then + stderr=$(mktemp) + wget -O "$file" "$url" >"$stderr" 2>&1 || error "wget failed: $(cat "$stderr")" + else + error "scfz standalone install requires curl or wget but neither is installed. Aborting." + fi + fi + + echo "$file" +} + +install_tool() { + # download the tarball + version="v0.2.0-beta-2" + repo="arch-formula/scaffoldizr" + os="$(get_os)" + arch="$(get_arch)" + install_path="${SCFZ_INSTALL_PATH:-$HOME/.local/bin/scfz}" + install_dir="$(dirname "$install_path")" + tarball_url="https://github.com/${repo}/releases/download/${version}/scfz-${version}-${os}-${arch}.tar.gz" + + cache_file=$(download_file "$tarball_url") + + # TODO: Validate checksum + # cd "$(dirname "$cache_file")" && get_checksum | "$(shasum_bin)" -c >/dev/null + + # extract tarball + mkdir -p "$install_dir" + rm -rf "$install_path" + cd "$(mktemp -d)" + tar -xzf "$cache_file" + mv "${os}-${arch}/scfz" "$install_path" + info "Scaffoldizr: installed successfully to $install_path" + info "Make sure that \"$install_dir\" is in your \$PATH" +} + +install_tool \ No newline at end of file