File size: 2,487 Bytes
be7f980
 
 
 
 
 
 
 
 
6e83fef
 
 
 
 
be7f980
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e83fef
 
 
be7f980
 
 
6e83fef
 
be7f980
6e83fef
 
be7f980
6e83fef
be7f980
 
 
 
6e83fef
be7f980
 
6e83fef
 
 
 
 
 
be7f980
 
 
6e83fef
 
 
 
 
 
 
be7f980
 
 
6e83fef
be7f980
 
 
 
6e83fef
be7f980
 
 
6e83fef
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
#!/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 ""