Update install.sh

This commit is contained in:
colin 2024-04-26 20:40:24 +00:00
parent b4f4c344c0
commit 9178e329b1
1 changed files with 11 additions and 30 deletions

View File

@ -1,16 +1,9 @@
### Installation Script (`install.sh`)
Here's a simple bash script to automate the installation process. This script will detect the architecture, find the appropriate binary in the `dist` directory, and install it to `/usr/local/bin`.
```bash
#!/bin/bash
# Define the installation directory and binary name
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="haste-it"
BASE_URL="https://git.nixc.us/Nixius/haste-it/raw/branch/main/dist"
# Define supported architectures and corresponding binaries
declare -A binaries
binaries["linux/amd64"]="haste-it_linux_amd64"
binaries["linux/arm64"]="haste-it_linux_arm64"
@ -18,42 +11,30 @@ binaries["linux/arm/v7"]="haste-it_linux_arm"
binaries["darwin/amd64"]="haste-it_darwin_amd64"
binaries["darwin/arm64"]="haste-it_darwin_arm64"
# Detect the OS and architecture
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case $ARCH in
x86_64)
ARCH="amd64"
;;
arm64)
ARCH="arm64"
;;
aarch64)
ARCH="arm64"
;;
arm*)
ARCH="arm/v7"
;;
x86_64) ARCH="amd64" ;;
arm64 | aarch64) ARCH="arm64" ;;
arm*) ARCH="arm/v7" ;;
esac
# Construct the key for finding the binary
KEY="${OS}/${ARCH}"
# Check if the binary exists for this architecture
if [[ -z "${binaries[$KEY]}" ]]; then
echo "No pre-built binary for your system architecture ($KEY)."
exit 1
fi
# Install the binary
BINARY_PATH="dist/${binaries[$KEY]}"
if [[ -f "$BINARY_PATH" ]]; then
sudo cp "$BINARY_PATH" "$INSTALL_DIR/$BINARY_NAME"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
BINARY_URL="${BASE_URL}/${binaries[$KEY]}"
echo "Downloading and installing $BINARY_NAME from $BINARY_URL..."
sudo curl -sSL "$BINARY_URL" -o "${INSTALL_DIR}/${BINARY_NAME}"
if [[ $? -eq 0 ]]; then
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
echo "Installed $BINARY_NAME to $INSTALL_DIR"
else
echo "Binary file not found: $BINARY_PATH"
echo "Failed to download or install $BINARY_NAME."
exit 1
fi