-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·192 lines (171 loc) · 6.23 KB
/
install.sh
File metadata and controls
executable file
·192 lines (171 loc) · 6.23 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/sh
set -e
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Function to detect shell and profile file
detect_shell_profile() {
shell=$(basename "$SHELL")
case "$shell" in
bash)
if [ -f "$HOME/.bash_profile" ]; then
echo "$HOME/.bash_profile"
else
echo "$HOME/.bashrc"
fi
;;
zsh)
echo "$HOME/.zshrc"
;;
*)
echo "$HOME/.profile"
;;
esac
}
# Function to update PATH in profile
update_path() {
profile_file="$1"
path_dir="$2"
if ! grep -q "export PATH=\"$path_dir:\$PATH\"" "$profile_file"; then
echo "" >> "$profile_file"
echo "# Add BB to PATH" >> "$profile_file"
echo "export PATH=\"$path_dir:\$PATH\"" >> "$profile_file"
echo "${GREEN}Added BB directory to PATH in $profile_file${NC}"
echo "${YELLOW}Please run: source $profile_file${NC}"
else
echo "${GREEN}BB directory already in PATH ($profile_file)${NC}"
fi
}
# Determine architecture
arch=$(uname -m)
case $arch in
x86_64)
arch="x86_64"
;;
aarch64|arm64)
arch="aarch64"
;;
*)
echo "${RED}Unsupported architecture: $arch${NC}"
exit 1
;;
esac
# Determine OS
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case $os in
linux)
os="unknown-linux-gnu"
;;
darwin)
os="apple-darwin"
;;
*)
echo "${RED}Unsupported OS: $os${NC}"
exit 1
;;
esac
# Check for existing system installation
system_bb="/usr/local/bin/bb"
system_api="/usr/local/bin/bb-api"
system_bui="/usr/local/bin/bb-bui"
has_system_install=false
if [ -f "$system_bb" ] || [ -f "$system_api" ] || [ -f "$system_bui" ]; then
has_system_install=true
fi
# Ask about installation location
user_install="y"
echo "${YELLOW}BB can be installed for the current user (~/.bb/bin) or system-wide (/usr/local/bin).${NC}"
echo "${YELLOW}User installation is recommended as it:${NC}"
echo "${YELLOW}- Doesn't require sudo for future updates${NC}"
echo "${YELLOW}- Enables automatic updates through the browser interface${NC}"
if [ "$has_system_install" = true ]; then
echo "${YELLOW}Note: Choosing user installation will remove existing system-wide installation${NC}"
echo "${YELLOW}(requires sudo password for cleanup)${NC}"
fi
printf "${YELLOW}Install for current user? [Y/n]: ${NC}"
read -r response
[ -n "$response" ] && user_install=$(echo "$response" | tr '[:upper:]' '[:lower:]')
if [ "$user_install" = "n" ] || [ "$user_install" = "no" ]; then
install_dir="/usr/local/bin"
need_sudo=true
else
install_dir="$HOME/.bb/bin"
need_sudo=false
# Ensure ~/.bb/bin exists
mkdir -p "$install_dir"
fi
# Fetch latest release version
latest_version=$(curl -sL https://asyagnmzoxgyhqprdaky.storage.supabase.co/storage/v1/object/releases/latest.json | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# echo "Latest version: $latest_version"
# Download URL
download_url="https://asyagnmzoxgyhqprdaky.storage.supabase.co/storage/v1/object/releases/${latest_version}/bb-${arch}-${os}-${latest_version}.tar.gz"
# echo "Download URL: $download_url"
# Create a temporary directory
temp_dir=$(mktemp -d)
# echo "Temporary directory: $temp_dir"
trap 'rm -rf "$temp_dir"' EXIT
# Download and extract the tarball
echo "${YELLOW}Downloading BB ${latest_version} for ${arch}-${os}...${NC}"
curl -L --progress-bar "$download_url" -o "$temp_dir/bb.tar.gz"
# echo "Download complete. File size: $(wc -c < "$temp_dir/bb.tar.gz") bytes"
# echo "File type: $(file "$temp_dir/bb.tar.gz")"
echo "${YELLOW}Extracting archive...${NC}"
tar xzf "$temp_dir/bb.tar.gz" -C "$temp_dir"
# List contents of temp directory
# echo "Contents of $temp_dir:"
# ls -la "$temp_dir"
# Make binaries executable
chmod +x "$temp_dir/bb" "$temp_dir/bb-api" "$temp_dir/bb-bui"
# Install binaries
echo "${YELLOW}Installing 'bb', 'bb-api' and 'bb-bui' to $install_dir...${NC}"
if [ "$need_sudo" = true ]; then
echo "${RED}Note: This step requires sudo access. You may be prompted for your password.${NC}"
sudo mv "$temp_dir/bb" "$temp_dir/bb-api" "$temp_dir/bb-bui" "$install_dir/"
else
mv "$temp_dir/bb" "$temp_dir/bb-api" "$temp_dir/bb-bui" "$install_dir/"
# Remove system installation if it exists
if [ "$has_system_install" = true ]; then
echo "${YELLOW}Removing system-wide installation...${NC}"
echo "${RED}Note: This step requires sudo access. You may be prompted for your password.${NC}"
if [ -f "$system_bb" ]; then
sudo rm "$system_bb"
fi
if [ -f "$system_api" ]; then
sudo rm "$system_api"
fi
if [ -f "$system_bui" ]; then
sudo rm "$system_bui"
fi
echo "${GREEN}System-wide installation removed successfully${NC}"
fi
fi
echo "${YELLOW}'bb', 'bb-api' and 'bb-bui' have been successfully installed to $install_dir${NC}"
# Update PATH for user installation
if [ "$need_sudo" = false ]; then
profile_file=$(detect_shell_profile)
printf "${YELLOW}Would you like to add $install_dir to your PATH? [Y/n]: ${NC}"
read -r add_path
[ -z "$add_path" ] || [ "$add_path" = "y" ] || [ "$add_path" = "Y" ] && update_path "$profile_file" "$install_dir"
fi
# # Install BB Manager
# echo "${YELLOW}Installing BB Manager...${NC}"
# if [ "$os" = "apple-darwin" ]; then
# echo "${YELLOW}Copying BB Manager.app to /Applications...${NC}"
# sudo cp -R "$temp_dir/BB Manager.app" /Applications/
# echo "${GREEN}BB Manager.app has been installed to /Applications/${NC}"
# else
# manager_path="$install_dir/bb-manager.sh"
# echo "${YELLOW}Copying bb-manager.sh to $manager_path...${NC}"
# if [ "$need_sudo" = true ]; then
# sudo cp "$temp_dir/bb-manager.sh" "$manager_path"
# sudo chmod +x "$manager_path"
# else
# cp "$temp_dir/bb-manager.sh" "$manager_path"
# chmod +x "$manager_path"
# fi
# echo "${GREEN}bb-manager.sh has been installed to $manager_path${NC}"
# fi
echo "${GREEN}You can now run '${BOLD}bb init${NC}${GREEN}' from a project directory, and then run '${BOLD}bb start${NC}${GREEN}' (or '${BOLD}bb chat${NC}${GREEN}').${NC}"