Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·275 lines (239 loc) · 8.32 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·275 lines (239 loc) · 8.32 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/sh
# zopp CLI installer
# Usage: curl -fsSL https://raw.githubusercontent.com/faiscadev/zopp/main/install.sh | sh
set -e
ZOPP_INSTALLER_VERSION="1.0"
ZOPP_REPO="faiscadev/zopp"
ZOPP_INSTALL_DIR="${ZOPP_INSTALL_DIR:-$HOME/.zopp/bin}"
# --- Output helpers ---
zopp_use_color() {
if [ -n "$NO_COLOR" ] || [ "$ZOPP_NO_COLOR" = "1" ]; then
return 1
fi
# Check if stdout is a TTY
if [ -t 1 ]; then
return 0
fi
return 1
}
zopp_log() {
printf " %s\n" "$1"
}
zopp_log_success() {
if zopp_use_color; then
printf " \033[32m\033[1m%s\033[0m %s\n" "ok" "$1"
else
printf " [ok] %s\n" "$1"
fi
}
zopp_log_error() {
if zopp_use_color; then
printf " \033[31m\033[1m%s\033[0m %s\n" "FAIL" "$1" >&2
else
printf " [FAIL] %s\n" "$1" >&2
fi
}
zopp_log_warn() {
if zopp_use_color; then
printf " \033[33m%s\033[0m %s\n" "WARN" "$1"
else
printf " [WARN] %s\n" "$1"
fi
}
# --- Platform detection ---
zopp_detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
case "$ARCH" in
x86_64)
ZOPP_TARGET="x86_64-unknown-linux-gnu"
ZOPP_PLATFORM_DISPLAY="Linux x86_64"
;;
aarch64)
ZOPP_TARGET="aarch64-unknown-linux-gnu"
ZOPP_PLATFORM_DISPLAY="Linux aarch64 (ARM64)"
;;
*)
zopp_log_error "Unsupported architecture: $ARCH"
zopp_log ""
zopp_log "Supported platforms:"
zopp_log " - Linux x86_64"
zopp_log " - Linux aarch64 (ARM64)"
zopp_log " - macOS x86_64 (Intel)"
zopp_log " - macOS aarch64 (Apple Silicon)"
zopp_log ""
zopp_log "Alternatively, install from source: cargo install --git https://github.com/$ZOPP_REPO zopp-cli"
exit 1
;;
esac
;;
Darwin)
case "$ARCH" in
x86_64)
ZOPP_TARGET="x86_64-apple-darwin"
ZOPP_PLATFORM_DISPLAY="macOS x86_64 (Intel)"
;;
arm64)
ZOPP_TARGET="aarch64-apple-darwin"
ZOPP_PLATFORM_DISPLAY="macOS aarch64 (Apple Silicon)"
;;
*)
zopp_log_error "Unsupported architecture: $ARCH"
zopp_log ""
zopp_log "Supported platforms:"
zopp_log " - macOS x86_64 (Intel)"
zopp_log " - macOS aarch64 (Apple Silicon)"
zopp_log " - Linux x86_64"
zopp_log " - Linux aarch64 (ARM64)"
zopp_log ""
zopp_log "Alternatively, install from source: cargo install --git https://github.com/$ZOPP_REPO zopp-cli"
exit 1
;;
esac
;;
*)
zopp_log_error "Unsupported operating system: $OS"
zopp_log ""
zopp_log "Supported platforms:"
zopp_log " - Linux x86_64"
zopp_log " - Linux aarch64 (ARM64)"
zopp_log " - macOS x86_64 (Intel)"
zopp_log " - macOS aarch64 (Apple Silicon)"
zopp_log ""
zopp_log "Alternatively, install from source: cargo install --git https://github.com/$ZOPP_REPO zopp-cli"
exit 1
;;
esac
}
# --- Version fetching ---
zopp_fetch_version() {
LATEST_URL="https://api.github.com/repos/$ZOPP_REPO/releases/latest"
VERSION=$(curl -fsSL "$LATEST_URL" | grep '"tag_name":' | sed 's/.*"tag_name": *"//;s/".*//')
if [ -z "$VERSION" ]; then
zopp_log_error "Could not fetch latest version from GitHub Releases."
zopp_log " Check your internet connection and try again."
zopp_log " URL: $LATEST_URL"
exit 1
fi
}
# --- Checksum verification ---
zopp_compute_sha256() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1" | awk '{print $1}'
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$1" | awk '{print $1}'
else
zopp_log_error "Neither sha256sum nor shasum found. Cannot verify download integrity."
zopp_log " Install one of these utilities and try again."
exit 1
fi
}
zopp_verify_checksum() {
ARCHIVE_PATH="$1"
CHECKSUMS_PATH="$2"
ARCHIVE_NAME="$3"
EXPECTED=$(grep "$ARCHIVE_NAME" "$CHECKSUMS_PATH" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
zopp_log_error "No checksum found for $ARCHIVE_NAME in checksums.txt."
zopp_log " The release may be incomplete or corrupted."
zopp_log " Try again, or download manually from:"
zopp_log " https://github.com/$ZOPP_REPO/releases"
exit 1
fi
ACTUAL=$(zopp_compute_sha256 "$ARCHIVE_PATH")
if [ "$EXPECTED" != "$ACTUAL" ]; then
zopp_log_error "SHA256 checksum verification failed!"
zopp_log ""
zopp_log " Expected: $EXPECTED"
zopp_log " Actual: $ACTUAL"
zopp_log ""
zopp_log " The downloaded file may be corrupted or tampered with."
zopp_log " Try again, or download manually from:"
zopp_log " https://github.com/$ZOPP_REPO/releases"
exit 1
fi
}
# --- Main install logic ---
zopp_install() {
zopp_detect_platform
zopp_log ""
zopp_log "zopp installer v$ZOPP_INSTALLER_VERSION"
zopp_log ""
zopp_log "Detected: $ZOPP_PLATFORM_DISPLAY"
zopp_fetch_version
zopp_log "Latest: zopp $VERSION"
zopp_log ""
# Set up temp directory
ZOPP_TMPDIR=$(mktemp -d)
trap 'rm -rf "$ZOPP_TMPDIR"' EXIT
ARCHIVE_NAME="zopp-$ZOPP_TARGET.tar.gz"
DOWNLOAD_URL="https://github.com/$ZOPP_REPO/releases/download/$VERSION/$ARCHIVE_NAME"
CHECKSUMS_URL="https://github.com/$ZOPP_REPO/releases/download/$VERSION/checksums.txt"
# Download archive
printf " Downloading..."
if curl -fsSL -o "$ZOPP_TMPDIR/$ARCHIVE_NAME" "$DOWNLOAD_URL"; then
zopp_log_success ""
else
printf "\n"
zopp_log_error "Download failed."
zopp_log " URL: $DOWNLOAD_URL"
zopp_log " Check your internet connection and try again."
exit 1
fi
# Download checksums and verify
printf " Verifying checksum..."
if curl -fsSL -o "$ZOPP_TMPDIR/checksums.txt" "$CHECKSUMS_URL"; then
zopp_verify_checksum "$ZOPP_TMPDIR/$ARCHIVE_NAME" "$ZOPP_TMPDIR/checksums.txt" "$ARCHIVE_NAME"
zopp_log_success "(SHA256 matched)"
else
printf "\n"
zopp_log_error "Could not download checksums.txt. Cannot verify download integrity."
zopp_log " URL: $CHECKSUMS_URL"
zopp_log " Check your internet connection and try again."
exit 1
fi
# Extract
tar -xzf "$ZOPP_TMPDIR/$ARCHIVE_NAME" -C "$ZOPP_TMPDIR"
# Install
mkdir -p "$ZOPP_INSTALL_DIR"
printf " Installing to %s..." "$ZOPP_INSTALL_DIR/zopp"
if mv "$ZOPP_TMPDIR/zopp" "$ZOPP_INSTALL_DIR/zopp" 2>/dev/null; then
chmod +x "$ZOPP_INSTALL_DIR/zopp"
zopp_log_success ""
else
printf "\n"
zopp_log_error "Could not install to $ZOPP_INSTALL_DIR."
zopp_log " Permission denied. Try setting a custom install directory:"
zopp_log " ZOPP_INSTALL_DIR=/path/to/writable/dir sh install.sh"
exit 1
fi
zopp_log ""
zopp_log "zopp $VERSION installed successfully!"
# PATH check
case ":$PATH:" in
*":$ZOPP_INSTALL_DIR:"*)
;;
*)
zopp_log ""
zopp_log_warn "$ZOPP_INSTALL_DIR is not in your PATH."
zopp_log " Add it by running:"
zopp_log " export PATH=\"$ZOPP_INSTALL_DIR:\$PATH\""
zopp_log ""
zopp_log " To make it permanent, add that line to your shell profile:"
zopp_log " ~/.bashrc, ~/.zshrc, or ~/.profile"
;;
esac
zopp_log ""
zopp_log "Next: Run \`zopp join <invite-token> you@email.com\` to get started."
zopp_log "Docs: https://zopp.dev/quickstart"
zopp_log ""
}
# Parse flags
for arg in "$@"; do
case "$arg" in
--no-color) NO_COLOR=1 ;;
esac
done
zopp_install