Skip to content

Instantly share code, notes, and snippets.

@Alex4386
Last active February 24, 2025 09:30
Show Gist options
  • Save Alex4386/45fb21bab398f96018a30e841ed2bc1f to your computer and use it in GitHub Desktop.
Save Alex4386/45fb21bab398f96018a30e841ed2bc1f to your computer and use it in GitHub Desktop.
Shell script for downloading static binaries
#!/bin/bash
# Base URL for the repository
BASE_URL="https://github.com/polaco1782/linux-static-binaries/raw/refs/heads/master"
# Check if ~/.local/bin is in the PATH environment variable
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo "Error: ~/.local/bin is not in your PATH. Please add it by running:"
echo "export PATH=\$HOME/.local/bin:\$PATH"
exit 1
fi
# Detect system architecture
ARCH=$(uname -m)
case $ARCH in
x86_64|i686)
ARCH_FOLDER="x86-i686"
;;
armv8*|aarch64)
ARCH_FOLDER="armv8-aarch64"
;;
armv7l*)
ARCH_FOLDER="armv7l-eabihf"
;;
*)
echo "Error: Unsupported architecture: $ARCH"
exit 1
;;
esac
# Get the argument
if [ -z "$1" ]; then
echo "Error: No argument provided. Usage: $0 <command>"
exit 1
fi
COMMAND=$1
# Define the destination directory and file
DEST_DIR="$HOME/.local/bin"
DEST_FILE="$DEST_DIR/$COMMAND"
# Check if wget or curl is available
if command -v wget > /dev/null 2>&1; then
DOWNLOAD_CMD="wget -O $DEST_FILE"
elif command -v curl > /dev/null 2>&1; then
DOWNLOAD_CMD="curl -L -o $DEST_FILE"
else
echo "Error: Neither wget nor curl is installed. Please install one of them."
exit 1
fi
# Create the destination directory if it doesn't exist
mkdir -p "$DEST_DIR"
# Download the file
URL="$BASE_URL/$ARCH_FOLDER/$COMMAND"
echo "Downloading $COMMAND for $ARCH..."
# Do overrides on some applications
case "$COMMAND" in
neofetch)
URL="https://github.com/dylanaraps/neofetch/raw/refs/heads/master/neofetch"
;;
esac
$DOWNLOAD_CMD "$URL"
if [ $? -ne 0 ]; then
echo "Error: Failed to download $URL"
rm $DEST_FILE
exit 1
fi
# Make the file executable
chmod +x "$DEST_FILE"
if [ $? -eq 0 ]; then
echo "$COMMAND installed successfully to $DEST_FILE"
else
echo "Error: Failed to set executable permissions on $DEST_FILE"
exit 1
fi
@Alex4386
Copy link
Author

Alex4386 commented Dec 13, 2024

Start setup:

mkdir -p ~/.local/bin && curl -L https://gist.github.com/Alex4386/45fb21bab398f96018a30e841ed2bc1f/raw/stat-pkg.sh | tee ~/.local/bin/stat-pkg.sh &&  chmod +x ~/.local/bin/stat-pkg.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment