Files

313 lines
13 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# shellcheck disable=SC2086
# VSCodium (codium) 공식 가이드 기반 자동 설치 스크립트
# 공식 사이트: https://vscodium.com/
# 공식 GitHub: https://github.com/VSCodium/vscodium
#
# VS Code 오픈소스에서 불필요한 원격 측정(Telemetry)/추적기 및 독점 요소를 제거하고
# 개발에 필요한 핵심 기능만 깔끔하게 남긴 순수 오픈소스 바이너리 에디터입니다.
#
# 지원 플랫폼:
# macOS : Homebrew Cask (brew install --cask vscodium) + GitHub Release 폴백
# Linux :
# - Debian / Ubuntu / Mint : 공식 APT 저장소 등록 및 설치
# - Fedora / RHEL / Rocky / Alma / openSUSE : 공식 RPM 저장소 등록 및 설치
# - Arch Linux : AUR 헬퍼(yay/paru) 또는 Snap / GitHub Release tarball 폴백
# - 범용 폴백 : GitHub Releases 정식 바이너리 (VSCodium-linux-<arch>-<tag>.tar.gz)
set -euo pipefail
# ────────────────────────────────────────────
# 상수 정의
# ────────────────────────────────────────────
REPO="VSCodium/vscodium"
API_URL="https://api.github.com/repos/${REPO}/releases"
FALLBACK_TAG="1.96.2.24355"
INSTALL_DIR="${HOME}/.local/bin"
OPT_DIR="${HOME}/.local/share/vscodium"
GPG_KEY_URL="https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg"
# ────────────────────────────────────────────
# 유틸리티 함수 (모두 stderr 출력)
# ────────────────────────────────────────────
info() { echo "[INFO] $*" >&2; }
warn() { echo "[WARN] $*" >&2; }
error() { echo "[ERROR] $*" >&2; exit 1; }
success() { echo "[OK] $*" >&2; }
# ────────────────────────────────────────────
# 필수 명령어 확인
# ────────────────────────────────────────────
for cmd in curl uname; do
command -v "$cmd" &>/dev/null || error "'$cmd' 명령어가 필요합니다."
done
# ────────────────────────────────────────────
# macOS용 Homebrew 확인 및 설치
# ────────────────────────────────────────────
ensure_brew() {
if command -v brew &>/dev/null; then
return 0
fi
info "Homebrew가 설치되어 있지 않습니다. Homebrew 설치를 진행합니다..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ -d /opt/homebrew/bin ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
if [ -d /usr/local/bin ]; then
export PATH="/usr/local/bin:$PATH"
fi
command -v brew &>/dev/null || return 1
success "Homebrew 설치 완료"
}
# ────────────────────────────────────────────
# GitHub API에서 에셋이 존재하는 최신 릴리스 태그 조회
# ────────────────────────────────────────────
if command -v jq &>/dev/null; then
_json_latest_tag() {
jq -r '[.[] | select(.prerelease==false and ((.assets | length) > 0))] | .[0].tag_name'
}
elif command -v python3 &>/dev/null; then
_json_latest_tag() {
python3 -c "
import sys, json
data = json.load(sys.stdin)
for r in data:
if not r.get('prerelease') and r.get('assets'):
print(r.get('tag_name', ''))
break
"
}
else
_json_latest_tag() {
grep -oE '"tag_name":[[:space:]]*"[^"]+"' | head -1 | sed -E 's/.*"([^"]+)"$/\1/'
}
fi
get_latest_tag() {
info "GitHub API에서 VSCodium 최신 릴리스 버전을 조회하는 중..."
local releases="" tag=""
releases="$(curl -fsSL -H "User-Agent: install-codium-sh" --connect-timeout 10 "${API_URL}" 2>/dev/null)" || true
if [[ -n "$releases" ]]; then
tag="$(echo "$releases" | _json_latest_tag 2>/dev/null || true)"
fi
if [[ -z "$tag" || "$tag" == "null" ]]; then
warn "GitHub API 조회 실패. 검증된 폴백 버전(${FALLBACK_TAG})을 사용합니다."
tag="${FALLBACK_TAG}"
fi
echo "$tag"
}
# ────────────────────────────────────────────
# Linux 공식 APT 저장소 설치 (Debian / Ubuntu / Mint)
# https://vscodium.com/#install-on-debian-ubuntu-deb-package
# ────────────────────────────────────────────
install_linux_apt() {
info "Debian/Ubuntu 계열 감지: 공식 VSCodium APT 저장소를 구성합니다..."
sudo apt-get update -y 2>/dev/null || true
sudo apt-get install -y wget gpg apt-transport-https 2>/dev/null || true
# 1. GPG 키 등록
curl -fsSL "${GPG_KEY_URL}" | gpg --dearmor | sudo dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg 2>/dev/null
# 2. APT 저장소 등록
echo 'deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg] https://download.vscodium.com/debs vscodium main' |
sudo tee /etc/apt/sources.list.d/vscodium.list >/dev/null
# 3. 패키지 업데이트 및 codium 설치
sudo apt-get update -y
sudo apt-get install -y codium
success "APT 공식 저장소를 통해 VSCodium (codium) 설치 완료!"
}
# ────────────────────────────────────────────
# Linux 공식 RPM 저장소 설치 (Fedora / RHEL / Rocky / openSUSE)
# https://vscodium.com/#install-on-fedora-rhel-opensuse-rpm-package
# ────────────────────────────────────────────
install_linux_rpm() {
info "RHEL/Fedora/openSUSE 계열 감지: 공식 VSCodium RPM 저장소를 구성합니다..."
sudo rpmkeys --import "${GPG_KEY_URL}"
if command -v dnf &>/dev/null || command -v yum &>/dev/null; then
printf "[gitlab.com_paulcarroty_vscodium_repo]\nname=download.vscodium.com\nbaseurl=https://download.vscodium.com/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=${GPG_KEY_URL}\nmetadata_expire=1h\n" |
sudo tee /etc/yum.repos.d/vscodium.repo >/dev/null
if command -v dnf &>/dev/null; then
sudo dnf install -y codium
else
sudo yum install -y codium
fi
success "DNF/YUM 공식 저장소를 통해 VSCodium (codium) 설치 완료!"
elif command -v zypper &>/dev/null; then
printf "[gitlab.com_paulcarroty_vscodium_repo]\nname=gitlab.com_paulcarroty_vscodium_repo\nbaseurl=https://download.vscodium.com/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=${GPG_KEY_URL}\nmetadata_expire=1h\n" |
sudo tee /etc/zypp/repos.d/vscodium.repo >/dev/null
sudo zypper -n --gpg-auto-import-keys refresh
sudo zypper -n install codium
success "Zypper 공식 저장소를 통해 VSCodium (codium) 설치 완료!"
else
return 1
fi
}
# ────────────────────────────────────────────
# GitHub Releases 직접 다운로드 폴백 (Linux / macOS)
# ────────────────────────────────────────────
install_from_github_tarball() {
local os="$1"
local arch="$2"
local codium_arch=""
case "$arch" in
x86_64 | amd64) codium_arch="x64" ;;
aarch64 | arm64) codium_arch="arm64" ;;
armv7l | armhf) codium_arch="armhf" ;;
*) error "지원하지 않는 아키텍처입니다: $arch" ;;
esac
local tag
tag="$(get_latest_tag)"
info "GitHub Releases에서 VSCodium (${tag}) 바이너리를 다운로드합니다..."
local tmpdir
tmpdir="$(mktemp -d)"
trap '[[ -d "${tmpdir:-}" ]] && rm -rf "$tmpdir"' EXIT
if [[ "$os" == "Darwin" ]]; then
local filename="VSCodium-darwin-${codium_arch}-${tag}.zip"
local url="https://github.com/${REPO}/releases/download/${tag}/${filename}"
local fallback_url="https://github.com/${REPO}/releases/download/${FALLBACK_TAG}/VSCodium-darwin-${codium_arch}-${FALLBACK_TAG}.zip"
info "다운로드 중: $url"
if ! curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url"; then
warn "최신 버전 다운로드 실패. 폴백 버전(${FALLBACK_TAG})으로 재시도합니다: $fallback_url"
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$fallback_url" ||
error "다운로드 실패: $fallback_url"
fi
info "/Applications 경로에 압축 해제 중..."
unzip -q -o "${tmpdir}/${filename}" -d "/Applications"
mkdir -p "$INSTALL_DIR"
ln -sf "/Applications/VSCodium.app/Contents/Resources/app/bin/codium" "${INSTALL_DIR}/codium"
success "VSCodium.app 설치 및 ${INSTALL_DIR}/codium 심볼릭 링크 생성 완료!"
else
local filename="VSCodium-linux-${codium_arch}-${tag}.tar.gz"
local url="https://github.com/${REPO}/releases/download/${tag}/${filename}"
local fallback_url="https://github.com/${REPO}/releases/download/${FALLBACK_TAG}/VSCodium-linux-${codium_arch}-${FALLBACK_TAG}.tar.gz"
info "다운로드 중: $url"
if ! curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url"; then
warn "최신 버전 다운로드 실패. 폴백 버전(${FALLBACK_TAG})으로 재시도합니다: $fallback_url"
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$fallback_url" ||
error "다운로드 실패: $fallback_url"
fi
info "${OPT_DIR} 경로에 압축 해제 중..."
rm -rf "$OPT_DIR"
mkdir -p "$OPT_DIR"
tar -xzf "${tmpdir}/${filename}" -C "$OPT_DIR"
mkdir -p "$INSTALL_DIR"
ln -sf "${OPT_DIR}/bin/codium" "${INSTALL_DIR}/codium"
success "VSCodium 리눅스 바이너리 배포 및 ${INSTALL_DIR}/codium 연결 완료!"
fi
}
# ────────────────────────────────────────────
# 메인 설치 로직
# ────────────────────────────────────────────
main() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
info "===== VSCodium (codium) 설치 스크립트 ====="
info "감지된 환경: OS=${os}, ARCH=${arch}"
if command -v codium &>/dev/null; then
info "이미 codium이 설치되어 있습니다: $(command -v codium)"
codium --version 2>/dev/null | head -n 1 || true
fi
case "$os" in
Darwin)
info "macOS 환경에서 공식 권장 방식(Homebrew Cask)으로 설치를 시도합니다..."
if ensure_brew && brew install --cask vscodium; then
success "Homebrew를 통해 VSCodium이 설치되었습니다!"
if [ -x "/Applications/VSCodium.app/Contents/Resources/app/bin/codium" ]; then
mkdir -p "$INSTALL_DIR"
ln -sf "/Applications/VSCodium.app/Contents/Resources/app/bin/codium" "${INSTALL_DIR}/codium" 2>/dev/null || true
fi
else
warn "Homebrew Cask 설치 실패. GitHub Releases 직접 다운로드 방식으로 전환합니다..."
install_from_github_tarball "$os" "$arch"
fi
;;
Linux)
local installed="false"
# 1. Debian / Ubuntu 계열 (apt-get)
if command -v apt-get &>/dev/null && command -v sudo &>/dev/null; then
if install_linux_apt; then
installed="true"
fi
# 2. Fedora / RHEL / openSUSE 계열 (dnf / yum / zypper)
elif (command -v dnf &>/dev/null || command -v yum &>/dev/null || command -v zypper &>/dev/null) && command -v sudo &>/dev/null; then
if install_linux_rpm; then
installed="true"
fi
# 3. Arch Linux 계열 (yay / paru)
elif command -v pacman &>/dev/null; then
if command -v yay &>/dev/null; then
info "Arch Linux 감지: yay를 통해 vscodium-bin을 설치합니다..."
if yay -S --noconfirm vscodium-bin; then
installed="true"
fi
elif command -v paru &>/dev/null; then
info "Arch Linux 감지: paru를 통해 vscodium-bin을 설치합니다..."
if paru -S --noconfirm vscodium-bin; then
installed="true"
fi
fi
fi
# 4. 패키지 매니저 설치 실패 또는 비루트 환경일 경우 GitHub 공식 tarball 폴백
if [[ "$installed" != "true" ]]; then
warn "배포판 패키지 매니저 설치를 사용할 수 없거나 실패하여 GitHub 공식 릴리스 바이너리로 설치합니다..."
install_from_github_tarball "$os" "$arch"
fi
;;
MINGW* | MSYS* | CYGWIN*)
error "Windows 환경입니다. PowerShell에서 install-codium.ps1을 실행해 주세요."
;;
*)
error "지원하지 않는 운영체제입니다: $os"
;;
esac
# PATH 안내
if ! echo ":${PATH}:" | grep -q ":${INSTALL_DIR}:"; then
export PATH="${INSTALL_DIR}:${PATH}"
warn "'${INSTALL_DIR}' 경로가 PATH에 없을 경우 쉘 설정(~/.bashrc 또는 ~/.zshrc)에 추가하세요:"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
echo "" >&2
info "=================================================="
success "VSCodium (codium) 설치가 완료되었습니다!"
info "=================================================="
info "주요 사용법:"
info " codium . # 현재 디렉토리를 VSCodium으로 열기"
info " codium <file> # 특정 파일 편집"
info " codium --install-extension # Open VSX 확장 플러그인 설치"
info " codium --version # 설치된 버전 확인"
}
main "$@"