Opencode / install.sh
jerecom's picture
Use custom release from badman99dev/opencode-1 v1.0.1
6e83fef verified
raw
history blame
2.49 kB
#!/usr/bin/env bash
set -euo pipefail
APP=opencode
MUTED='\033[0;2m'
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
NC='\033[0m' # No Color
# Custom version from badman99dev/opencode-1 release
VERSION="v1.0.1"
REPO="badman99dev/opencode-1"
FILENAME="opencode-linux-x64.tar.gz"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${FILENAME}"
INSTALL_DIR=$HOME/.opencode/bin
mkdir -p "$INSTALL_DIR"
print_message() {
local level=$1
local message=$2
local color=""
case $level in
info) color="${NC}" ;;
warning) color="${NC}" ;;
error) color="${RED}" ;;
esac
echo -e "${color}${message}${NC}"
}
download_and_install() {
print_message info "\n${MUTED}Installing ${NC}opencode ${MUTED}version: ${NC}$VERSION"
print_message info "${MUTED}From: ${NC}$URL"
local tmp_dir="${TMPDIR:-/tmp}/opencode_install_$$"
mkdir -p "$tmp_dir"
# Download binary
curl -# -L -o "$tmp_dir/$FILENAME" "$url"
# Extract (Linux tar.gz)
tar -xzf "$tmp_dir/$FILENAME" -C "$tmp_dir"
# Move binary to install directory
mv "$tmp_dir/opencode" "$INSTALL_DIR"
chmod 755 "${INSTALL_DIR}/opencode"
rm -rf "$tmp_dir"
print_message info "${MUTED}Installed successfully to ${NC}$INSTALL_DIR/opencode"
}
# Check if already installed
if command -v opencode >/dev/null 2>&1; then
installed_version=$(opencode --version 2>/dev/null || echo "")
if [[ "$installed_version" == "$VERSION" ]] || [[ "$installed_version" == "${VERSION#v}" ]]; then
print_message info "${MUTED}Version ${NC}$VERSION${MUTED} already installed"
exit 0
fi
fi
# Install
download_and_install
# Add to PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
export PATH="$INSTALL_DIR:$PATH"
print_message info "${MUTED}Added to PATH: ${NC}$INSTALL_DIR"
fi
echo -e ""
echo -e "${MUTED} ${NC} β–„ "
echo -e "${MUTED}β–ˆβ–€β–€β–ˆ β–ˆβ–€β–€β–ˆ β–ˆβ–€β–€β–ˆ β–ˆβ–€β–€β–„ ${NC}β–ˆβ–€β–€β–€ β–ˆβ–€β–€β–ˆ β–ˆβ–€β–€β–ˆ β–ˆβ–€β–€β–ˆ"
echo -e "${MUTED}β–ˆβ–‘β–‘β–ˆ β–ˆβ–‘β–‘β–ˆ β–ˆβ–€β–€β–€ β–ˆβ–‘β–‘β–ˆ ${NC}β–ˆβ–‘β–‘β–‘ β–ˆβ–‘β–‘β–ˆ β–ˆβ–‘β–‘β–ˆ β–ˆβ–€β–€β–€"
echo -e "${MUTED}β–€β–€β–€β–€ β–ˆβ–€β–€β–€ β–€β–€β–€β–€ β–€ β–€ ${NC}β–€β–€β–€β–€ β–€β–€β–€β–€ β–€β–€β–€β–€ β–€β–€β–€β–€"
echo -e ""
echo -e "${MUTED}OpenCode installed from custom release${NC}"
echo -e ""
echo -e "cd <project> ${MUTED}# Open directory${NC}"
echo -e "opencode ${MUTED}# Run command${NC}"
echo -e ""