✨ feat(vscode): 代码阅读支持 Shell 脚本(bash / sh / zsh):解释器、选项每个开关一行、变量展开读成中文、分情况表、函数按位置的参数 / 输出 / 返回、常用命令按命令规则读成一句、重定向、条件、遍历、管道;同一文件里的函数和变量能跳转、高亮
This commit is contained in:
1 parent
c577f38bee
commit
e96694317d
12 files changed
+2559
-3
No files matched your search
+130
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
# 下载执行器自带的 git 与 python, 放到 src-tauri/resources/runtime/<target>/{git,python}。
|
||||
#
|
||||
# scripts/fetch-runtime.sh <target>
|
||||
#
|
||||
# 支持的 target:
|
||||
# x86_64-pc-windows-msvc MinGit 64-bit (git-for-windows) + python-build-standalone
|
||||
# aarch64-apple-darwin dugite-native macOS arm64 (GitHub Desktop 的可搬移 git) + python-build-standalone
|
||||
#
|
||||
# 构建 (含 cargo test / tauri dev) 前先跑一次: tauri 按目标平台的配置把这个目录打进安装包
|
||||
# (见 src-tauri/tauri.<os>.conf.json), 目录缺了构建直接失败。
|
||||
# 下载的包按版本缓存在 ~/.cache/luffy-desktop-runtime, 校验 sha256; 国内访问 GitHub 需要
|
||||
# 先 export https_proxy。版本升级时同时改下面的地址与 sha256。
|
||||
set -euo pipefail
|
||||
|
||||
target="${1:-}"
|
||||
here="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
dest="$here/src-tauri/resources/runtime/$target"
|
||||
cache="${XDG_CACHE_HOME:-$HOME/.cache}/luffy-desktop-runtime"
|
||||
|
||||
PY_RELEASE=20260924
|
||||
PY_VERSION=3.13.15
|
||||
|
||||
case "$target" in
|
||||
x86_64-pc-windows-msvc)
|
||||
GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.55.0.windows.5/MinGit-2.55.0.5-64-bit.zip
|
||||
GIT_SHA256=56d7b226b7693196cfc71fef26568f536c4a021ab6c37ff2db4287bed908e96e
|
||||
PY_SHA256=e42fa944748a50e9ff481cbb817ef8a6e3da6fbcf0cf6f29b554e1acb8c7384d
|
||||
;;
|
||||
aarch64-apple-darwin)
|
||||
GIT_URL=https://github.com/desktop/dugite-native/releases/download/v2.53.0-4/dugite-native-v2.53.0-4098283-macOS-arm64.tar.gz
|
||||
GIT_SHA256=f9dc64635a5b62fbd7ad95db73268bbb8912255ac516d65d37bf7af22fcb8ffe
|
||||
PY_SHA256=064afb7c2fc0bbf511d886288adf98696af5105e36c138cdf2c199c0146fcf68
|
||||
;;
|
||||
*)
|
||||
echo "用法: $0 <x86_64-pc-windows-msvc|aarch64-apple-darwin>" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
PY_URL="https://github.com/astral-sh/python-build-standalone/releases/download/${PY_RELEASE}/cpython-${PY_VERSION}%2B${PY_RELEASE}-${target}-install_only_stripped.tar.gz"
|
||||
|
||||
sha_ok() {
|
||||
[ -f "$1" ] && [ "$(shasum -a 256 "$1" | cut -d' ' -f1)" = "$2" ]
|
||||
}
|
||||
|
||||
# 下载 (已缓存且校验通过就不重下), 回显本地文件路径
|
||||
fetch() {
|
||||
local url="$1" sha="$2" out
|
||||
out="$cache/$(basename "${url//%2B/+}")"
|
||||
mkdir -p "$cache"
|
||||
if ! sha_ok "$out" "$sha"; then
|
||||
echo "下载 $url" >&2
|
||||
curl -fL --retry 3 -o "$out.part" "$url"
|
||||
mv "$out.part" "$out"
|
||||
fi
|
||||
if ! sha_ok "$out" "$sha"; then
|
||||
echo "sha256 不符: $out" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "$out"
|
||||
}
|
||||
|
||||
git_pkg="$(fetch "$GIT_URL" "$GIT_SHA256")"
|
||||
py_pkg="$(fetch "$PY_URL" "$PY_SHA256")"
|
||||
|
||||
rm -rf "$dest"
|
||||
mkdir -p "$dest/git"
|
||||
case "$git_pkg" in
|
||||
*.zip) unzip -q "$git_pkg" -d "$dest/git" ;;
|
||||
*) tar -xzf "$git_pkg" -C "$dest/git" ;;
|
||||
esac
|
||||
# python-build-standalone 的包里顶层目录就叫 python
|
||||
tar -xzf "$py_pkg" -C "$dest"
|
||||
|
||||
# ── 去掉 Git Credential Manager ──────────────────────────────────────────────
|
||||
# 两个 git 包都带了 GCM (.NET 写的图形界面凭证助手, 占包体大头: macOS 约 120MB、Windows 约 60MB)。
|
||||
# 平台的 git 在后台跑, 凭证由平台写进仓库配置, 不能弹窗, 用不上它。
|
||||
case "$target" in
|
||||
*-apple-darwin)
|
||||
gc="$dest/git/libexec/git-core"
|
||||
rm -rf "$gc"/git-credential-manager* "$gc"/*.dll "$gc"/*.dylib \
|
||||
"$gc"/createdump "$gc"/NOTICE "$gc"/uninstall.sh
|
||||
# .NET 的各语言资源目录; git 自己的子目录只有 mergetools
|
||||
find "$gc" -mindepth 1 -maxdepth 1 -type d ! -name mergetools -exec rm -rf {} +
|
||||
;;
|
||||
*-windows-msvc)
|
||||
# mingw64/bin 里 git 自己依赖的 DLL 都以 lib 开头 (外加 zlib1.dll), 其余 DLL 都属于 GCM;
|
||||
# lib 开头的只有 HarfBuzzSharp / SkiaSharp 两个属于 GCM
|
||||
mb="$dest/git/mingw64/bin"
|
||||
rm -f "$mb"/git-credential-manager.exe* "$mb"/libHarfBuzzSharp.dll "$mb"/libSkiaSharp.dll
|
||||
find "$mb" -maxdepth 1 -name '*.dll' ! -name 'lib*' ! -name zlib1.dll -delete
|
||||
;;
|
||||
esac
|
||||
|
||||
# Windows 版 python 只有 python.exe; 平台脚本按 python3 这个名字再调起它时 (它的目录前置在
|
||||
# PATH 上), 要在这里先找到, 而不是落到系统自带的「去应用商店安装」占位程序上。
|
||||
# python.exe 只是 90KB 的启动器, 本体在同目录的 python3xx.dll。
|
||||
if [[ "$target" == *-windows-msvc ]]; then
|
||||
cp "$dest/python/python.exe" "$dest/python/python3.exe"
|
||||
fi
|
||||
|
||||
# ── 去掉符号链接 ─────────────────────────────────────────────────────────────
|
||||
# tauri 打包不保留符号链接, 会把每个都展开成一整份拷贝 (git 的 140 多个内建命令别名全指向
|
||||
# 3MB 的 git)。只有 macOS 的包里有符号链接。
|
||||
if [[ "$target" == *-apple-darwin ]]; then
|
||||
gc="$dest/git/libexec/git-core"
|
||||
# 内建命令的短横线别名 (git-add -> git …): git 自己调内建命令不走它们。同 git 构建选项
|
||||
# SKIP_DASHED_BUILT_INS, 只留远端/本地传输要按名字调起的三个
|
||||
for f in "$gc"/git-*; do
|
||||
[ -L "$f" ] && [ "$(readlink "$f")" = git ] || continue
|
||||
case "$(basename "$f")" in
|
||||
git-upload-pack | git-receive-pack | git-upload-archive) ;;
|
||||
*) rm "$f" ;;
|
||||
esac
|
||||
done
|
||||
# python 只留 bin/python3 这一个入口 (执行器按它找), 版本号命名的本体挪过来
|
||||
pybin="$dest/python/bin"
|
||||
real="$(readlink "$pybin/python3")"
|
||||
rm "$pybin/python3"
|
||||
mv "$pybin/$real" "$pybin/python3"
|
||||
find "$dest/python" -type l -delete
|
||||
# 剩下的 (传输程序、git-remote-https 之类) 换成实体文件
|
||||
find "$dest" -type l | while read -r link; do
|
||||
cp -L "$link" "$link.tmp"
|
||||
mv "$link.tmp" "$link"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "自带运行时就绪: $dest" >&2
|
||||
du -sh "$dest/git" "$dest/python" >&2
|
||||
Reference in new issue
Block a user