Files
goldenChart/scripts/install-desktop-build-deps.sh
T

146 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# macOS Jenkins / 개발 Mac — GoldenChart Desktop 빌드 의존성 설치
set -euo pipefail
MAC_ONLY=0
while [[ $# -gt 0 ]]; do
case "$1" in
--mac-only) MAC_ONLY=1; shift ;;
*) echo "Unknown arg: $1 (supported: --mac-only)"; exit 1 ;;
esac
done
log() { echo "[install-desktop-deps] $*"; }
if [[ "$(uname -s)" != "Darwin" ]]; then
log "이 스크립트는 macOS용입니다."
exit 1
fi
# Homebrew / Rust PATH (표준 prefix + 사용자 prefix)
prepend_path() {
case ":${PATH}:" in
*":$1:"*) ;;
*) export PATH="$1:$PATH" ;;
esac
}
for prefix in /opt/homebrew "$HOME/homebrew" /usr/local; do
if [[ -x "$prefix/bin/brew" ]]; then
prepend_path "$prefix/bin"
prepend_path "$prefix/sbin"
fi
if [[ -d "$prefix/opt/llvm/bin" ]]; then
prepend_path "$prefix/opt/llvm/bin"
fi
done
prepend_path "$HOME/.cargo/bin"
install_homebrew_user() {
local prefix="$HOME/homebrew"
if [[ -x "$prefix/bin/brew" ]]; then
return 0
fi
log "Homebrew 사용자 설치 ($prefix) — sudo 불필요"
mkdir -p "$prefix"
curl -fsSL https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C "$prefix"
prepend_path "$prefix/bin"
prepend_path "$prefix/sbin"
}
install_homebrew_system() {
if [[ -x /opt/homebrew/bin/brew ]] || [[ -x /usr/local/bin/brew ]]; then
return 0
fi
if [[ "${NONINTERACTIVE:-}" == "1" ]] && ! sudo -n true 2>/dev/null; then
log "sudo 없음 — $HOME/homebrew 로 설치합니다."
install_homebrew_user
return 0
fi
log "Homebrew 시스템 설치 (/opt/homebrew)..."
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
ensure_homebrew() {
if command -v brew >/dev/null 2>&1; then
return 0
fi
install_homebrew_system
if ! command -v brew >/dev/null 2>&1; then
install_homebrew_user
fi
if ! command -v brew >/dev/null 2>&1; then
log "Homebrew 설치 실패. https://brew.sh 수동 설치 후 재실행."
exit 1
fi
# shellcheck disable=SC1091
eval "$(brew shellenv)"
}
ensure_rust() {
if command -v rustc >/dev/null 2>&1; then
log "Rust 이미 설치됨: $(rustc --version)"
return 0
fi
log "Rust 설치 (rustup)..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
# shellcheck disable=SC1091
source "$HOME/.cargo/env"
}
setup_shell_profile() {
local marker="# GoldenChart desktop build PATH"
local profile="${ZDOTDIR:-$HOME}/.zprofile"
if [[ -f "$profile" ]] && grep -qF "$marker" "$profile" 2>/dev/null; then
log "shell profile 이미 설정됨: $profile"
return 0
fi
log "shell profile에 PATH 추가: $profile"
{
echo ""
echo "$marker"
echo 'export PATH="$HOME/.cargo/bin:$PATH"'
if [[ -x "$HOME/homebrew/bin/brew" ]]; then
echo 'eval "$("$HOME/homebrew/bin/brew" shellenv)"'
elif [[ -x /opt/homebrew/bin/brew ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"'
fi
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$HOME/homebrew/opt/llvm/bin:$PATH"'
} >> "$profile"
}
ensure_homebrew
setup_shell_profile
if [[ "$MAC_ONLY" -eq 1 ]]; then
log "macOS 전용 모드 — NSIS/LLVM/cargo-xwin 생략"
else
log "Homebrew 패키지 (NSIS, LLVM)..."
brew install nsis llvm 2>/dev/null || brew upgrade nsis llvm 2>/dev/null || true
fi
ensure_rust
# shellcheck disable=SC1091
[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
if [[ "$MAC_ONLY" -eq 0 ]]; then
log "Windows 크로스 컴파일 타겟..."
rustup target add x86_64-pc-windows-msvc 2>/dev/null || true
if ! command -v cargo-xwin >/dev/null 2>&1; then
log "cargo-xwin 설치 (시간 소요)..."
cargo install cargo-xwin --locked
else
log "cargo-xwin 이미 설치됨"
fi
fi
log "완료. 검증:"
node --version
npm --version
rustc --version
cargo --version
command -v makensis && makensis -VERSION || log "[INFO] makensis — Windows 빌드 시 필요"
command -v cargo-xwin && cargo-xwin --version || log "[INFO] cargo-xwin — Windows 빌드 시 필요"
log "새 터미널을 열거나: source ~/.zprofile"