Skip to content

Commit afdc61c

Browse files
Added linux autoinstall/uninstall script
1 parent 9d81c59 commit afdc61c

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

install.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
if [ "$(id -u)" -ne 0 ]; then
3+
echo "This script must be run as root or with sudo."
4+
exit 1
5+
fi
6+
7+
REPO_URL="https://api.github.com/repos/CosmicPredator/chibi-cli/releases/latest"
8+
BINARY_NAME="chibi"
9+
INSTALL_PATH="/usr/local/bin/$BINARY_NAME"
10+
CONFIG_DIR="/home/$SUDO_USER/.config/chibi"
11+
OS_ARCH="linux_amd64"
12+
13+
install_binary() {
14+
echo "Fetching the latest release information..."
15+
16+
if command -v curl > /dev/null 2>&1; then
17+
RELEASE_INFO=$(curl -s "$REPO_URL")
18+
elif command -v wget > /dev/null 2>&1; then
19+
RELEASE_INFO=$(wget -q -O- "$REPO_URL")
20+
else
21+
echo "Error: Neither curl nor wget is installed."
22+
exit 1
23+
fi
24+
25+
DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r ".assets[] | select(.name | test(\"$OS_ARCH\")) | .browser_download_url")
26+
27+
if [ -z "$DOWNLOAD_URL" ]; then
28+
echo "Error: No binary found for $OS_ARCH in the latest release."
29+
exit 1
30+
fi
31+
32+
echo "Downloading $BINARY_NAME from $DOWNLOAD_URL..."
33+
wget -O "$BINARY_NAME" "$DOWNLOAD_URL"
34+
35+
if [ ! -f "$BINARY_NAME" ]; then
36+
echo "Error: Failed to download $BINARY_NAME."
37+
exit 1
38+
fi
39+
40+
echo "Installing $BINARY_NAME to $INSTALL_PATH..."
41+
mv "$BINARY_NAME" "$INSTALL_PATH"
42+
43+
chmod +x "$INSTALL_PATH"
44+
45+
if [ -x "$INSTALL_PATH" ]; then
46+
echo "$BINARY_NAME installed successfully at $INSTALL_PATH"
47+
else
48+
echo "Error: Failed to install $BINARY_NAME."
49+
exit 1
50+
fi
51+
}
52+
53+
uninstall_binary() {
54+
if [ -f "$INSTALL_PATH" ]; then
55+
echo "Uninstalling $BINARY_NAME from $INSTALL_PATH..."
56+
rm -f "$INSTALL_PATH"
57+
58+
if [ ! -f "$INSTALL_PATH" ]; then
59+
echo "$BINARY_NAME uninstalled successfully."
60+
else
61+
echo "Error: Failed to uninstall $BINARY_NAME."
62+
exit 1
63+
fi
64+
else
65+
echo "Error: $BINARY_NAME is not installed."
66+
exit 1
67+
fi
68+
69+
if [ -d "$CONFIG_DIR" ]; then
70+
echo "Removing $CONFIG_DIR directory..."
71+
rm -rf "$CONFIG_DIR"
72+
73+
if [ ! -d "$CONFIG_DIR" ]; then
74+
echo "$CONFIG_DIR removed successfully."
75+
else
76+
echo "Error: Failed to remove $CONFIG_DIR."
77+
exit 1
78+
fi
79+
else
80+
echo "No configuration directory found at $CONFIG_DIR."
81+
fi
82+
}
83+
84+
if [ "$1" == "--uninstall" ]; then
85+
uninstall_binary
86+
else
87+
install_binary
88+
fi
89+
90+
exit 0

0 commit comments

Comments
 (0)