Update 1 file: bootstrap.sh

This commit is contained in:
2026-08-01 15:11:45 -04:00
parent 3298ac25f6
commit c5babfec48
+68 -62
View File
@@ -7,13 +7,6 @@ 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 &>/dev/null || true
sed -i.bak 's/^repo_mode\s*=\s*".*"/repo_mode = "Local"/' ~/.config/dotstate/config.toml &>/dev/null || echo 'repo_mode = "Local"' >> ~/.config/dotstate/config.toml &>/dev/null
dotstate doctor --fix &>/dev/null || true
dotstate activate &>/dev/null || true
}
arch() {
case "$(uname -m)" in
x86_64) echo "x86_64" ;;
@@ -23,24 +16,26 @@ arch() {
esac
}
# --- Check existing ---
# --- Check ---
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
# --- Update ---
# --- Detect package manager ---
update() {
dotstate activate &>/dev/null || true
sed -i.bak 's/^repo_mode\s*=\s*".*"/repo_mode = "Local"/' ~/.config/dotstate/config.toml &>/dev/null || echo 'repo_mode = "Local"' >> ~/.config/dotstate/config.toml &>/dev/null
dotstate doctor --fix &>/dev/null || true
dotstate activate &>/dev/null || true
}
# --- Install ---
install_pkgs() {
if command -v pacman &>/dev/null; then
@@ -58,43 +53,6 @@ install_pkgs() {
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[@]}" &>/dev/null || {
warn "system install failed, falling back to binaries"
BIN_pkgs+=("${SYS_pkgs[@]}")
}
fi
# --- Install pre-built binaries ---
install_binary() {
local name="$1"
local arch
@@ -138,22 +96,70 @@ install_binary() {
esac
}
for tool in "${BIN_pkgs[@]}"; do
install_missing() {
local missing=("$@")
[[ ${#missing[@]} -eq 0 ]] && return 0
declare -A PKG_NAMES=(
[git]="git"
[curl]="curl"
[jq]="jq"
[fzf]="fzf"
[eza]="eza"
[bat]="bat"
[delta]="git-delta"
[fastfetch]="fastfetch"
)
local sys_pkgs=()
local bin_pkgs=()
for tool in "${missing[@]}"; do
if [[ "$tool" == "starship" || "$tool" == "dotstate" ]]; then
bin_pkgs+=("$tool")
continue
fi
sys_pkgs+=("${PKG_NAMES[$tool]:-$tool}")
done
if [[ ${#sys_pkgs[@]} -gt 0 ]]; then
info "installing from system repos: ${sys_pkgs[*]}"
install_pkgs "${sys_pkgs[@]}" &>/dev/null || {
warn "system install failed, falling back to binaries"
bin_pkgs+=("${sys_pkgs[@]}")
}
fi
for tool in "${bin_pkgs[@]}"; do
install_binary "$tool"
done
done
}
REPO_URL="https://git.jeremymcclure.com/jeremy/dotstate-storage.git"
TARGET_DIR="$HOME/.config/dotstate/storage"
# --- Repo ---
if [[ -d "$TARGET_DIR/.git" ]]; then
# Case 1: It is already a git repo -> Pull updates
update_repo() {
local REPO_URL="https://git.jeremymcclure.com/jeremy/dotstate-storage.git"
local TARGET_DIR="$HOME/.config/dotstate/storage"
if [[ -d "$TARGET_DIR/.git" ]]; then
info "Repository exists. Pulling updates..."
git -C "$TARGET_DIR" pull &>/dev/null
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
else
info "Repository not found. Cloning..."
git clone --depth=1 "$REPO_URL" "$TARGET_DIR" &>/dev/null
fi
}
# --- Main ---
MISSING=($(check_all))
if [[ ${#MISSING[@]} -eq 0 ]]; then
info "all tools present"
update
else
install_missing "${MISSING[@]}"
fi
info "Done"
update_repo
info "Done"