diff --git a/install.sh b/install.sh index 4d112b0..16e8923 100755 --- a/install.sh +++ b/install.sh @@ -95,7 +95,6 @@ linux_packages() { # $1: build | app | hands | server case $PM in apt-get) - $SUDO apt-get update -qq || warn "apt-get update 有錯誤,繼續試試看" case $1 in server) set -- curl ca-certificates git ;; 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 \ xclip wl-clipboard ffmpeg fonts-noto-cjk ;; 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' ' ') - 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" ;; dnf)