Browse Source

feat(archlinux): unify `upgrade` function (#11597)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
deimosian 2 years ago
parent
commit
9b1ef262bc
1 changed files with 26 additions and 5 deletions
  1. 26 5
      plugins/archlinux/archlinux.plugin.zsh

+ 26 - 5
plugins/archlinux/archlinux.plugin.zsh

@@ -23,7 +23,6 @@ alias pacfiles='pacman -F'
 alias pacls='pacman -Ql'
 alias pacown='pacman -Qo'
 alias pacupd="sudo pacman -Sy"
-alias upgrade='sudo pacman -Syu'
 
 function paclist() {
   # Based on https://bbs.archlinux.org/viewtopic.php?id=93683
@@ -109,7 +108,6 @@ if (( $+commands[aura] )); then
   alias auupd="sudo aura -Sy"
   alias auupg='sudo sh -c "aura -Syu              && aura -Au"'
   alias ausu='sudo sh -c "aura -Syu --no-confirm && aura -Au --no-confirm"'
-  alias upgrade='sudo aura -Syu'
 
   # extra bonus specially for aura
   alias auown="aura -Qqo"
@@ -136,7 +134,6 @@ if (( $+commands[pacaur] )); then
   alias painsd='pacaur -S --asdeps'
   alias pamir='pacaur -Syy'
   alias paupd="pacaur -Sy"
-  alias upgrade='pacaur -Syu'
 fi
 
 if (( $+commands[trizen] )); then
@@ -158,7 +155,6 @@ if (( $+commands[trizen] )); then
   alias trinsd='trizen -S --asdeps'
   alias trmir='trizen -Syy'
   alias trupd="trizen -Sy"
-  alias upgrade='trizen -Syu'
 fi
 
 if (( $+commands[yay] )); then
@@ -180,5 +176,30 @@ if (( $+commands[yay] )); then
   alias yainsd='yay -S --asdeps'
   alias yamir='yay -Syy'
   alias yaupd="yay -Sy"
-  alias upgrade='yay -Syu'
 fi
+
+# Check Arch Linux PGP Keyring before System Upgrade to prevent failure.
+function upgrade() {
+  echo "[oh-my-zsh] Checking Arch Linux PGP Keyring"
+  local installedver="$(sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version         : ).*')"
+  local currentver="$(sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version         : ).*')"
+  if [ $installedver != $currentver ]; then
+    echo "[oh-my-zsh] Arch Linux PGP Keyring is out of date."
+    echo "[oh-my-zsh] Updating before full system upgrade."
+    sudo pacman -Syu --needed --noconfirm archlinux-keyring
+  else
+    echo "[oh-my-zsh] Arch Linux PGP Keyring is up to date."
+  fi
+  echo "[oh-mh-zsh] Proceeding with full system upgrade."
+  if (( $+commands[yay] )); then
+    yay -Syu
+  elif (( $+commands[trizen] )); then
+    trizen -Syu
+  elif (( $+commands[pacaur] )); then
+    pacaur -Syu
+  elif (( $+commands[aura] )); then
+    sudo aura -Syu
+  else
+    sudo pacman -Syu
+  fi
+}