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

echo "[VSCode应用-补丁]"
read -p "指定VSCode路径: " VSCODE_APP_PATH
if [ ! -f "$VSCODE_APP_PATH/code" ]; then
  echo "错误：指定路径下不存在VSCode可执行文件"
  exit 1
fi
echo "-- 找到code程序，即将补丁code程序..."
echo "-- 备份原始code程序..."
if [ ! -f "$VSCODE_APP_PATH/code.bak" ]; then
  cp "$VSCODE_APP_PATH/code" "$VSCODE_APP_PATH/code.bak"
fi
echo "-- 开始打补丁..."
$VSCODE_PATCH_DIR/tools/patchelf \
  --set-interpreter "$VSCODE_PATCH_DIR/lib/ld-linux-x86-64.so.2" \
  --set-rpath '$ORIGIN:~/.vscode-patch/lib' \
  "$VSCODE_APP_PATH/code"
echo "-- 补丁完成！"