-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·96 lines (84 loc) · 2.14 KB
/
install.sh
File metadata and controls
executable file
·96 lines (84 loc) · 2.14 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
#!/bin/bash
set -euo pipefail
REPO="fatwang2/search1api-cli"
BINARY_NAME="s1"
# Detect OS
OS="$(uname -s)"
case "$OS" in
Darwin) OS="darwin" ;;
Linux) OS="linux" ;;
*)
echo "Error: Unsupported operating system: $OS"
echo "Please install via npm: npm install -g search1api-cli"
exit 1
;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
*)
echo "Error: Unsupported architecture: $ARCH"
echo "Please install via npm: npm install -g search1api-cli"
exit 1
;;
esac
ASSET_NAME="s1-${OS}-${ARCH}"
echo "Detected platform: ${OS}-${ARCH}"
# Get latest version
echo "Fetching latest release..."
LATEST_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
# Determine install directory
INSTALL_DIR="/usr/local/bin"
NEED_SUDO=false
if [ ! -w "$INSTALL_DIR" ]; then
if command -v sudo &>/dev/null; then
NEED_SUDO=true
else
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
fi
INSTALL_PATH="${INSTALL_DIR}/${BINARY_NAME}"
# Download
TMPFILE="$(mktemp)"
echo "Downloading ${ASSET_NAME}..."
if command -v curl &>/dev/null; then
curl -fSL -o "$TMPFILE" "$LATEST_URL"
elif command -v wget &>/dev/null; then
wget -qO "$TMPFILE" "$LATEST_URL"
else
echo "Error: curl or wget is required"
exit 1
fi
chmod +x "$TMPFILE"
# Install
if [ "$NEED_SUDO" = true ]; then
echo "Installing to ${INSTALL_PATH} (requires sudo)..."
sudo mv "$TMPFILE" "$INSTALL_PATH"
else
echo "Installing to ${INSTALL_PATH}..."
mv "$TMPFILE" "$INSTALL_PATH"
fi
# Verify
if command -v "$BINARY_NAME" &>/dev/null; then
VERSION="$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")"
echo ""
echo "Successfully installed s1 v${VERSION}"
echo ""
echo "Get started:"
echo " s1 login"
echo " s1 search \"your query\""
echo ""
echo "Get your API key at https://search1api.com"
else
echo ""
echo "Installed to ${INSTALL_PATH}"
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
echo ""
echo "Note: ${INSTALL_DIR} is not in your PATH."
echo "Add it by running:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
fi