-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·180 lines (146 loc) · 5.46 KB
/
setup.sh
File metadata and controls
executable file
·180 lines (146 loc) · 5.46 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
174
175
176
177
178
179
180
#!/bin/bash
#
# Trusted Setup
#
# Bootstraps a developer machine with the baseline tools required to clone
# and run any Trusted project's bin/setup script.
#
# Usage:
# # First-time setup or update
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trusted/setup/main/setup.sh)"
#
# # Re-run a specific migration
# ./setup.sh --rerun <timestamp>
set -euo pipefail
# ---------------------------------------------------------------------------
# Resolve script directory (works for both local execution and curl pipe)
# ---------------------------------------------------------------------------
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
# Running via curl | bash — clone (or update) the repo at ~/Work/setup
SETUP_CLONE_DIR="$HOME/Work/setup"
SETUP_REPO="${SETUP_REPO:-trusted/setup}"
SETUP_REF="${SETUP_REF:-main}"
if [ -d "$SETUP_CLONE_DIR/.git" ]; then
# Abort if there are uncommitted changes
if ! git -C "$SETUP_CLONE_DIR" diff --quiet HEAD 2>/dev/null; then
echo "ERROR: $SETUP_CLONE_DIR has uncommitted changes."
echo "Commit or stash them, then re-run setup."
exit 1
fi
# Abort if on the wrong branch
local_branch="$(git -C "$SETUP_CLONE_DIR" branch --show-current)"
if [ "$local_branch" != "$SETUP_REF" ]; then
echo "ERROR: $SETUP_CLONE_DIR is on branch '$local_branch', expected '$SETUP_REF'."
echo "Switch to $SETUP_REF, then re-run setup."
exit 1
fi
echo "Updating setup from github.com/$SETUP_REPO ($SETUP_REF)..."
git -C "$SETUP_CLONE_DIR" pull --ff-only --quiet
else
echo "Cloning setup from github.com/$SETUP_REPO ($SETUP_REF)..."
mkdir -p "$HOME/Work"
git clone "https://github.com/$SETUP_REPO.git" "$SETUP_CLONE_DIR" --quiet
git -C "$SETUP_CLONE_DIR" checkout "$SETUP_REF" --quiet
fi
SCRIPT_DIR="$SETUP_CLONE_DIR"
fi
# ---------------------------------------------------------------------------
# Load shared helpers and OS detection
# ---------------------------------------------------------------------------
# shellcheck source=lib/common.sh
source "$SCRIPT_DIR/lib/common.sh"
# shellcheck source=lib/migrate.sh
source "$SCRIPT_DIR/lib/migrate.sh"
# COLOR_RED, COLOR_GREEN, COLOR_YELLOW, and COLOR_RESET are provided by common.sh.
# Show a red notice if setup exits unexpectedly
trap 'echo ""; echo "${COLOR_RED}Setup failed.${COLOR_RESET} Check the output above for details."; echo ""' ERR
# ---------------------------------------------------------------------------
# Parse arguments
# ---------------------------------------------------------------------------
ACTION="setup"
RERUN_TIMESTAMP=""
while [[ $# -gt 0 ]]; do
case "$1" in
--rerun)
ACTION="rerun"
RERUN_TIMESTAMP="${2:-}"
if [ -z "$RERUN_TIMESTAMP" ]; then
echo "ERROR: --rerun requires a migration timestamp."
echo "Usage: setup.sh --rerun <timestamp>"
exit 1
fi
shift 2
;;
--help|-h)
echo "Trusted Setup"
echo ""
echo "Usage: setup.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --rerun <timestamp> Re-run a specific migration"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Run setup.sh --help for usage."
exit 1
;;
esac
done
# Handle --rerun before anything else
if [ "$ACTION" = "rerun" ]; then
rerun_migration "$SCRIPT_DIR" "$RERUN_TIMESTAMP"
exit $?
fi
# ---------------------------------------------------------------------------
# Run setup
# ---------------------------------------------------------------------------
echo ""
echo "= Trusted Setup ="
echo ""
echo " Platform: $OS"
echo ""
# shellcheck source=lib/packages_setup.sh
source "$SCRIPT_DIR/lib/packages_setup.sh"
# shellcheck source=lib/git_setup.sh
source "$SCRIPT_DIR/lib/git_setup.sh"
# shellcheck source=lib/build_setup.sh
source "$SCRIPT_DIR/lib/build_setup.sh"
# shellcheck source=lib/mise_setup.sh
source "$SCRIPT_DIR/lib/mise_setup.sh"
# shellcheck source=lib/1password_setup.sh
source "$SCRIPT_DIR/lib/1password_setup.sh"
# shellcheck source=lib/circleci_setup.sh
source "$SCRIPT_DIR/lib/circleci_setup.sh"
# shellcheck source=lib/docker_setup.sh
source "$SCRIPT_DIR/lib/docker_setup.sh"
# shellcheck source=lib/aws_setup.sh
source "$SCRIPT_DIR/lib/aws_setup.sh"
# shellcheck source=lib/registries_setup.sh
source "$SCRIPT_DIR/lib/registries_setup.sh"
# ---------------------------------------------------------------------------
# Migrations
# ---------------------------------------------------------------------------
fmt_header "Migrations"
run_migrations "$SCRIPT_DIR"
# ---------------------------------------------------------------------------
# Repositories
# ---------------------------------------------------------------------------
# shellcheck source=lib/repos_setup.sh
source "$SCRIPT_DIR/lib/repos_setup.sh"
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
echo ""
echo "= Trusted Setup Complete ="
echo ""
echo "${COLOR_GREEN}Setup finished successfully.${COLOR_RESET}"
echo ""
echo "${COLOR_YELLOW}Next steps:${COLOR_RESET}"
echo " 1. Open a new terminal (or run: source ~/.zshrc)"
echo " 2. Clone a project: cd ~/Work && gh repo clone trusted/<repo-name>"
echo " 3. Run project setup: cd <repo-name> && bin/setup"
echo ""