-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
55 lines (45 loc) · 1.45 KB
/
Copy pathbootstrap.sh
File metadata and controls
55 lines (45 loc) · 1.45 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
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="${REPO_URL:-https://github.com/MCamner/macos-scripts.git}"
BRANCH="${BRANCH:-main}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/macos-scripts}"
# Handles log.
log() { printf "\033[1;34m[INFO]\033[0m %s\n" "$*"; }
# Handles ok.
ok() { printf "\033[1;32m[ OK ]\033[0m %s\n" "$*"; }
# Handles warn.
warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*" >&2; }
# Handles err.
err() { printf "\033[1;31m[ERR ]\033[0m %s\n" "$*" >&2; }
# Handles die.
die() { err "$*"; exit 1; }
# Handles require cmd.
require_cmd() {
command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"
}
# Runs the main entry point.
main() {
require_cmd git
require_cmd bash
log "Installing macos-scripts"
log "Repository: $REPO_URL"
log "Branch: $BRANCH"
log "Target: $INSTALL_DIR"
if [[ -d "$INSTALL_DIR/.git" ]]; then
log "Existing git checkout found. Updating..."
git -C "$INSTALL_DIR" fetch origin "$BRANCH"
git -C "$INSTALL_DIR" checkout "$BRANCH"
git -C "$INSTALL_DIR" pull --ff-only origin "$BRANCH"
else
if [[ -e "$INSTALL_DIR" ]]; then
die "Target path exists but is not a git repo: $INSTALL_DIR"
fi
log "Cloning repository..."
git clone --branch "$BRANCH" --depth 1 "$REPO_URL" "$INSTALL_DIR"
fi
log "Running local installer..."
bash "$INSTALL_DIR/install.sh" --install-dir "$INSTALL_DIR" --yes
ok "macos-scripts installed"
printf '\nRun:\n mqlaunch\n'
}
main "$@"