-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathinstall
More file actions
executable file
·266 lines (235 loc) · 7.23 KB
/
Copy pathinstall
File metadata and controls
executable file
·266 lines (235 loc) · 7.23 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
#!/bin/bash
set -e
GITHUB_REPO="theinterfold/interfold"
BINARY_NAME="interfoldup"
INSTALL_DIR="$HOME/.local/bin"
# Release tag to install. Empty selects the latest release.
REQUESTED_VERSION="${INTERFOLDUP_VERSION:-}"
log_info() {
echo "$1" >&2
}
log_success() {
echo "$1" >&2
}
log_warning() {
echo "$1" >&2
}
log_error() {
echo "$1" >&2
}
detect_platform() {
local os=""
local arch=""
case "$(uname -s)" in
Linux*)
os="linux"
case "$(uname -m)" in
x86_64)
arch="x86_64"
;;
arm64|aarch64)
arch="aarch64"
;;
*)
log_error "Unsupported Linux architecture: $(uname -m)"
exit 1
;;
esac
;;
Darwin*)
os="macos"
case "$(uname -m)" in
x86_64)
arch="aarch64"
log_info "Intel Mac detected - using Apple Silicon binary (runs via Rosetta 2)"
;;
arm64|aarch64)
arch="aarch64"
;;
*)
log_error "Unsupported macOS architecture: $(uname -m)"
exit 1
;;
esac
;;
*)
log_error "Unsupported operating system: $(uname -s)"
exit 1
;;
esac
echo "${os}-${arch}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
download_file() {
local url="$1"
local output="$2"
if command_exists curl; then
curl -fsSL "$url" -o "$output"
elif command_exists wget; then
wget -q "$url" -O "$output"
else
log_error "Neither curl nor wget is available. Please install one of them."
exit 1
fi
}
release_api_url() {
if [ -n "$REQUESTED_VERSION" ]; then
local tag="$REQUESTED_VERSION"
case "$tag" in
v*) ;;
*) tag="v${tag}" ;;
esac
echo "https://api.github.com/repos/${GITHUB_REPO}/releases/tags/${tag}"
else
echo "https://api.github.com/repos/${GITHUB_REPO}/releases/latest"
fi
}
get_latest_release() {
local api_url
api_url=$(release_api_url)
local temp_file=$(mktemp)
log_info "Fetching release information..."
if ! download_file "$api_url" "$temp_file"; then
log_error "Failed to fetch release information from GitHub API"
rm -f "$temp_file"
exit 1
fi
local tag_name=$(grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' "$temp_file" | cut -d'"' -f4)
if [ -z "$tag_name" ]; then
log_error "Failed to parse release information"
rm -f "$temp_file"
exit 1
fi
rm -f "$temp_file"
echo "$tag_name"
}
get_download_url() {
local platform="$1"
local api_url
api_url=$(release_api_url)
local temp_file=$(mktemp)
if ! download_file "$api_url" "$temp_file"; then
log_error "Failed to fetch release information"
rm -f "$temp_file"
exit 1
fi
local asset_pattern="${BINARY_NAME}-${platform}"
local download_url=$(grep -o '"browser_download_url"[[:space:]]*:[[:space:]]*"[^"]*'"$asset_pattern"'[^"]*"' "$temp_file" | cut -d'"' -f4)
if [ -z "$download_url" ]; then
log_error "No compatible binary found for platform: $platform"
log_info "Available assets:"
grep -o '"name"[[:space:]]*:[[:space:]]*"[^"]*"' "$temp_file" | cut -d'"' -f4 | sed 's/^/ - /'
rm -f "$temp_file"
exit 1
fi
rm -f "$temp_file"
echo "$download_url"
}
usage() {
cat <<EOF
Usage: install [--version TAG]
Options:
--version TAG Release tag of interfoldup to install, for example v0.13.0.
Default: the latest release. Also settable with the
INTERFOLDUP_VERSION environment variable.
-h, --help Show this message.
EOF
}
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--version)
if [ -z "${2:-}" ]; then
log_error "--version needs a release tag, for example v0.13.0"
exit 1
fi
REQUESTED_VERSION="$2"
shift 2
;;
--version=*)
REQUESTED_VERSION="${1#--version=}"
if [ -z "$REQUESTED_VERSION" ]; then
log_error "--version needs a release tag, for example v0.13.0"
exit 1
fi
shift
;;
-h|--help)
usage
exit 0
;;
*)
log_error "Unknown option: $1"
usage >&2
exit 1
;;
esac
done
}
main() {
log_info "Interfold Installer"
parse_args "$@"
local platform
platform=$(detect_platform)
log_info "Detected platform: $platform"
local version
version=$(get_latest_release)
log_info "Version: $version"
local download_url
download_url=$(get_download_url "$platform")
log_info "Download URL: $download_url"
log_info "Creating install directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
local temp_file=$(mktemp)
local asset_name=$(basename "$download_url")
log_info "Downloading $asset_name..."
if ! download_file "$download_url" "$temp_file"; then
log_error "Failed to download $asset_name"
rm -f "$temp_file"
exit 1
fi
local target_path="$INSTALL_DIR/$BINARY_NAME"
log_info "Extracting to $target_path..."
if ! tar -xzf "$temp_file" -C "$INSTALL_DIR" --strip-components=0 "$BINARY_NAME" 2>/dev/null; then
# Extracting without specifying the binary name (in case the structure is different)
if ! tar -xzf "$temp_file" -O | dd of="$target_path" 2>/dev/null; then
log_error "Failed to extract binary from tarball"
rm -f "$temp_file"
exit 1
fi
fi
rm -f "$temp_file"
chmod +x "$target_path"
log_success "Successfully installed $BINARY_NAME to $target_path"
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
log_warning "$INSTALL_DIR is not in your PATH"
echo ""
echo "To add it to your PATH, run one of the following:"
echo ""
echo " # For bash users:"
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc"
echo " source ~/.bashrc"
echo ""
echo " # For zsh users:"
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc"
echo " source ~/.zshrc"
echo ""
echo " # For fish users:"
echo " fish_add_path $INSTALL_DIR"
echo ""
fi
echo ""
log_success "Installation complete!"
echo ""
echo "You can now use $BINARY_NAME to install the Interfold CLI:"
echo ""
echo " $BINARY_NAME install # Install the latest interfold CLI"
echo " $BINARY_NAME install --version v0.13.0 # Install a specific release"
echo " $BINARY_NAME update # Update to the latest version"
echo " $BINARY_NAME uninstall # Remove the interfold CLI"
echo " $BINARY_NAME --help # Show help"
echo ""
}
main "$@"