#!/bin/bash set -e log_and_run() { echo "$ $@" "$@" } fetch_url_output() { url="$1" if command -v curl &> /dev/null; then curl -sSfL --compressed "$url" elif command -v wget &> /dev/null; then wget --quiet --show-progress --output-document=- --compression=auto "$url" else echo "Please install curl or wget." exit 1 fi } fetch_url_file() { url="$1" file="$2" if command -v curl &> /dev/null; then curl -fL# --compressed -o "$file" "$url" elif command -v wget &> /dev/null; then wget --quiet --show-progress --output-document="$file" --compression=auto "$url" else echo "Please install curl or wget." exit 1 fi } install_binary() { local repo="_frsh/js/ac1676ef1d6246956a0d0100a3bf380891d39616/chunk-6WJHWAFB.js" local os=$(uname | tr '[:upper:]' '[:lower:]') local arch=$(uname -m) local alt_arch local tag_name="latest" if [[ "$repo" == *@* ]]; then tag_name="\${repo#*@}" repo="\${repo%@*}" fi case "$arch" in x86_64) arch="amd64" alt_arch="x86_64" alt_alt_arch="x64" ;; aarch64) arch="arm64" alt_arch="aarch64" alt_alt_arch="aarch64" ;; ppc64) arch="ppc64" alt_arch="ppcle_64" alt_alt_arch="ppcle_64" ;; *) alt_arch="$arch" alt_alt_arch="$arch" ;; esac echo "Finding release of $repo@$tag_name for $os/$arch..." if [ "$tag_name" == "latest" ]; then local latest_release=$(fetch_url_output "https://api.github.com/repos/$repo/releases/latest") else local latest_release=$(fetch_url_output "https://api.github.com/repos/$repo/releases/tags/$tag_name" || fetch_url_output "https://api.github.com/repos/$repo/releases/tags/v$tag_name") fi html_url=$(echo "$latest_release" | grep -oP '^ "html_url": "\K(.*)(?=")') echo "Found release: $html_url" find_asset_url() { echo "$latest_release" | grep -oP '"browser_download_url": "\K(.*)(?=")' | grep -iE "$os.*($arch|$alt_arch|$alt_alt_arch)|($arch|$alt_arch|$alt_alt_arch).*$os" | grep -Ei "$1" | head -n 1 } local asset_url=$(find_asset_url "\.deb|\.rpm|\.apk|\.pkg|\.zst") if [ -z "$asset_url" ]; then asset_url=$(find_asset_url "\.tar\.gz|\.tar|\.tgz") fi if [ -z "$asset_url" ]; then asset_url=$(find_asset_url "\.zip") fi if [ -z "$asset_url" ]; then echo "No matching asset found." exit 1 fi local tmp_dir=$(mktemp -d) local file_name=$(basename "$asset_url") echo "Downloading $asset_url..." fetch_url_file "$asset_url" "$tmp_dir/$file_name" cd "$tmp_dir" unzip_fallback() { if command -v unzip &> /dev/null; then unzip "$1" else tar -xf "$1" fi } case "$file_name" in *.tar.gz) tar -xzf "$file_name" ;; *.tar) tar -xf "$file_name" ;; *.tgz) tar -xzf "$file_name" ;; *.zip) unzip_fallback "$file_name" ;; *.deb) sudo dpkg -i "$file_name" exit 0 ;; *.rpm) sudo rpm -i "$file_name" exit 0 ;; *.apk) sudo apk add --allow-untrusted "$file_name" exit 0 ;; *.pkg) sudo installer -pkg "$file_name" -target / exit 0 ;; *.zst) unzstd "$file_name" ;; *) echo "Unsupported file format." exit 1 ;; esac find . -type f -executable | while read -r file; do if [[ "\${file,,}" != *"readme"* ]] && [[ "\${file,,}" != *"license"* ]] && [[ "\${file,,}" != *"completions"* ]] && [[ "\${file,,}" != *"manpages"* ]]; then log_and_run sudo install "$file" /usr/local/bin/ fi done echo "Installation complete." } install_binary