-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·127 lines (103 loc) · 3.53 KB
/
install.sh
File metadata and controls
executable file
·127 lines (103 loc) · 3.53 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
#!/bin/sh
set -e
# SFK CLI Installer
# Usage: curl -fsSL https://raw.githubusercontent.com/starfolkai/cli/main/install.sh | sh
REPO="starfolkai/cli"
BINARY_NAME="sfk"
INSTALL_DIR="${SFK_INSTALL_DIR:-$HOME/.local/bin}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { printf "${GREEN}info${NC}: %s\n" "$1"; }
warn() { printf "${YELLOW}warn${NC}: %s\n" "$1"; }
error() { printf "${RED}error${NC}: %s\n" "$1" >&2; exit 1; }
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
*) error "Unsupported OS: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
PLATFORM="${BINARY_NAME}-${OS}-${ARCH}"
}
get_latest_version() {
# Try API first (may fail due to rate limiting)
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
# If API fails, use GitHub's redirect to get version from Location header
if [ -z "$VERSION" ]; then
VERSION=$(curl -sI "https://github.com/${REPO}/releases/latest" 2>/dev/null | grep -i '^location:' | sed -E 's|.*/tag/([^[:space:]]+).*|\1|')
fi
if [ -z "$VERSION" ]; then
error "Could not determine latest version. Check https://github.com/${REPO}/releases"
fi
}
download_and_install() {
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${PLATFORM}.tar.gz"
info "Downloading SFK CLI ${VERSION} for ${OS}/${ARCH}..."
TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" EXIT
curl -fsSL "$DOWNLOAD_URL" -o "$TMPDIR/sfk.tar.gz"
tar -xzf "$TMPDIR/sfk.tar.gz" -C "$TMPDIR"
info "Installing to ${INSTALL_DIR}..."
mkdir -p "$INSTALL_DIR"
mv "$TMPDIR/$PLATFORM" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
}
check_path() {
case ":$PATH:" in
*":$INSTALL_DIR:"*) return 0 ;;
esac
return 1
}
path_instructions() {
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash) RC_FILE="$HOME/.bashrc" ;;
zsh) RC_FILE="$HOME/.zshrc" ;;
fish) RC_FILE="$HOME/.config/fish/config.fish" ;;
*) RC_FILE="your shell rc file" ;;
esac
warn "$INSTALL_DIR is not in your PATH"
echo ""
echo "Add it by running:"
echo ""
if [ "$SHELL_NAME" = "fish" ]; then
echo " fish_add_path $INSTALL_DIR"
else
echo " echo 'export PATH=\"\$PATH:$INSTALL_DIR\"' >> $RC_FILE"
fi
echo ""
echo "Then restart your shell or run: source $RC_FILE"
}
main() {
echo ""
echo " ███████╗███████╗██╗ ██╗"
echo " ██╔════╝██╔════╝██║ ██╔╝"
echo " ███████╗█████╗ █████╔╝ "
echo " ╚════██║██╔══╝ ██╔═██╗ "
echo " ███████║██║ ██║ ██╗"
echo " ╚══════╝╚═╝ ╚═╝ ╚═╝"
echo ""
echo " Your Agent gets a Laptop in the Cloud"
echo ""
detect_platform
get_latest_version
download_and_install
echo ""
printf "${GREEN}Successfully installed SFK CLI ${VERSION}!${NC}\n"
echo ""
if ! check_path; then
path_instructions
else
echo "Run 'sfk --help' to get started."
fi
echo ""
}
main