forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-dev
More file actions
executable file
·204 lines (170 loc) · 6.04 KB
/
install-dev
File metadata and controls
executable file
·204 lines (170 loc) · 6.04 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
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env bash
set -euo pipefail
MUTED='\033[0;2m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[38;5;214m'
NC='\033[0m'
REPO_URL="https://github.com/VibeTechnologies/opencode.git"
BRANCH="${BRANCH:-dev}"
INSTALL_DIR="$HOME/.opencode/bin"
CLONE_DIR="$HOME/.opencode/src"
print_message() {
local level=$1
local message=$2
local color=""
case $level in
info) color="${NC}" ;;
success) color="${GREEN}" ;;
warning) color="${ORANGE}" ;;
error) color="${RED}" ;;
esac
echo -e "${color}${message}${NC}"
}
check_dependencies() {
print_message info "${MUTED}Checking dependencies...${NC}"
if ! command -v git >/dev/null 2>&1; then
print_message error "Error: 'git' is required but not installed."
exit 1
fi
if ! command -v bun >/dev/null 2>&1; then
print_message warning "Bun not found. Installing bun..."
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
if ! command -v bun >/dev/null 2>&1; then
print_message error "Failed to install bun. Please install manually: https://bun.sh"
exit 1
fi
fi
print_message success "Dependencies OK"
}
clone_or_update_repo() {
print_message info "${MUTED}Setting up repository...${NC}"
if [ -d "$CLONE_DIR/.git" ]; then
print_message info "${MUTED}Updating existing clone...${NC}"
cd "$CLONE_DIR"
git fetch origin
git checkout "$BRANCH"
git reset --hard "origin/$BRANCH"
else
print_message info "${MUTED}Cloning repository...${NC}"
rm -rf "$CLONE_DIR"
mkdir -p "$CLONE_DIR"
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$CLONE_DIR"
cd "$CLONE_DIR"
fi
print_message success "Repository ready"
}
detect_platform() {
local raw_os=$(uname -s)
case "$raw_os" in
Darwin*) os="darwin" ;;
Linux*) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
*) os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]') ;;
esac
arch=$(uname -m)
if [[ "$arch" == "aarch64" ]]; then
arch="arm64"
fi
if [[ "$arch" == "x86_64" ]]; then
arch="x64"
fi
if [ "$os" = "darwin" ] && [ "$arch" = "x64" ]; then
rosetta_flag=$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)
if [ "$rosetta_flag" = "1" ]; then
arch="arm64"
fi
fi
PLATFORM="$os-$arch"
}
build_and_install() {
print_message info "${MUTED}Installing dependencies...${NC}"
bun install
print_message info "${MUTED}Building opencode...${NC}"
cd "$CLONE_DIR/packages/opencode"
bun run build
print_message info "${MUTED}Installing binary...${NC}"
mkdir -p "$INSTALL_DIR"
detect_platform
local binary_path="$CLONE_DIR/packages/opencode/dist/opencode-$PLATFORM/bin/opencode"
if [ ! -f "$binary_path" ]; then
print_message error "Binary not found for platform: $PLATFORM"
print_message info "Available platforms:"
ls "$CLONE_DIR/packages/opencode/dist/"
exit 1
fi
cp "$binary_path" "$INSTALL_DIR/opencode"
chmod 755 "$INSTALL_DIR/opencode"
if [ "$os" = "darwin" ]; then
print_message info "${MUTED}Signing binary for macOS...${NC}"
codesign -s - "$INSTALL_DIR/opencode" 2>/dev/null || true
fi
print_message success "Build complete"
}
add_to_path() {
local config_file=$1
local command=$2
if grep -Fxq "$command" "$config_file" 2>/dev/null; then
print_message info "${MUTED}PATH already configured in $config_file${NC}"
elif [[ -w $config_file ]]; then
echo -e "\n# opencode" >> "$config_file"
echo "$command" >> "$config_file"
print_message info "${MUTED}Added opencode to \$PATH in ${NC}$config_file"
else
print_message warning "Manually add to $config_file:"
print_message info " $command"
fi
}
setup_path() {
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
current_shell=$(basename "$SHELL")
case $current_shell in
fish) config_files="$HOME/.config/fish/config.fish" ;;
zsh) config_files="$HOME/.zshrc $HOME/.zshenv $XDG_CONFIG_HOME/zsh/.zshrc" ;;
bash) config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile" ;;
*) config_files="$HOME/.bashrc $HOME/.bash_profile" ;;
esac
config_file=""
for file in $config_files; do
if [[ -f $file ]]; then
config_file=$file
break
fi
done
if [[ -z $config_file ]]; then
print_message warning "No config file found. Manually add to PATH:"
print_message info " export PATH=$INSTALL_DIR:\$PATH"
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
case $current_shell in
fish) add_to_path "$config_file" "fish_add_path $INSTALL_DIR" ;;
*) add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" ;;
esac
fi
}
main() {
echo -e ""
echo -e "${ORANGE}OpenCode Dev Install${NC}"
echo -e "${MUTED}Installing from: ${NC}$REPO_URL ${MUTED}(branch: ${NC}$BRANCH${MUTED})${NC}"
echo -e ""
check_dependencies
clone_or_update_repo
build_and_install
setup_path
VERSION=$(opencode --version 2>/dev/null || echo "unknown")
echo -e ""
echo -e "${MUTED} ${NC} ▄ "
echo -e "${MUTED}█▀▀█ █▀▀█ █▀▀█ █▀▀▄ ${NC}█▀▀▀ █▀▀█ █▀▀█ █▀▀█"
echo -e "${MUTED}█░░█ █░░█ █▀▀▀ █░░█ ${NC}█░░░ █░░█ █░░█ █▀▀▀"
echo -e "${MUTED}▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ${NC}▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀"
echo -e ""
echo -e "${GREEN}Successfully installed!${NC}"
echo -e "${MUTED}Version: ${NC}$VERSION"
echo -e ""
echo -e "${MUTED}To start:${NC}"
echo -e " cd <project>"
echo -e " opencode"
echo -e ""
}
main "$@"