Add 1 file, Remove 1 file: bootstrap.sh, bootstrap.sh
This commit is contained in:
@@ -1,164 +0,0 @@
|
||||
#!/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" "$*"; }
|
||||
|
||||
update() {
|
||||
dotstate activate || true
|
||||
|
||||
sed -i.bak 's/^repo_mode\s*=\s*".*"/repo_mode = "Local"/' ~/.config/dotstate/config.toml || echo 'repo_mode = "Local"' >> ~/.config/dotstate/config.toml
|
||||
|
||||
dotstate doctor --fix || true
|
||||
dotstate activate || true
|
||||
|
||||
info "done"
|
||||
}
|
||||
|
||||
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
|
||||
update
|
||||
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
|
||||
|
||||
REPO_URL="https://git.jeremymcclure.com/jeremy/dotstate-storage.git"
|
||||
TARGET_DIR="$HOME/.config/dotstate/storage"
|
||||
|
||||
if [[ -d "$TARGET_DIR/.git" ]]; then
|
||||
# Case 1: It is already a git repo -> Pull updates
|
||||
echo "Repository exists. Pulling updates..."
|
||||
git -C "$TARGET_DIR" pull
|
||||
else
|
||||
# Case 2: Not a repo (or doesn't exist) -> Clone fresh
|
||||
# Note: git clone will fail if TARGET_DIR exists as a non-empty non-git dir
|
||||
echo "Repository not found. Cloning..."
|
||||
git clone --depth=1 "$REPO_URL" "$TARGET_DIR"
|
||||
fi
|
||||
|
||||
info "done"
|
||||
update
|
||||
Reference in New Issue
Block a user