-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·111 lines (96 loc) · 3.43 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·111 lines (96 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -euo pipefail
# --- tiny prelude (needed BEFORE sourcing libs) ---
_abort(){ echo "ERROR: $*" >&2; exit 1; }
_have(){ command -v "$1" >/dev/null 2>&1; }
# Defaults / env
declare -r DOTFILES_DIR="${DOTFILES_DIR:-"$HOME/.dotfiles"}"
export DOTFILES_DIR
declare -r GITHUB_USER="${GITHUB_USER:-usma0118}"
declare CONTAINER_ENV
CONTAINER_ENV=$([[ -n "${CODESPACES:-}" || -n "${container:-}" ]] && echo true || echo false)
readonly CONTAINER_ENV
export REMOTE_USER="${ANSIBLE_REMOTE_USER:-${SUDO_USER:-${USER}}}"
# Ensure required files exist before sourcing
[ -r "$DOTFILES_DIR/lib/log.sh" ] || _abort "Missing $DOTFILES_DIR/lib/log.sh"
[ -r "$DOTFILES_DIR/lib/utils.sh" ] || _abort "Missing $DOTFILES_DIR/lib/utils.sh"
# --- libraries (define abort/have properly; will shadow the tiny ones) ---
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/log.sh"
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/utils.sh"
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/updater.sh"
# sudo helper
SUDO=""
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
if have sudo; then SUDO="sudo"; else abort "This script needs root or sudo"; fi
fi
# utils.sh exports lowercase os_family
log_info "Running on OS: ${os_family:-unknown}"
# Install Ansible if missing
if ! have ansible || ! have ansible-playbook ; then
case "$os_family" in
ubuntu)
$SUDO apt-get update -y
$SUDO apt-get install -y software-properties-common git direnv
if ! grep -Rqs "ansible/ansible" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null; then
$SUDO add-apt-repository -y ppa:ansible/ansible
$SUDO apt-get update -y
fi
$SUDO apt-get install -y ansible-core
;;
debian)
$SUDO apt-get update -y
$SUDO apt-get install -y ansible-core git direnv
;;
alpine)
if [ "$CONTAINER_ENV" = true ]; then
if [ -n "${VIRTUAL_ENV:-}" ]; then
log_info 'Installing Ansible in venv:' "$VIRTUAL_ENV"
elif [ -f "$HOME/.venv/bin/activate" ]; then
# shellcheck disable=SC1090
# shellcheck disable=SC1091
source "$HOME/.venv/bin/activate"
log_warning 'info: activated venv at %s/.venv\n' "$HOME"
python -m pip install --no-cache-dir ansible-core
else
log_warning "Installing Ansible on Alpine…"
$SUDO apk add --no-cache ansible-core git direnv
fi
python -m pip install --upgrade --no-cache-dir pip
python -m pip install --no-cache-dir ansible-core
fi
;;
darwin)
if ! have brew; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
log_info "Homebrew already installed"
fi
brew install ansible git
;;
*)
abort "Unsupported OS family: ${os_family}"
;;
esac
fi
# Point Ansible at project config if present
if [ -f "$DOTFILES_DIR/playbooks/ansible.cfg" ]; then
export ANSIBLE_CONFIG="$DOTFILES_DIR/playbooks/ansible.cfg"
fi
# Load direnv for this shell only if present
if have direnv && [ -f "$DOTFILES_DIR/playbooks/.envrc" ]; then
# shellcheck disable=SC1090
eval "$(direnv export bash)"
fi
# Run the playbook installer
pushd "$DOTFILES_DIR/playbooks" >/dev/null || abort "cd failed: $DOTFILES_DIR/playbooks"
trap 'popd >/dev/null || true' EXIT
if [ -x ./install ]; then
./install
else
# shellcheck disable=SC1091
source ./install
fi
log_info "Rollout completed"