install.sh: an update needs no sudo when the system packages are already there

Fresh systems still fetch the package lists first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
This commit is contained in:
王性驊 2026-11-05 08:02:57 +08:00
parent c71e8357b8
commit 39bd19e9df
1 changed files with 12 additions and 2 deletions

View File

@ -95,7 +95,6 @@ linux_packages() {
# $1: build | app | hands | server # $1: build | app | hands | server
case $PM in case $PM in
apt-get) apt-get)
$SUDO apt-get update -qq || warn "apt-get update 有錯誤,繼續試試看"
case $1 in case $1 in
server) set -- curl ca-certificates git ;; server) set -- curl ca-certificates git ;;
build) set -- build-essential pkg-config git curl ca-certificates libasound2-dev ;; build) set -- build-essential pkg-config git curl ca-certificates libasound2-dev ;;
@ -106,8 +105,19 @@ linux_packages() {
libxkbcommon-x11-0 "libgl1|libgl1-mesa-glx" xdg-utils libnotify-bin libsecret-tools espeak-ng zenity \ libxkbcommon-x11-0 "libgl1|libgl1-mesa-glx" xdg-utils libnotify-bin libsecret-tools espeak-ng zenity \
xclip wl-clipboard ffmpeg fonts-noto-cjk ;; xclip wl-clipboard ffmpeg fonts-noto-cjk ;;
esac esac
# A fresh system has no package lists yet: fetch them first, or nothing can be picked.
if ! ls /var/lib/apt/lists/*_Packages >/dev/null 2>&1; then
$SUDO apt-get update -qq || warn "apt-get update 有錯誤,繼續試試看"
UPDATED=1
fi
pkgs=$(apt_pick "$@" | tr '\n' ' ') pkgs=$(apt_pick "$@" | tr '\n' ' ')
info "apt-get install $pkgs" # Already there (an update): nothing to install, no sudo password needed.
missing=""
for p in $pkgs; do dpkg -s "$p" >/dev/null 2>&1 || missing="$missing $p"; done
if [ -z "$missing" ]; then info "都已經裝好了"; return 0; fi
pkgs=$missing
[ -n "${UPDATED:-}" ] || $SUDO apt-get update -qq || warn "apt-get update 有錯誤,繼續試試看"
info "apt-get install$pkgs"
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pkgs >/dev/null || die "安裝系統套件失敗。" "請看上面的錯誤,或手動執行:sudo apt-get install $pkgs" $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pkgs >/dev/null || die "安裝系統套件失敗。" "請看上面的錯誤,或手動執行:sudo apt-get install $pkgs"
;; ;;
dnf) dnf)