Update 1 file: bootstrap.sh
This commit is contained in:
+72
-66
@@ -7,13 +7,6 @@ info() { printf "\033[1;34m%s\033[0m\n" "$*"; }
|
|||||||
warn() { printf "\033[1;33m%s\033[0m\n" "$*"; }
|
warn() { printf "\033[1;33m%s\033[0m\n" "$*"; }
|
||||||
error() { printf "\033[1;31m%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() {
|
arch() {
|
||||||
case "$(uname -m)" in
|
case "$(uname -m)" in
|
||||||
x86_64) echo "x86_64" ;;
|
x86_64) echo "x86_64" ;;
|
||||||
@@ -23,24 +16,26 @@ arch() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Check existing ---
|
# --- Check ---
|
||||||
|
|
||||||
check_all() {
|
check_all() {
|
||||||
local missing=()
|
local missing=()
|
||||||
for cmd in git curl jq fzf starship eza bat delta fastfetch dotstate; do
|
for cmd in git curl jq fzf starship eza bat delta fastfetch dotstate; do
|
||||||
command -v "$cmd" &>/dev/null || missing+=("$cmd")
|
command -v "$cmd" &>/dev/null || missing+=("$cmd")
|
||||||
done
|
done
|
||||||
if [[ ${#missing[@]} -eq 0 ]]; then
|
|
||||||
info "all tools present" >&2
|
|
||||||
update
|
|
||||||
fi
|
|
||||||
echo "${missing[@]}"
|
echo "${missing[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
MISSING=($(check_all))
|
# --- Update ---
|
||||||
[[ ${#MISSING[@]} -eq 0 ]] && exit 0
|
|
||||||
|
|
||||||
# --- 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() {
|
install_pkgs() {
|
||||||
if command -v pacman &>/dev/null; then
|
if command -v pacman &>/dev/null; then
|
||||||
@@ -58,43 +53,6 @@ install_pkgs() {
|
|||||||
fi
|
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() {
|
install_binary() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local arch
|
local arch
|
||||||
@@ -138,22 +96,70 @@ install_binary() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
for tool in "${BIN_pkgs[@]}"; do
|
install_missing() {
|
||||||
install_binary "$tool"
|
local missing=("$@")
|
||||||
done
|
[[ ${#missing[@]} -eq 0 ]] && return 0
|
||||||
|
|
||||||
REPO_URL="https://git.jeremymcclure.com/jeremy/dotstate-storage.git"
|
declare -A PKG_NAMES=(
|
||||||
TARGET_DIR="$HOME/.config/dotstate/storage"
|
[git]="git"
|
||||||
|
[curl]="curl"
|
||||||
|
[jq]="jq"
|
||||||
|
[fzf]="fzf"
|
||||||
|
[eza]="eza"
|
||||||
|
[bat]="bat"
|
||||||
|
[delta]="git-delta"
|
||||||
|
[fastfetch]="fastfetch"
|
||||||
|
)
|
||||||
|
|
||||||
if [[ -d "$TARGET_DIR/.git" ]]; then
|
local sys_pkgs=()
|
||||||
# Case 1: It is already a git repo -> Pull updates
|
local bin_pkgs=()
|
||||||
info "Repository exists. Pulling updates..."
|
|
||||||
git -C "$TARGET_DIR" pull &>/dev/null
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Repo ---
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
else
|
||||||
# Case 2: Not a repo (or doesn't exist) -> Clone fresh
|
install_missing "${MISSING[@]}"
|
||||||
# Note: git clone will fail if TARGET_DIR exists as a non-empty non-git dir
|
|
||||||
info "Repository not found. Cloning..."
|
|
||||||
git clone --depth=1 "$REPO_URL" "$TARGET_DIR" &>/dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Done"
|
update_repo
|
||||||
|
info "Done"
|
||||||
|
|||||||
Reference in New Issue
Block a user