Created
February 2, 2026 14:48
-
-
Save R0rt1z2/217055f0c5d73d3079c5c83c9145d161 to your computer and use it in GitHub Desktop.
Script to automatically download & setup ARM toolchains (for payload development)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| TOOLCHAIN_DIR="$HOME/toolchains" | |
| ARM32_URL="https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf.tar.xz" | |
| ARM64_URL="https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu.tar.xz" | |
| ARM32_DIR="arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf" | |
| ARM64_DIR="arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu" | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' | |
| info() { echo -e "${BLUE}[*]${NC} $*"; } | |
| success() { echo -e "${GREEN}[+]${NC} $*"; } | |
| warn() { echo -e "${YELLOW}[!]${NC} $*"; } | |
| error() { echo -e "${RED}[-]${NC} $*" >&2; exit 1; } | |
| detect_shell() { | |
| local shell_path shell_name | |
| if [[ -d /proc ]]; then | |
| shell_path="$(sh -c 'ps -p $$ -o ppid=' | xargs -I'{}' readlink -f '/proc/{}/exe' 2>/dev/null)" || true | |
| fi | |
| if [[ -z "${shell_path:-}" ]]; then | |
| shell_path="$(sh -c 'ps -p $$ -o ppid=' | xargs ps -o comm= -p 2>/dev/null)" || true | |
| fi | |
| if [[ -z "${shell_path:-}" ]]; then | |
| shell_path="$SHELL" | |
| fi | |
| shell_name="$(basename "$shell_path")" | |
| case "$shell_name" in | |
| bash) | |
| if [[ -f "$HOME/.bash_profile" ]]; then | |
| echo "$HOME/.bash_profile" | |
| elif [[ -f "$HOME/.bashrc" ]]; then | |
| echo "$HOME/.bashrc" | |
| else | |
| echo "$HOME/.profile" | |
| fi | |
| ;; | |
| zsh) | |
| echo "$HOME/.zshrc" | |
| ;; | |
| fish) | |
| echo "$HOME/.config/fish/config.fish" | |
| ;; | |
| *) | |
| echo "$HOME/.profile" | |
| ;; | |
| esac | |
| } | |
| check_deps() { | |
| for cmd in curl tar; do | |
| command -v "$cmd" >/dev/null 2>&1 || error "Required command not found: $cmd" | |
| done | |
| } | |
| download_toolchain() { | |
| local url="$1" | |
| local dir="$2" | |
| local filename | |
| filename="$(basename "$url")" | |
| if [[ -d "$TOOLCHAIN_DIR/$dir" ]]; then | |
| warn "Already installed: $dir" | |
| return 0 | |
| fi | |
| info "Downloading $dir..." | |
| curl -#Lo "$TOOLCHAIN_DIR/$filename" "$url" | |
| info "Extracting $dir..." | |
| tar -xf "$TOOLCHAIN_DIR/$filename" -C "$TOOLCHAIN_DIR" | |
| rm "$TOOLCHAIN_DIR/$filename" | |
| success "Installed: $dir" | |
| } | |
| update_profile() { | |
| local profile="$1" | |
| local shell_name | |
| shell_name="$(basename "$profile")" | |
| local marker="# ARM toolchains" | |
| if grep -qF "$marker" "$profile" 2>/dev/null; then | |
| warn "PATH already configured in $profile" | |
| return 0 | |
| fi | |
| info "Updating $profile..." | |
| if [[ "$profile" == *"fish"* ]]; then | |
| mkdir -p "$(dirname "$profile")" | |
| cat >> "$profile" <<EOF | |
| $marker | |
| set -gx PATH "\$HOME/toolchains/$ARM32_DIR/bin" \$PATH | |
| set -gx PATH "\$HOME/toolchains/$ARM64_DIR/bin" \$PATH | |
| EOF | |
| else | |
| cat >> "$profile" <<EOF | |
| $marker | |
| export PATH="\$HOME/toolchains/$ARM32_DIR/bin:\$PATH" | |
| export PATH="\$HOME/toolchains/$ARM64_DIR/bin:\$PATH" | |
| EOF | |
| fi | |
| success "Updated $profile" | |
| } | |
| main() { | |
| check_deps | |
| local profile | |
| profile="$(detect_shell)" | |
| info "Detected profile: $profile" | |
| mkdir -p "$TOOLCHAIN_DIR" | |
| download_toolchain "$ARM32_URL" "$ARM32_DIR" | |
| download_toolchain "$ARM64_URL" "$ARM64_DIR" | |
| update_profile "$profile" | |
| success "Installation complete! Run 'source $profile' or open a new terminal." | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment