Skip to content

Commit ee3f9f1

Browse files
Merge pull request #7 from agent-netizen/develop
✨ Add support for MacOS in install script
2 parents afdc61c + 49d5195 commit ee3f9f1

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

install.sh

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
#!/bin/bash
2+
23
if [ "$(id -u)" -ne 0 ]; then
34
echo "This script must be run as root or with sudo."
45
exit 1
56
fi
67

8+
9+
PLATFORM=$(uname | tr "[:upper:]" "[:lower:]")
10+
ARCHITECTURE=$(uname -m | sed -e "s/^x86_64$/amd64/" -e "s/^aarch64$/arm64/")
11+
OS_ARCH=$(echo "$PLATFORM"_"$ARCHITECTURE")
712
REPO_URL="https://api.github.com/repos/CosmicPredator/chibi-cli/releases/latest"
813
BINARY_NAME="chibi"
914
INSTALL_PATH="/usr/local/bin/$BINARY_NAME"
10-
CONFIG_DIR="/home/$SUDO_USER/.config/chibi"
11-
OS_ARCH="linux_amd64"
1215

1316
install_binary() {
17+
18+
echo "Platform: $PLATFORM Arch: $ARCHITECTURE"
19+
20+
if [ "$PLATFORM" == "darwin" ] && ! command -v jq > /dev/null 2>&1; then
21+
tools_path=$(xcode-select -p 2>/dev/null)
22+
if [ -z "$tools_path" ]; then
23+
echo "Error: Either install jq or enable command line tools. To enable command line tools run 'xcode-select --install'"
24+
exit 1
25+
fi
26+
fi
27+
1428
echo "Fetching the latest release information..."
1529

1630
if command -v curl > /dev/null 2>&1; then
@@ -22,22 +36,35 @@ install_binary() {
2236
exit 1
2337
fi
2438

25-
DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r ".assets[] | select(.name | test(\"$OS_ARCH\")) | .browser_download_url")
39+
if command -v jq > /dev/null 2>&1; then
40+
DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r ".assets[] | select(.name | test(\"$OS_ARCH\")) | .browser_download_url")
41+
elif command -v python3 > /dev/null 2>&1; then
42+
DOWNLOAD_URL=$(echo "$RELEASE_INFO" | python3 -c "import sys, json; data = json.load(sys.stdin); print(next(asset['browser_download_url'] for asset in data['assets'] if '$OS_ARCH' in asset['name']))")
43+
else
44+
echo "Error: Neither jq or python3 is installed"
45+
fi
2646

2747
if [ -z "$DOWNLOAD_URL" ]; then
2848
echo "Error: No binary found for $OS_ARCH in the latest release."
2949
exit 1
3050
fi
3151

3252
echo "Downloading $BINARY_NAME from $DOWNLOAD_URL..."
33-
wget -O "$BINARY_NAME" "$DOWNLOAD_URL"
53+
54+
if command -v wget > /dev/null 2>&1; then
55+
wget -O "$BINARY_NAME" "$DOWNLOAD_URL"
56+
else
57+
curl -L -o "$BINARY_NAME" "$DOWNLOAD_URL"
58+
fi
3459

3560
if [ ! -f "$BINARY_NAME" ]; then
3661
echo "Error: Failed to download $BINARY_NAME."
3762
exit 1
3863
fi
3964

4065
echo "Installing $BINARY_NAME to $INSTALL_PATH..."
66+
67+
mkdir -p "$(dirname "$INSTALL_PATH")"
4168
mv "$BINARY_NAME" "$INSTALL_PATH"
4269

4370
chmod +x "$INSTALL_PATH"
@@ -66,6 +93,12 @@ uninstall_binary() {
6693
exit 1
6794
fi
6895

96+
if [ "$PLATFORM" == "darwin" ]; then
97+
CONFIG_DIR="$HOME/Library/Application Support/chibi"
98+
else
99+
CONFIG_DIR="/home/$SUDO_USER/.config/chibi"
100+
fi
101+
69102
if [ -d "$CONFIG_DIR" ]; then
70103
echo "Removing $CONFIG_DIR directory..."
71104
rm -rf "$CONFIG_DIR"
@@ -81,6 +114,8 @@ uninstall_binary() {
81114
fi
82115
}
83116

117+
118+
84119
if [ "$1" == "--uninstall" ]; then
85120
uninstall_binary
86121
else

0 commit comments

Comments
 (0)