-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode-install
More file actions
executable file
·58 lines (51 loc) · 1.79 KB
/
Copy pathopencode-install
File metadata and controls
executable file
·58 lines (51 loc) · 1.79 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
#!/bin/sh
################################################################################
#
# opencode-install
#
# Install/Update OpenCode for current user. This also works as a version manager.
# If version is not specified, the latest version will be installed.
#
# Homepage: https://opencode.ai/
#
# Usage:
# opencode-install [<version>]
#
# Example:
# opencode-install
# opencode-install 1.3.17
# opencode-install v1.3.17
#
# MIT License.
# Copyright (C) 2025 Nguyen Nhat Tung.
#
################################################################################
set -e
# Application info
PROGRAM_ID="opencode"
PROGRAM_EXEC="opencode"
# Shared library
CTXDIR="$(cd "$(dirname "$0")" && pwd)"
. "${CTXDIR}/shared/install-common.sh"
. "${CTXDIR}/shared/install-source.sh"
# Prepare environment
GITHUB_OWNER="$(get_source_owner "${PROGRAM_ID}")"
GITHUB_REPO="$(get_source_repo "${PROGRAM_ID}")"
get_install_version_from_github "${GITHUB_OWNER}" "${GITHUB_REPO}" "$1"
init_install_env "${PROGRAM_ID}" "${INSTALL_VERSION}"
# Download and install binaries
if [ ! -d "${INSTALL_TARGET}" ]; then
BIN_ARCH_URI_AMD64="$(get_download_uri_amd64 "${PROGRAM_ID}" "${INSTALL_VERSION}")"
BIN_ARCH_URI_ARM64="$(get_download_uri_arm64 "${PROGRAM_ID}" "${INSTALL_VERSION}")"
BIN_ARCH_TMP_FILE="${TEMP_TARGET}.zip"
download_uri_per_arch "${BIN_ARCH_URI_AMD64}" "${BIN_ARCH_URI_ARM64}" "${BIN_ARCH_TMP_FILE}"
create_dir "${TEMP_TARGET}"
extract_archive "${BIN_ARCH_TMP_FILE}" "zip" "${TEMP_TARGET}"
remove_item "${BIN_ARCH_TMP_FILE}"
move_item_overwrite "${TEMP_TARGET}" "${INSTALL_TARGET}"
remove_item "${TEMP_TARGET}"
fi
# Finalize install
symlink_item_overwrite "${INSTALL_TARGET}" "${ACTIVE_TARGET}"
symlink_item_overwrite "${ACTIVE_TARGET}/${PROGRAM_EXEC}" "${SYSTEM_BIN_ROOT}/${PROGRAM_ID}"
finalize_install