Files
coder-docker/template/docker/install.sh
2025-08-31 19:14:13 +08:00

91 lines
1.9 KiB
Bash

#!/bin/sh
set -eu
# mscode (VS Code CLI Web) installer
# Inspired by code-server install.sh, but simplified
# Reference: https://code.visualstudio.com/docs/remote/vscode-cli
VERSION="insider" # 可选择 stable | insider
OS="linux"
ARCH="x64"
CACHE_DIR="${HOME}/.cache/mscode"
INSTALL_PREFIX="/usr/local"
usage() {
cat <<EOF
Installs mscode (VS Code CLI Web).
Usage:
install.sh [--version insider|stable] [--prefix <dir>]
Default:
--version insider
--prefix /usr/local
Examples:
sh install.sh --version stable
sh install.sh --prefix /opt/vscode
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--version=*)
VERSION="${1#*=}"
;;
--version)
shift
VERSION="${1:-}"
;;
--prefix=*)
INSTALL_PREFIX="${1#*=}"
;;
--prefix)
shift
INSTALL_PREFIX="${1:-}"
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
shift || true
done
mkdir -p "$CACHE_DIR"
# 下载 VS Code CLI
TAR_FILE="${CACHE_DIR}/vscode_cli_${VERSION}_${OS}_${ARCH}.tar.gz"
if [ ! -f "$TAR_FILE" ]; then
echo "Downloading VS Code CLI ($VERSION)..."
curl -fL -o "$TAR_FILE" "https://code.visualstudio.com/sha/download?build=${VERSION}&os=cli-alpine-${ARCH}"
fi
# 解压缩
TEMP_DIR="$(mktemp -d)"
tar -xzf "$TAR_FILE" -C "$TEMP_DIR"
# 查找可执行文件
FILE="$(find "$TEMP_DIR" -type f -iname "code*" | head -n 1)"
if [ -z "$FILE" ]; then
echo "ERROR: Failed to find VS Code CLI executable."
exit 1
fi
# 安装到指定目录
echo "Installing VS Code CLI to $INSTALL_PREFIX/bin..."
sudo mkdir -p "$INSTALL_PREFIX/bin"
sudo cp "$FILE" "$INSTALL_PREFIX/bin/mscode"
sudo chmod +x "$INSTALL_PREFIX/bin/mscode"
# 清理
rm -rf "$TEMP_DIR"
echo
echo "✅ VS Code CLI installed successfully!"
echo "Run with: mscode serve-web --accept-server-license-terms --host 0.0.0.0 --port 8000"