Files
image-workbench-desktop/scripts/publish-update.sh
T

89 lines
4.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 发布在线更新:签名构建(双架构)+ 上传产物 + 生成 latest.json
#
# 用法:
# ./scripts/publish-update.sh # 用 package.json 的版本
# ./scripts/publish-update.sh 3.25.3 # 先改版本再发布(等价于 set-version + 本脚本)
#
# 依赖:
# · 签名私钥:~/.config/iwb-updater.key(TAURI_SIGNING_PRIVATE_KEY)
# · 公钥已写进 src-tauri/tauri.conf.json → plugins.updater.pubkey
# · NAS 可 ssh(~/.ssh/id_ed25519_fnos)
#
# 产物:
# <target>/bundle/macos/image-workbench.app.tar.gz(.sig) ← 更新器用
# <target>/bundle/dmg/*.dmg ← 官网下载用
# https://download.maqiart.eu.org/updates/latest.json ← 更新源
set -euo pipefail
cd "$(dirname "$0")/.."
[ $# -ge 1 ] && node scripts/set-version.js "$1"
V=$(node -e "console.log(require('./package.json').version)")
KEY="${TAURI_SIGNING_PRIVATE_KEY:-$HOME/.config/iwb-updater.key}"
export TAURI_SIGNING_PRIVATE_KEY="$KEY"
export TAURI_SIGNING_PRIVATE_KEY_PASSWORD="${TAURI_SIGNING_PRIVATE_KEY_PASSWORD:-}"
export CARGO_HOME="${CARGO_HOME:-$PWD/.cargo-home}"
NAS_HOST="${NAS_HOST:-malongan@192.168.100.185}"
NAS_DIR="${NAS_DIR:-/vol8/web/iwb-download}"
SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_fnos}"
SCP="scp -i $SSH_KEY -o BatchMode=yes"
echo "== 1/4 构建 arm64(app + dmg,含签名)"
npx tauri build --bundles app,dmg >/dev/null
echo "== 2/4 构建 x86_64(app + dmg,含签名)"
npx tauri build --target x86_64-apple-darwin --bundles app,dmg >/dev/null
ARM="src-tauri/target/release/bundle"
INT="src-tauri/target/x86_64-apple-darwin/release/bundle"
echo "== 3/4 上传产物"
TMP=$(mktemp -d)
cp "$ARM/macos/image-workbench.app.tar.gz" "$TMP/image-workbench_${V}_aarch64.app.tar.gz"
cp "$ARM/macos/image-workbench.app.tar.gz.sig" "$TMP/image-workbench_${V}_aarch64.app.tar.gz.sig"
cp "$INT/macos/image-workbench.app.tar.gz" "$TMP/image-workbench_${V}_x64.app.tar.gz"
cp "$INT/macos/image-workbench.app.tar.gz.sig" "$TMP/image-workbench_${V}_x64.app.tar.gz.sig"
$SCP "$TMP"/*.app.tar.gz* "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/" 2>/dev/null || true
$SCP "$TMP/image-workbench_${V}_aarch64.app.tar.gz" "$TMP/image-workbench_${V}_aarch64.app.tar.gz.sig" "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/"
$SCP "$TMP/image-workbench_${V}_x64.app.tar.gz" "$TMP/image-workbench_${V}_x64.app.tar.gz.sig" "$NAS_HOST:$NAS_DIR/updates/darwin-x86_64/"
$SCP "$ARM/dmg/image-workbench_${V}_aarch64.dmg" "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/"
$SCP "$INT/dmg/image-workbench_${V}_x64.dmg" "$NAS_HOST:$NAS_DIR/updates/darwin-x86_64/"
echo "== 4/4 生成 latest.json"
export SIG_ARM="$(cat "$ARM/macos/image-workbench.app.tar.gz.sig")"
export SIG_INT="$(cat "$INT/macos/image-workbench.app.tar.gz.sig")"
export UPD_VERSION="$V"
# Windows 包单独构建:全局 version 提升后,旧 windows 条目会变成「声明新版本、实际旧安装包」,
# 客户端会因 app-version 绑定不一致而拒绝安装。所以每次发布 mac 时明确提示并丢弃过期的非 darwin 条目,
# 等 Windows 包跟上再用 publish-windows-update.sh 合并回来。
curl -s -m 20 https://download.maqiart.eu.org/updates/latest.json -o /tmp/iwb-latest-prev.json 2>/dev/null || echo '{}' > /tmp/iwb-latest-prev.json
node -e '
const fs = require("fs")
let prev = {}
try { prev = JSON.parse(fs.readFileSync("/tmp/iwb-latest-prev.json", "utf8")) } catch (e) { prev = {} }
const stale = (prev.platforms ? Object.keys(prev.platforms) : []).filter(function (k) { return k.indexOf("darwin-") !== 0 && prev.version !== process.env.UPD_VERSION })
if (stale.length) console.log("将丢弃过期的非 darwin 平台条目:" + stale.join(","))
'
node -e '
const fs = require("fs")
const v = process.env.UPD_VERSION
const j = {
version: v,
notes: process.env.UPD_NOTES || "",
pub_date: new Date().toISOString(),
platforms: {
"darwin-aarch64": { signature: process.env.SIG_ARM, url: "https://download.maqiart.eu.org/updates/darwin-aarch64/image-workbench_" + v + "_aarch64.app.tar.gz" },
"darwin-x86_64": { signature: process.env.SIG_INT, url: "https://download.maqiart.eu.org/updates/darwin-x86_64/image-workbench_" + v + "_x64.app.tar.gz" },
},
}
fs.writeFileSync("/tmp/iwb-latest.json", JSON.stringify(j, null, 2))
console.log("latest.json -> v" + v)
'
$SCP /tmp/iwb-latest.json "$NAS_HOST:$NAS_DIR/updates/latest.json"
ssh -i "$SSH_KEY" -o BatchMode=yes "$NAS_HOST" "chmod -R a+rX $NAS_DIR"
echo "== 完成:https://download.maqiart.eu.org/updates/latest.json"
curl -s -m 15 https://download.maqiart.eu.org/updates/latest.json | head -c 200; echo