#!/bin/bash

# VSCode Remote Server 补丁脚本
# 用于补丁 ~/.vscode-server 下的 code-{id} 可执行程序

VSCODE_PATCH_DIR="$HOME/.vscode-patch"
VSCODE_SERVER_DIR="$HOME/.vscode-server"

echo "[VSCode Remote Server 补丁工具]"

# 1. 检查补丁工具文件夹
if [ ! -d "$VSCODE_PATCH_DIR/lib" ]; then
  echo "错误：补丁文件夹应放在这儿：$HOME/.vscode-patch/"
  exit 1
fi

echo "-- 设置VSCode补丁环境变量"

cat >> ~/.profile << EOF

# VSCode 远程服务补丁库
export VSCODE_SERVER_PATCHELF_PATH="$HOME/.vscode-patch/lib"
export VSCODE_SERVER_CUSTOM_GLIBC_LINKER="$HOME/.vscode-patch/lib/ld-linux-x86-64.so.2"
export VSCODE_SERVER_CUSTOM_GLIBC_PATH="$HOME/.vscode-patch/lib"

EOF

cat >> ~/.zprofile << EOF

# VSCode 远程服务补丁库
export VSCODE_SERVER_PATCHELF_PATH="$HOME/.vscode-patch/lib"
export VSCODE_SERVER_CUSTOM_GLIBC_LINKER="$HOME/.vscode-patch/lib/ld-linux-x86-64.so.2"
export VSCODE_SERVER_CUSTOM_GLIBC_PATH="$HOME/.vscode-patch/lib"

EOF

echo "-- 设置完毕"