-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·166 lines (145 loc) · 5.49 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·166 lines (145 loc) · 5.49 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
#!/usr/bin/env bash
# macrift — one-line installer
# Usage: bash <(curl -fsSL https://raw.githubusercontent.com/emylfy/macrift/main/install.sh)
# Works on a fresh macOS — only needs curl (built-in). No git, no Xcode CLT.
set -euo pipefail
REPO="emylfy/macrift"
INSTALL_DIR="$HOME/.macrift"
LOCAL_BIN="$HOME/.local/bin"
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[38;5;39m'
RED='\033[0;31m'
info() { printf ' %b›%b %s\n' "$CYAN" "$RESET" "$1"; }
ok() { printf ' %b✓%b %s\n' "$GREEN" "$RESET" "$1"; }
err() { printf ' %b✗%b %s\n' "$RED" "$RESET" "$1"; }
ask() {
printf ' %b%s%b %b[y/n]%b ' "$YELLOW" "$1" "$RESET" "$DIM" "$RESET"
read -r answer </dev/tty
[[ "$answer" =~ ^[Yy]$ ]]
}
# Resolve the latest published release, download its checksummed tarball, verify
# the sha256, and extract into $1 (yielding $1/macrift). Pinned + verified — never
# floating `main`; fails loud rather than installing anything unverified. Needs
# only curl/tar/shasum (all stock on macOS — no python/jq).
fetch_verified_macrift() {
local dest="$1" url tag ver fname asset_url
info "Resolving latest release..."
url=$(curl -fsSL -I -o /dev/null -w '%{url_effective}' \
"https://github.com/$REPO/releases/latest" 2>/dev/null) || true
tag="${url##*/}"
if [[ -z "$tag" || "$tag" == "latest" ]]; then
err "Could not resolve a published release"
return 1
fi
ver="${tag#v}"
fname="macrift-$ver.tar.gz"
asset_url="https://github.com/$REPO/releases/download/$tag/$fname"
info "Downloading macrift $tag..."
if ! curl -fsSL -o "$dest/$fname" "$asset_url"; then
err "Download failed — release asset missing or no connection"
return 1
fi
if ! curl -fsSL -o "$dest/$fname.sha256" "$asset_url.sha256"; then
err "No checksum published for $tag — refusing to install unverified"
return 1
fi
info "Verifying checksum..."
if ! ( cd "$dest" && shasum -a 256 -c "$fname.sha256" ) >/dev/null 2>&1; then
err "Checksum mismatch — refusing to install"
return 1
fi
ok "Verified $tag"
if ! tar -xzf "$dest/$fname" -C "$dest" || [[ ! -d "$dest/macrift" ]]; then
err "Extract failed or unexpected archive layout"
return 1
fi
}
if [[ "$(uname)" != "Darwin" ]]; then
err "macrift is for macOS only"
exit 1
fi
# One-shot mode: any args after `--` → download to /tmp, run macrift with those
# args, clean up, exit. Lets you do `... | bash -s -- check` to inspect a Mac
# without installing anything (perfect for the seller's machine before buying).
if [[ $# -gt 0 ]]; then
printf '\n %bmacrift%b %bone-shot:%b %s\n\n' "$BOLD" "$RESET" "$DIM" "$RESET" "$*"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
if fetch_verified_macrift "$tmp"; then
chmod +x "$tmp/macrift/macrift.sh"
find "$tmp/macrift" -name "*.sh" -exec chmod +x {} +
"$tmp/macrift/macrift.sh" "$@"
exit $?
else
exit 1
fi
fi
printf '\n %bmacrift installer%b\n\n' "$BOLD" "$RESET"
# Download + verify
tmp="$(mktemp -d)"
if fetch_verified_macrift "$tmp"; then
# Atomic swap: backup old → move new → remove backup
[[ -d "$INSTALL_DIR" ]] && mv "$INSTALL_DIR" "$INSTALL_DIR.bak"
if mv "$tmp/macrift" "$INSTALL_DIR"; then
rm -rf "$INSTALL_DIR.bak"
else
err "Failed to move files into place"
[[ -d "$INSTALL_DIR.bak" ]] && mv "$INSTALL_DIR.bak" "$INSTALL_DIR"
rm -rf "$tmp"
exit 1
fi
rm -rf "$tmp"
ok "Installed → $INSTALL_DIR"
else
rm -rf "$tmp"
exit 1
fi
# Permissions
chmod +x "$INSTALL_DIR/macrift.sh"
find "$INSTALL_DIR" -name "*.sh" -exec chmod +x {} +
# Global command — ~/.local/bin (no sudo)
_link_exists() {
local target="$1/macrift"
[[ -L "$target" ]] && [[ "$(readlink "$target" 2>/dev/null)" == "$INSTALL_DIR/macrift.sh" ]]
}
if _link_exists "$LOCAL_BIN" || _link_exists "/usr/local/bin"; then
ok "macrift command already set up"
else
printf '\n'
if ask "Create global 'macrift' command?"; then
mkdir -p "$LOCAL_BIN"
ln -sf "$INSTALL_DIR/macrift.sh" "$LOCAL_BIN/macrift"
ok "Linked → $LOCAL_BIN/macrift"
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
local_zshrc="$HOME/.zshrc"
path_line='export PATH="$HOME/.local/bin:$PATH" # added by macrift'
if ! grep -qF '# added by macrift' "$local_zshrc" 2>/dev/null; then
printf '\n%s\n' "$path_line" >> "$local_zshrc"
ok "Added ~/.local/bin to PATH in .zshrc"
fi
export PATH="$LOCAL_BIN:$PATH"
fi
ok "Run from anywhere: macrift"
else
info "Run directly: ~/.macrift/macrift.sh"
fi
fi
# Bundled extras (Spotify SpotX + Spicetify) ship as a separate plugin so the
# core stays lean. Install it by default to keep the out-of-box experience whole.
# Best-effort: a failed clone (offline / repo not published yet) just skips it.
MISC_PLUGIN_DIR="$HOME/.macrift/plugins/misc"
if [[ ! -d "$MISC_PLUGIN_DIR" ]]; then
info "Adding bundled extras plugin (Spotify SpotX + Spicetify)…"
if "$INSTALL_DIR/macrift.sh" plugin add github.com/emylfy/macrift-misc </dev/tty; then
ok "Extras installed"
else
info "Skipped extras — add later with: macrift plugin add github.com/emylfy/macrift-misc"
fi
fi
printf '\n %bDone!%b Run %bmacrift%b to start.\n\n' "$GREEN" "$RESET" "$BOLD" "$RESET"
# Launch
"$INSTALL_DIR/macrift.sh"