Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File: /usr/local/bin/yarp
- USAGE: $ yarp <-- Update the mirrors list and then update the system with yip script.
- #!/bin/bash
- # Installation:
- # $ sudo cp ./yarp /usr/local/bin/
- # $ sudo chmod +x /usr/local/bin/yarp
- # Check if reflector is installed.
- if ! command -v reflector >/dev/null 2>&1
- then
- echo -e "\e[94m::\e[0m Reflector could not be found. Install with: $ sudo pacman -S reflector"
- exit
- fi
- # Retrieve the latest mirror list from the Arch Linux Mirror Status page, filter the most up-to-date mirrors, sort them by speed, and overwrite the file /etc/pacman.d/mirrorlist.
- # NOTE: When installing Arch, the ISO's installation environment includes a copy of reflector to assist during install. Its just not installed to the system by default.
- sudo reflector --verbose --country "United States" --latest 10 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
- echo
- # Call yip script.
- yip
- File: /usr/local/bin/yip
- USAGE: $ yip <-- Update installed packages, delete downloaded packages, and purge the orphans, like a boss.
- #!/bin/bash
- # Installation:
- # $ sudo cp ./yip /usr/local/bin/
- # $ sudo chmod +x /usr/local/bin/yip
- free_space_check() {
- local directory=$1
- local low_space=$2
- # Check if directory exists.
- if [[ ! -d "$directory" ]]; then
- echo -e "\e[31m::\e[0m ERROR: Directory '$directory' does not exist."
- exit 1
- fi
- # Get available and total space in megabytes.
- local available_space=$(df --output=avail "$directory" 2>/dev/null | tail -n1 | awk '{print int($1/1024)}')
- local total_space=$(df --output=size "$directory" 2>/dev/null | tail -n1 | awk '{print int($1/1024)}')
- # Calculate percentage of free space.
- local free_percent=$((available_space / total_space * 100))
- # Check if disk space is below threshold.
- if [[ "$available_space" -lt "$low_space" ]]; then
- while true; do
- echo -e "\e[31m:: WARNING: Low disk space detected. ${free_percent}% free (${available_space} MB) on drive '${directory}'."
- echo -e " Running out of disk space during an update could corrupt your system.\e[0m"
- echo
- read -p "Do you want to continue? [Y/N]: " response
- case "$response" in
- y|Y) echo; break ;;
- n|N) exit 1 ;; # Exit script with status 1 to indicate failure.
- *) echo; echo "Please answer Y or N."; echo ;;
- esac
- done
- fi
- }
- # WIP values. Feel free to mod.
- free_space_check /boot/efi 50
- free_space_check /boot 500
- free_space_check / 10240
- free_space_check "$HOME" 10240
- # Update packages including AUR.
- yay -Syyu
- # I actually use this one:
- # yay -Syyu --noconfirm
- # Remove unneeded dependencies.
- # NOTE: Strangely both [$ yes | yay -Scc] and [$ yay -Scc --noconfirm] will prompt you to remove dependencies so [yay -Ycc --noconfirm] needs to be called first to prevent that prompt from displaying.
- #
- # NOTE: The command [yay -Ycc --noconfirm] is implemented in https://github.com/Jguer/yay/blob/next/cmd.go
- # It calls cleanDependencies(...) defined in https://github.com/Jguer/yay/blob/next/clean.go
- # Which calls hangingPackages(...) defined in https://github.com/Jguer/yay/blob/next/query.go
- #
- # WARNING: This version will not work [$ yes | yay -Scc --noconfirm].
- # The prompt will still be displayed to delete dependencies,
- # Yay AUR build directory $HOME/.cache/yay/ will be purged,
- # but no cleaning will take place in Pacman cache directory /var/cache/pacman/pkg/ and Pacman database directory /var/lib/pacman/
- # because the --noconfirm forces the "yes |" to be ignored, resulting in the default Pacman behavior of not cleaning anything to occur.
- echo -e "\e[94m::\e[0m Remove unneeded dependencies..."
- yay -Ycc --noconfirm
- # Clean Pacman cache directory /var/cache/pacman/pkg/, Pacman database directory /var/lib/pacman/, and Yay AUR build directory $HOME/.cache/yay/.
- # If you need to downgrade or install an outdated package then you will need to download it again.
- #
- # NOTE: To just clean the Pacman directories the command is [$ yes | sudo pacman -Scc].
- # WARNING: This version doesn't do anything: [$ sudo pacman -Scc --noconfirm]
- # SEE: https://bbs.archlinux.org/viewtopic.php?id=236186
- # SEE: https://unix.stackexchange.com/questions/52277/pacman-option-to-assume-yes-to-every-question
- # WARNING: This command is broken as well [$ yay -Scc --noconfirm]. It will only clean Yay AUR build directory: $HOME/.cache/yay/
- echo -e "\e[94m::\e[0m Clean Pacman and Yay caches..."
- yes | yay -Scc
- echo
- # Purge the orphans.
- # NOTE: This code might be redundant because of [yay -Ycc --noconfirm]. I've yet to see it actually find an orphan.
- orphans=$(pacman -Qdtq)
- if [[ -n "$orphans" ]]; then
- echo -e "\e[94m::\e[0m Remove orphaned packages..."
- sudo pacman -Rns $orphans
- else
- echo -e "\e[94m::\e[0m No orphaned packages found..."
- fi
- # Optional section for vim users.
- # echo
- # echo -e "\e[94m::\e[0m Updating vim plugins..."
- # # Update ~/.vim/ plugins.
- # gvim +PlugUpgrade +PlugUpdate +qall
- # # Update /root/.vim/ plugins.
- # sudo gvim +PlugUpgrade +PlugUpdate +qall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement