This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·185 lines (156 loc) · 4.78 KB
/
install.sh
File metadata and controls
executable file
·185 lines (156 loc) · 4.78 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
#!/usr/bin/env bash
# FTL CLI Installation Script
# Detects platform and architecture, downloads the appropriate binary
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Configuration
REPO="fastertools/ftl"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
BINARY_NAME="ftl"
# Helper functions
error() {
echo -e "${RED}Error: $1${NC}" >&2
exit 1
}
success() {
echo -e "${GREEN}$1${NC}"
}
info() {
echo -e "${YELLOW}$1${NC}"
}
# Detect OS and architecture
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux*)
PLATFORM="linux"
;;
Darwin*)
PLATFORM="darwin"
;;
*)
error "Unsupported operating system: $OS"
;;
esac
case "$ARCH" in
x86_64|amd64)
ARCH="amd64"
;;
arm64|aarch64)
ARCH="arm64"
;;
*)
error "Unsupported architecture: $ARCH"
;;
esac
echo "${PLATFORM}-${ARCH}"
}
# Get the latest CLI release version
get_latest_version() {
local url="https://api.github.com/repos/${REPO}/releases"
# Get releases and filter for CLI releases (cli-v*)
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" | grep '"tag_name":' | grep '"cli-v' | head -1 | sed -E 's/.*"([^"]+)".*/\1/'
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$url" | grep '"tag_name":' | grep '"cli-v' | head -1 | sed -E 's/.*"([^"]+)".*/\1/'
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Download and install the binary
install_ftl() {
local version="${1:-$(get_latest_version)}"
local platform="$(detect_platform)"
if [ -z "$version" ]; then
error "Could not determine the latest version"
fi
info "Installing FTL CLI ${version} for ${platform}..."
# Strip 'cli-v' prefix from version for archive name
local version_num="${version#cli-v}"
local archive_name="ftl-${version_num}-${platform}.tar.gz"
local download_url="https://github.com/${REPO}/releases/download/${version}/${archive_name}"
# Create temporary directory
local tmp_dir="$(mktemp -d)"
trap "rm -rf $tmp_dir" EXIT
cd "$tmp_dir"
# Download the archive
info "Downloading from ${download_url}..."
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$archive_name" "$download_url" || error "Failed to download FTL CLI"
else
wget -q -O "$archive_name" "$download_url" || error "Failed to download FTL CLI"
fi
# Extract the archive
info "Extracting..."
tar xzf "$archive_name" || error "Failed to extract archive"
# Find the binary
local binary_path="ftl"
if [ ! -f "$binary_path" ]; then
error "Binary not found in archive"
fi
# Check if we need sudo for installation
local use_sudo=""
if [ "$INSTALL_DIR" = "/usr/local/bin" ] && [ "$EUID" -ne 0 ]; then
if command -v sudo >/dev/null 2>&1; then
use_sudo="sudo"
info "Installing to $INSTALL_DIR (requires sudo)..."
else
error "Installation to $INSTALL_DIR requires root privileges"
fi
fi
# Install the binary
chmod +x "$binary_path"
$use_sudo mkdir -p "$INSTALL_DIR"
$use_sudo mv "$binary_path" "$INSTALL_DIR/$BINARY_NAME"
# Verify installation
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
success "FTL CLI installed successfully!"
info "Version: $("$BINARY_NAME" --version)"
else
if [ -f "$INSTALL_DIR/$BINARY_NAME" ]; then
info "FTL CLI installed to $INSTALL_DIR/$BINARY_NAME"
info "Make sure $INSTALL_DIR is in your PATH"
else
error "Installation failed"
fi
fi
}
# Main execution
main() {
echo "FTL CLI Installer"
echo "================="
echo
# Parse arguments
local version=""
while [ $# -gt 0 ]; do
case "$1" in
--version|-v)
version="$2"
shift 2
;;
--install-dir|-d)
INSTALL_DIR="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -v, --version VERSION Install a specific version"
echo " -d, --install-dir DIR Installation directory (default: /usr/local/bin)"
echo " -h, --help Show this help message"
exit 0
;;
*)
error "Unknown option: $1"
;;
esac
done
install_ftl "$version"
}
main "$@"