-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·75 lines (64 loc) · 2.01 KB
/
install.sh
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
#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
readonly brain_url="https://raw.githubusercontent.com/neobrains/brain/main/brain.sh"
readonly brain_dir="$HOME/.brain"
readonly brain_bin="/usr/local/bin/brain"
if ! command -v curl &>/dev/null; then
echo -e "${RED}Error: curl is not installed. Please install curl to continue.${NC}"
exit 1
fi
check_sudo() {
if ! sudo -v >/dev/null 2>&1; then
echo -e "${RED}Error: You need to have sudo privileges to install brain${NC}"
exit 1
fi
}
check_jq_installed() {
if ! command -v jq &>/dev/null; then
echo -e "${RED}Error: jq is not installed. Please install jq to continue.${NC}"
echo -e "On apt based systems, you can install it using: sudo apt install jq"
echo -e "For more information, visit https://stedolan.github.io/jq"
exit 1
fi
}
check_jq_installed
echo -e "Installing brain..."
latest_version=$(curl -s https://api.github.com/repos/neobrains/brain/releases/latest | jq -r '.tag_name')
if [ -x "$brain_bin" ]; then
if [[ "$(brain --version)" == *"$latest_version"* ]]; then
echo "brain is already installed and up-to-date."
exit 0
else
read -r -p "Brain is already installed, but there is a new version available. Do you want to update it? (y/n) " answer
if [[ $answer =~ ^[Yy]$ ]]; then
curl -o brain "$brain_url" -L
chmod +x brain
check_sudo
if [ ! -d "$brain_dir" ]; then
mkdir "$brain_dir"
fi
printf '%s' "$latest_version" >"$brain_dir/version"
sudo mv brain "$brain_bin"
sudo chown root:root "$brain_bin"
sudo chmod +x "$brain_bin"
echo -e "${GREEN}brain has been updated.${NC}"
else
echo "Installation aborted."
exit 0
fi
fi
else
curl -o brain "$brain_url" -Ls
chmod +x brain
check_sudo
mkdir -p "$brain_dir"
printf '%s' "$latest_version" >"$brain_dir/version"
sudo mv brain "$brain_bin"
sudo chown root:root "$brain_bin"
sudo chmod +x "$brain_bin"
echo -e "${GREEN}brain installed successfully.${NC}"
fi
exit 0