Skip to content

Instantly share code, notes, and snippets.

@sickcodes
Created November 30, 2021 12:27
Show Gist options
  • Select an option

  • Save sickcodes/37760f4380c6cf22e7b010867a646685 to your computer and use it in GitHub Desktop.

Select an option

Save sickcodes/37760f4380c6cf22e7b010867a646685 to your computer and use it in GitHub Desktop.

Revisions

  1. sickcodes created this gist Nov 30, 2021.
    42 changes: 42 additions & 0 deletions arch_unattended_reinstall_all_packages.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/bash
    # Author: sickcodes
    # Contact: https://twitter.com/sickcodes
    # Copyright: sickcodes (C) 2021
    # License: GPLv3+

    # reinstall all packages, unattended
    # does not include any manual makepkg'ed installations
    # said packages, plus any unavailable AUR packages will be listed at ~/yay_reinstall_failed.log

    # you need to be a NOPASSWD sudoer
    # user ALL=(ALL) NOPASSWD: ALL

    native_packages (){
    ALL_PACKAGES="$(sudo pacman -Qqn)"

    IGNORABLES="$(grep --no-filename ^IgnorePkg /etc/pacman.* 2>/dev/null \
    | sed -E -e 's/IgnorePkg[\ ]+\=[\ ]+//g')"

    yes | sudo pacman -Qqn \
    | grep -v "${IGNORABLES}" \
    | sudo pacman -Syu - --noconfirm

    }

    yays (){
    MANUAL_PACKAGES=($(sudo pacman -Qm -q))

    for PACKAGE in "${MANUAL_PACKAGES[@]}"; do
    yes | yay -S "${PACKAGE}" --noconfirm
    case $? in
    0 ) true
    ;;
    1 ) tee -a ~/yay_reinstall_failed.log <<< "${PACKAGE}"
    ;;
    esac
    yes | yay -Scc --noconfirm
    done
    }

    native_packages
    yays