Add 16 files (16+ files changed)
This commit is contained in:
Executable
+138
@@ -0,0 +1,138 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# --- Helpers ---
|
||||
|
||||
info() { printf "\033[1;34m%s\033[0m\n" "$*"; }
|
||||
warn() { printf "\033[1;33m%s\033[0m\n" "$*"; }
|
||||
error() { printf "\033[1;31m%s\033[0m\n" "$*"; }
|
||||
|
||||
arch() {
|
||||
case "$(uname -m)" in
|
||||
x86_64) echo "x86_64" ;;
|
||||
aarch64) echo "aarch64" ;;
|
||||
armv7l) echo "armhf" ;;
|
||||
*) echo "unknown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# --- Check existing ---
|
||||
|
||||
check_all() {
|
||||
local missing=()
|
||||
for cmd in git curl jq fzf starship eza bat delta fastfetch dotstate; do
|
||||
command -v "$cmd" &>/dev/null || missing+=("$cmd")
|
||||
done
|
||||
if [[ ${#missing[@]} -eq 0 ]]; then
|
||||
info "all tools present" >&2
|
||||
exit 0
|
||||
fi
|
||||
echo "${missing[@]}"
|
||||
}
|
||||
|
||||
MISSING=($(check_all))
|
||||
[[ ${#MISSING[@]} -eq 0 ]] && exit 0
|
||||
|
||||
# --- Detect package manager ---
|
||||
|
||||
install_pkgs() {
|
||||
if command -v pacman &>/dev/null; then
|
||||
sudo pacman -S --noconfirm "$@"
|
||||
elif command -v dnf &>/dev/null; then
|
||||
sudo dnf install -y "$@"
|
||||
elif command -v apt &>/dev/null; then
|
||||
sudo apt update -qq && sudo apt install -y "$@"
|
||||
elif command -v zypper &>/dev/null; then
|
||||
sudo zypper install -y "$@"
|
||||
elif command -v apk &>/dev/null; then
|
||||
sudo apk add "$@"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Install from system repos ---
|
||||
|
||||
SYS_pkgs=()
|
||||
BIN_pkgs=()
|
||||
|
||||
# Map tool names to distro package names where they differ
|
||||
declare -A PKG_NAMES=(
|
||||
[git]="git"
|
||||
[curl]="curl"
|
||||
[jq]="jq"
|
||||
[fzf]="fzf"
|
||||
[eza]="eza"
|
||||
[bat]="bat"
|
||||
[delta]="git-delta"
|
||||
[fastfetch]="fastfetch"
|
||||
)
|
||||
|
||||
# starship and dotstate have no distro package, always binary
|
||||
for tool in "${MISSING[@]}"; do
|
||||
if [[ "$tool" == "starship" || "$tool" == "dotstate" ]]; then
|
||||
BIN_pkgs+=("$tool")
|
||||
continue
|
||||
fi
|
||||
pkg="${PKG_NAMES[$tool]:-$tool}"
|
||||
SYS_pkgs+=("$pkg")
|
||||
done
|
||||
|
||||
if [[ ${#SYS_pkgs[@]} -gt 0 ]]; then
|
||||
info "installing from system repos: ${SYS_pkgs[*]}"
|
||||
install_pkgs "${SYS_pkgs[@]}" || {
|
||||
warn "system install failed, falling back to binaries"
|
||||
BIN_pkgs+=("${SYS_pkgs[@]}")
|
||||
}
|
||||
fi
|
||||
|
||||
# --- Install pre-built binaries ---
|
||||
|
||||
install_binary() {
|
||||
local name="$1"
|
||||
local arch
|
||||
arch=$(arch)
|
||||
|
||||
case "$name" in
|
||||
starship)
|
||||
info "installing starship"
|
||||
curl -sS https://starship.rs/install.sh | sh -s -- -y
|
||||
;;
|
||||
eza)
|
||||
info "installing eza"
|
||||
local url="https://github.com/eza-community/eza/releases/latest/download/eza-${arch}-unknown-linux-musl.tar.gz"
|
||||
curl -sSfL "$url" | sudo tar xz -C /usr/local/bin
|
||||
;;
|
||||
bat)
|
||||
info "installing bat"
|
||||
local url="https://github.com/sharkdp/bat/releases/latest/download/bat-${arch}-unknown-linux-musl.tar.gz"
|
||||
curl -sSfL "$url" | sudo tar xz --strip-components=1 -C /usr/local/bin "bat-${arch}-unknown-linux-musl/bat"
|
||||
;;
|
||||
delta)
|
||||
info "installing delta"
|
||||
local url="https://github.com/dandavison/delta/releases/latest/download/delta-${arch}-unknown-linux-musl.tar.gz"
|
||||
curl -sSfL "$url" | sudo tar xz --strip-components=1 -C /usr/local/bin "delta-${arch}-unknown-linux-musl/delta"
|
||||
;;
|
||||
fastfetch)
|
||||
info "installing fastfetch"
|
||||
local url="https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-${arch}.tar.gz"
|
||||
curl -sSfL "$url" | sudo tar xz --strip-components=2 -C /usr/local/bin
|
||||
;;
|
||||
jq)
|
||||
info "installing jq"
|
||||
local url="https://github.com/jqlang/jq/releases/latest/download/jq-linux-${arch}"
|
||||
curl -sSfL "$url" -o /usr/local/bin/jq
|
||||
sudo chmod +x /usr/local/bin/jq
|
||||
;;
|
||||
dotstate)
|
||||
info "installing dotstate"
|
||||
curl -fsSL https://dotstate.serkan.dev/install.sh | bash
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
for tool in "${BIN_pkgs[@]}"; do
|
||||
install_binary "$tool"
|
||||
done
|
||||
|
||||
info "done"
|
||||
Reference in New Issue
Block a user