mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat: skip unchanged dependency updates
This commit is contained in:
@@ -14,8 +14,11 @@ fi
|
||||
PACKAGE_SOURCE=${PI_PACKAGE_SOURCE:-git:git@bitbucket.org:siakitem/my-pi.git}
|
||||
POWERLEVEL10K_PRESET_FILE=$SCRIPT_DIR/config/p10k.zsh
|
||||
CODEGRAPH_INSTALL_URL=https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh
|
||||
CODEGRAPH_LATEST_RELEASE_URL=https://github.com/colbymchenry/codegraph/releases/latest
|
||||
KITTY_INSTALL_URL=https://sw.kovidgoyal.net/kitty/installer.sh
|
||||
KITTY_VERSION_URL=https://sw.kovidgoyal.net/kitty/current-version.txt
|
||||
update_failed=0
|
||||
brew_metadata_refreshed=0
|
||||
|
||||
say() {
|
||||
printf '%s\n' "$*"
|
||||
@@ -47,7 +50,7 @@ select_updated_bundle_config() {
|
||||
if [ -n "$updated_bundle_dir" ] && [ -f "$updated_bundle_dir/config/p10k.zsh" ]; then
|
||||
POWERLEVEL10K_PRESET_FILE=$updated_bundle_dir/config/p10k.zsh
|
||||
elif [ ! -f "$POWERLEVEL10K_PRESET_FILE" ]; then
|
||||
warn "无法定位升级后的组合包配置,找不到 $POWERLEVEL10K_PRESET_FILE。"
|
||||
warn "无法定位升级后的组合包配置,找不到 ${POWERLEVEL10K_PRESET_FILE}。"
|
||||
return 1
|
||||
else
|
||||
warn "无法从当前 PI_PACKAGE_SOURCE 推导升级后的包目录,将使用脚本目录中的配置。"
|
||||
@@ -87,7 +90,28 @@ update_git_checkout() {
|
||||
warn "升级 $component 需要 git。"
|
||||
return 1
|
||||
fi
|
||||
git -C "$checkout" pull --ff-only
|
||||
upstream=$(git -C "$checkout" rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null) || {
|
||||
warn "$component 的 Git checkout 没有可识别的上游分支,已跳过版本升级。"
|
||||
return 1
|
||||
}
|
||||
git -C "$checkout" fetch --quiet || return 1
|
||||
local_revision=$(git -C "$checkout" rev-parse HEAD) || return 1
|
||||
remote_revision=$(git -C "$checkout" rev-parse "$upstream") || return 1
|
||||
if [ "$local_revision" = "$remote_revision" ]; then
|
||||
say "✓ $component 已是最新版本。"
|
||||
return 0
|
||||
fi
|
||||
say "发现 $component 有新版本,正在快进升级。"
|
||||
git -C "$checkout" merge --ff-only "$upstream"
|
||||
}
|
||||
|
||||
refresh_brew_metadata() {
|
||||
if [ "$brew_metadata_refreshed" -eq 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
say "正在刷新 Homebrew 版本信息。"
|
||||
brew update || return 1
|
||||
brew_metadata_refreshed=1
|
||||
}
|
||||
|
||||
update_brew_formula_if_installed() {
|
||||
@@ -95,8 +119,20 @@ update_brew_formula_if_installed() {
|
||||
description=$2
|
||||
command_name=$3
|
||||
if command -v brew >/dev/null 2>&1 && brew list --formula "$formula" >/dev/null 2>&1; then
|
||||
say "正在升级 $description。"
|
||||
brew upgrade "$formula" || record_update_failure "$description"
|
||||
refresh_brew_metadata || {
|
||||
record_update_failure "$description"
|
||||
return 0
|
||||
}
|
||||
outdated_formula=$(brew outdated --formula --quiet "$formula") || {
|
||||
record_update_failure "$description"
|
||||
return 0
|
||||
}
|
||||
if [ -z "$outdated_formula" ]; then
|
||||
say "✓ $description 已是最新版本。"
|
||||
else
|
||||
say "发现 $description 有新版本,正在升级。"
|
||||
brew upgrade "$formula" || record_update_failure "$description"
|
||||
fi
|
||||
elif command -v "$command_name" >/dev/null 2>&1; then
|
||||
say "- $description 已安装,但不由 Homebrew 管理,已保留现有安装。"
|
||||
else
|
||||
@@ -140,18 +176,47 @@ update_kitty() {
|
||||
fi
|
||||
|
||||
if command -v brew >/dev/null 2>&1 && brew list --cask kitty >/dev/null 2>&1; then
|
||||
brew upgrade --cask kitty || record_update_failure "Kitty"
|
||||
if refresh_brew_metadata; then
|
||||
if outdated_kitty=$(brew outdated --cask --quiet kitty); then
|
||||
if [ -z "$outdated_kitty" ]; then
|
||||
say "✓ Kitty 已是最新版本。"
|
||||
else
|
||||
say "发现 Kitty 有新版本,正在升级。"
|
||||
brew upgrade --cask kitty || record_update_failure "Kitty"
|
||||
fi
|
||||
else
|
||||
record_update_failure "Kitty"
|
||||
fi
|
||||
else
|
||||
record_update_failure "Kitty"
|
||||
fi
|
||||
elif [ "$kitty_bin" = "$HOME/.local/kitty.app/bin/kitty" ] || \
|
||||
[ "$kitty_bin" = "/Applications/kitty.app/Contents/MacOS/kitty" ]; then
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
record_update_failure "Kitty(官方安装需要 curl)"
|
||||
record_update_failure "Kitty(检查版本需要 curl)"
|
||||
else
|
||||
installer_file=$(mktemp "${TMPDIR:-/tmp}/my-pi-kitty.XXXXXX") || return 1
|
||||
if ! curl -fsSL "$KITTY_INSTALL_URL" -o "$installer_file" || \
|
||||
! sh "$installer_file" launch=n; then
|
||||
record_update_failure "Kitty"
|
||||
kitty_version_output=$("$kitty_bin" --version 2>/dev/null) || kitty_version_output=
|
||||
case $kitty_version_output in
|
||||
kitty\ *)
|
||||
installed_kitty_version=${kitty_version_output#kitty }
|
||||
installed_kitty_version=${installed_kitty_version%% *}
|
||||
;;
|
||||
*) installed_kitty_version= ;;
|
||||
esac
|
||||
latest_kitty_version=$(curl -fsSL "$KITTY_VERSION_URL") || latest_kitty_version=
|
||||
if [ -z "$installed_kitty_version" ] || [ -z "$latest_kitty_version" ]; then
|
||||
record_update_failure "Kitty 版本检查"
|
||||
elif [ "$installed_kitty_version" = "$latest_kitty_version" ]; then
|
||||
say "✓ Kitty $installed_kitty_version 已是最新版本。"
|
||||
else
|
||||
say "发现 Kitty ${latest_kitty_version}(当前 ${installed_kitty_version}),正在升级。"
|
||||
installer_file=$(mktemp "${TMPDIR:-/tmp}/my-pi-kitty.XXXXXX") || return 1
|
||||
if ! curl -fsSL "$KITTY_INSTALL_URL" -o "$installer_file" || \
|
||||
! sh "$installer_file" launch=n "installer=version-$latest_kitty_version"; then
|
||||
record_update_failure "Kitty"
|
||||
fi
|
||||
rm -f "$installer_file"
|
||||
fi
|
||||
rm -f "$installer_file"
|
||||
fi
|
||||
else
|
||||
say "- Kitty 已安装,但不由 Homebrew 或官方 ~/.local 安装管理,已保留现有安装。"
|
||||
@@ -169,11 +234,30 @@ update_codegraph() {
|
||||
return 0
|
||||
fi
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
warn "升级 CodeGraph 需要 curl。"
|
||||
warn "检查 CodeGraph 版本需要 curl。"
|
||||
return 1
|
||||
fi
|
||||
installed_codegraph_version=$(codegraph --version 2>/dev/null) || installed_codegraph_version=
|
||||
latest_release_url=$(curl -fsSLI -o /dev/null -w '%{url_effective}' \
|
||||
"$CODEGRAPH_LATEST_RELEASE_URL") || latest_release_url=
|
||||
case $latest_release_url in
|
||||
*/releases/tag/*) latest_codegraph_tag=${latest_release_url##*/} ;;
|
||||
*) latest_codegraph_tag= ;;
|
||||
esac
|
||||
latest_codegraph_version=${latest_codegraph_tag#v}
|
||||
installed_codegraph_version=${installed_codegraph_version#v}
|
||||
if [ -z "$installed_codegraph_version" ] || [ -z "$latest_codegraph_version" ]; then
|
||||
warn "无法比较 CodeGraph 的本地版本与最新发布版本,已跳过替换。"
|
||||
return 1
|
||||
fi
|
||||
if [ "$installed_codegraph_version" = "$latest_codegraph_version" ]; then
|
||||
say "✓ CodeGraph $installed_codegraph_version 已是最新版本。"
|
||||
return 0
|
||||
fi
|
||||
say "发现 CodeGraph ${latest_codegraph_version}(当前 ${installed_codegraph_version}),正在升级。"
|
||||
installer_file=$(mktemp "${TMPDIR:-/tmp}/my-pi-codegraph.XXXXXX") || return 1
|
||||
if ! curl -fsSL "$CODEGRAPH_INSTALL_URL" -o "$installer_file" || ! sh "$installer_file"; then
|
||||
if ! curl -fsSL "$CODEGRAPH_INSTALL_URL" -o "$installer_file" || \
|
||||
! CODEGRAPH_VERSION="$latest_codegraph_tag" sh "$installer_file"; then
|
||||
rm -f "$installer_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user