Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File: /usr/local/bin/yarr
- USAGE: $ yarr <-- Update the mirrors list and then update the system with yip script.
- #!/bin/bash
- # Installation:
- # $ sudo cp ./yarr /usr/local/bin/
- # $ sudo chmod +x /usr/local/bin/yarr
- # If reflector is not installed.
- if ! command -v reflector >/dev/null 2>&1
- then
- # 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.
- echo -e "\e[94m::\e[0m Reflector could not be found. Install with: $ sudo pacman -S reflector"
- exit
- fi
- # Update /etc/pacman.d/mirrorlist with the 10 fastest HTTPS mirrors.
- 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_mb=$2
- # If directory does not exist or is not a directory.
- if [[ ! -d "$directory" ]]; then
- echo -e "\e[31m::\e[0m ERROR: Directory '$directory' does not exist."
- exit 1
- fi
- # Get all space values in bytes.
- local low_space_bytes=$(awk "BEGIN {print $low_space_mb * 1024 * 1024}") # Using awk because bash will overflow: $ echo $((9999999999999 * 1024 * 1024)) # will display -7960984073710600192.
- local free_space_bytes=$(df --block-size=1 --output=avail "$directory" 2>/dev/null | tail -n1)
- local total_space_bytes=$(df --block-size=1 --output=size "$directory" 2>/dev/null | tail -n1)
- # If free space is less than low space.
- if awk -v free="$free_space_bytes" -v low="$low_space_bytes" 'BEGIN { exit !(free < low) }'; then
- local si_scalars=(1208925819614629174706176 1180591620717411303424 1152921504606846976 1125899906842624 1099511627776 1073741824 1048576 1024)
- local si_prefixes=("YiB" "ZiB" "EiB" "PiB" "TiB" "GiB" "MiB" "KiB")
- # Find the appropriate SI prefix.
- local scalar=1
- local prefix="KiB"
- for i in ${!si_scalars[@]}; do
- if awk -v space="$total_space_bytes" -v scalar="${si_scalars[$i]}" 'BEGIN { exit !(space >= scalar) }'; then
- scalar="${si_scalars[$i]}"
- prefix="${si_prefixes[$i]}"
- break
- fi
- done
- # Calculate output space info.
- local free_space_scaled=$(awk -v bytes="$free_space_bytes" -v scalar="$scalar" 'BEGIN { printf "%.1f", bytes / scalar }')
- local total_space_scaled=$(awk -v bytes="$total_space_bytes" -v scalar="$scalar" 'BEGIN { printf "%.1f", bytes / scalar }')
- local used_percent=$(awk -v free="$free_space_bytes" -v total="$total_space_bytes" 'BEGIN { printf "%.f", (1 - free / total) * 100 }')
- while true; do
- # Displays disk space info like Dolphin properties window.
- echo -e "\e[31m:: WARNING: Low disk space detected. ${free_space_scaled} ${prefix} free of ${total_space_scaled} ${prefix} (${used_percent}% used) on drive '${directory}'."
- echo -e " This can cause incomplete installations, system crashes, or render the system unbootable.\e[0m"
- echo
- read -p "Do you want to continue? [Y/N]: " response
- # Sets response to 'Y' if you didn't press Y|N, so Enter allows you to continue like it does with Yay/Pacman.
- response=${response:-Y}
- 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 low-space thresholds. Feel free to mod.
- # If paths are on the same drive then you can remove redundant checks.
- 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
- # Update gvim plugins.
- # Assumes vim-plug is installed: https://github.com/junegunn/vim-plug
- echo
- echo -e "\e[94m::\e[0m Updating vim plugins..."
- # Update ~/.vim/ plugins.
- gvim +PlugUpgrade +PlugUpdate +qall
- # Update /root/.vim/ plugins.
- # NOTE: I have GVIM_ENABLE_WAYLAND=1 in my /etc/environment so gvim is resizable in Wayland.
- # -E is needed so the environment variables are available to the sudo instance of gvim.
- # -H is needed so $HOME=/root instead of ~/home/wolf (a side effect of using the -E option).
- sudo -EH gvim +PlugUpgrade +PlugUpdate +qall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement