-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
173 lines (146 loc) · 5.03 KB
/
bootstrap.sh
File metadata and controls
173 lines (146 loc) · 5.03 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/zsh
set -euo pipefail
# -----------------------------
# Defaults
# -----------------------------
RSD_REPO_URL="${RSD_REPO_URL:-https://github.com/afonsoc12/ready-set-develop.git}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export RSD_ANSIBLE_HOME="${RSD_ANSIBLE_HOME:-$XDG_DATA_HOME/ansible}"
# Repo defaults
RSD_REPO_DIR="${RSD_REPO_DIR:-$XDG_DATA_HOME/ready-set-develop}"
RSD_REPO_VERSION="${RSD_REPO_VERSION:-master}"
export PATH="$HOME/Library/Python/3.9/bin:/opt/homebrew/bin:$PATH"
# Optional SOPS file
RSD_SOPS_FILE="${RSD_SOPS_FILE:-}"
echo
echo "========================================"
echo "🚀 Ready, Set, Develop — bootstrap"
echo "========================================"
echo
# -----------------------------
# 1. Sanity checks
# -----------------------------
if [[ "$(uname -s)" != "Darwin" ]]; then
echo "❌ This bootstrap script is intended for macOS only."
exit 1
fi
echo "----------------------------------------"
# -----------------------------
# 2. Command Line Tools
# -----------------------------
if ! xcode-select -p >/dev/null 2>&1; then
echo "🔧 Installing Apple Command Line Tools..."
xcode-select --install
echo
echo "⚠️ Complete the installation and re-run this script."
exit 1
else
echo "✅ Command Line Tools installed"
fi
echo "----------------------------------------"
# -----------------------------
# 3. SOPS check
# -----------------------------
if [[ -z "${SOPS_AGE_KEY_FILE:-}" ]]; then
echo "❌ SOPS_AGE_KEY_FILE is not set."
echo "Export your AGE key file before running:"
echo " export SOPS_AGE_KEY_FILE=<PATH AGE KEY>"
exit 1
fi
if [[ ! -f "$SOPS_AGE_KEY_FILE" ]]; then
echo "❌ SOPS_AGE_KEY_FILE does not exist: $SOPS_AGE_KEY_FILE"
exit 1
fi
echo "🔐 SOPS AGE key detected"
echo "----------------------------------------"
# -----------------------------
# 4. Ensure directories exist
# -----------------------------
echo "📁 Ensuring directories exist"
mkdir -p "$XDG_DATA_HOME" "$RSD_ANSIBLE_HOME"
echo "----------------------------------------"
# -----------------------------
# 5. Install Ansible (user)
# -----------------------------
if ! command -v ansible >/dev/null 2>&1; then
echo "📦 Installing Ansible (user install)"
/usr/bin/pip3 install --upgrade pip
/usr/bin/pip3 install ansible
else
echo "✅ Ansible already installed"
fi
echo "----------------------------------------"
# -----------------------------
# 6. Clone repository
# -----------------------------
if [[ -d "$RSD_REPO_DIR" && "${RSD_FORCE_REPO:-false}" == "true" ]]; then
echo "⚠️ RSD_FORCE_REPO=true, removing existing repo: $RSD_REPO_DIR"
rm -rf "$RSD_REPO_DIR"
fi
if [[ ! -d "$RSD_REPO_DIR" ]]; then
echo "📥 Cloning ready-set-develop into: $RSD_REPO_DIR"
git clone "$RSD_REPO_URL" "$RSD_REPO_DIR"
else
echo "📂 Repository already exists: $RSD_REPO_DIR, pulling latest..."
git -C "$RSD_REPO_DIR" pull
fi
cd "$RSD_REPO_DIR"
# -----------------------------
# Checkout version if specified
# -----------------------------
if [[ -n "${RSD_REPO_VERSION:-}" ]]; then
echo "🔀 Checking out version: $RSD_REPO_VERSION"
git fetch --all
git checkout "$RSD_REPO_VERSION"
fi
echo "----------------------------------------"
# -----------------------------
# 6.1 Show last commit info
# -----------------------------
last_commit_hash=$(git -C "$RSD_REPO_DIR" log -1 --pretty=format:%H)
last_commit_message=$(git -C "$RSD_REPO_DIR" log -1 --pretty=format:%s)
last_commit_date=$(git -C "$RSD_REPO_DIR" log -1 --pretty=format:%ad --date=iso)
repo_web_url=${RSD_REPO_URL%.git}
repo_web_url=${repo_web_url#git@github.com:}
repo_web_url=${repo_web_url#https://github.com/}
repo_web_url="https://github.com/$repo_web_url"
echo "🧾 Last commit: $last_commit_hash"
echo " 🔗 $repo_web_url/commit/$last_commit_hash"
echo " 🗨 $last_commit_message"
echo " 🕒 $last_commit_date"
echo "----------------------------------------"
# -----------------------------
# 7. SOPS file (inside repo)
# -----------------------------
if [[ -n "$RSD_SOPS_FILE" ]]; then
if [[ ! -f "$RSD_SOPS_FILE" ]]; then
echo "❌ Provided SOPS file does not exist inside repo: $RSD_SOPS_FILE"
exit 1
fi
echo "🗝 Using SOPS file: $RSD_SOPS_FILE"
fi
# -----------------------------
# 8. Install Ansible requirements
# -----------------------------
echo "📚 Installing Ansible Galaxy requirements"
ansible-galaxy install -r requirements.yml
echo "----------------------------------------"
# -----------------------------
# 9. Run playbook
# -----------------------------
echo
echo "▶️ Running Ansible playbook"
echo
ANSIBLE_CMD="ansible-playbook main.yml --ask-become-pass"
[[ -n "$RSD_SOPS_FILE" ]] && ANSIBLE_CMD+=" -e sops_file=$RSD_SOPS_FILE"
# Append any extra flags passed to this script
if [[ $# -gt 0 ]]; then
ANSIBLE_CMD+=" $@"
echo "📋 Extra flags: $@"
fi
eval "$ANSIBLE_CMD"
echo
echo "========================================"
echo "🎉 Ready, Set, Develop completed successfully"
echo "You may want to restart your terminal or log out/in"
echo "========================================"