Handy scripts you'd like to share

Edit:

See new revised version of the script below:



Garuda-Update Now:

Lots of newbs complain because they don’t want to use the terminal for updates, they want a GUI. Well too bad :rofl:. Here’s the next best thing, a TUI (some would say better). If you were inclined to do so, the TUI’s color scheme can be changed via a dialogrc file. A deskstop launcher could also be created for those who are terminal averse.

I wrote the script using dialog to create a TUI menu of choices for running garuda-update, (with a few customizations and extra info for the newbs).

This is my preliminary gun.sh script, see the revised final version at the link below:

#!/bin/bash
#cat /usr/local/bin/gun.sh
#sudo chmod +x  /usr/local/bin/gun.sh

black='\033[0;30m'
dk_gray='\033[1;30m'
red='\033[0;31m'
lt_red='\033[1;31m'
green='\033[0;32m'
lt_green='\033[1;32m'
yellow='\033[1;33m'
blue='\033[0;34m'
lt_blue='\033[1;34m'
purple='\033[0;35m'
lt_purple='\033[1;35m'
orange='\033[0;33m'
cyan='\033[0;36m'
lt_gray='\033[0;37m'
white='\033[1;37m'
default='\033[0m' # Default Color

HEIGHT=20
WIDTH=80
CHOICE_HEIGHT=4
BACKTITLE="Garuda Update Now"
TITLE="Garuda Update Advanced Options"
MENU="Choose one of the following options:"

OPTIONS=(1 "garuda-update + with mirrorlist refresh"
         2 "garuda-update + Chaotic AUR + AUR updates + with mirrorlist refresh"
         3 "garuda-update - without mirrorlist refresh"
         4 "garuda-update + Chaotic AUR + AUR updates - without mirrorlist refresh"
         5 "garuda-update –noconfirm"
         6 "garuda-update remote fix"
         7 "garuda-update remote keyring"
         8 "garuda-update remote fullfix"
         9 "garuda-update remote reinstall"
        10 "garuda-update remote reset-snapper"
        11 "garuda-update remote reset-audio")

CHOICE=$(dialog --clear \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${OPTIONS[@]}" \
                2>&1 >/dev/tty)

clear
case $CHOICE in
        1)
            freespace="$(btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}')"
            notify-send -i /usr/share/icons/breeze/emblems/8/emblem-warning.svg "$freespace of space remaining for system update"
            echo -e "\nAlways ensure you have adequate free space before beginning any system update "
            echo "You currently have $freespace of space remaining in your BTRFS /root partition"
            echo -e "\n${lt_blue}You have selected:"
            echo -e "${yellow}garuda-update + ${lt_purple}refresh mirrorlist${default}\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update
            ;;
        2)
            freespace="$(btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}')"
            notify-send -i /usr/share/icons/breeze/emblems/8/emblem-warning.svg "$freespace of space remaining for system update"
            echo -e  "\nAlways ensure you have adequate free space before beginning any system update "
            echo "You currently have $freespace of space remaining in your BTRFS /root partition"
            echo -e "\n${lt_blue}You have selected:"
            echo -e "${yellow}garuda-update + ${lt_green}Chaotic AUR + AUR updates + ${lt_purple}refresh mirrorlist${default}\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update -a
            ;;
        3)
            freespace="$(btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}')"
            notify-send -i /usr/share/icons/breeze/emblems/8/emblem-warning.svg "$freespace of space remaining for system update"
            echo -e "\nAlways ensure you have adequate free space before beginning any system update "
            echo "You currently have $freespace of space remaining in your BTRFS /root partition"
            echo -e "\n${lt_blue}You have selected:"
            echo -e "${yellow}garuda-update - ${orange}skip refresh mirrorlist${default}\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update –skip-mirrorlist
            ;;
        4)
            freespace="$(btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}')"
            notify-send -i /usr/share/icons/breeze/emblems/8/emblem-warning.svg "$freespace of space remaining for system update"
            echo -e "\nAlways ensure you have adequate free space before beginning any system update "
            echo "You currently have $freespace of space remaining in your BTRFS /root partition"
            echo -e "\n${lt_blue}You have selected:"
            echo -e "${yellow}garuda-update + ${lt_green}Chaotic AUR + AUR+updates - ${orange}skip refresh mirrorlist${default}\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update -a  –skip-mirrorlist
            ;;
        5)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update –noconfirm${default}"
            echo  "This command will perform a system update without multiple confirmation prompts"
            echo -e "This emulates a custom (safer) version of --noconfirm for pacman (PACMAN_NOCONFIRM=1)\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update –noconfirm
             ;;
        6)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote fix${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo "Reset pacman.conf"
            echo -e "Refresh keyrings\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote fix
            ;;
        7)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote keyring${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo -e "Refresh the keyring without resetting pacman.conf\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote keyring
            ;;
        8)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote fullfix${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo "Reset pacman.conf"
            echo "Refresh keyrings"
            echo -e "Reinstall all Garuda OS packages\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote fullfix
            ;;
         9)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote reinstall${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo -e "Reinstall all Garuda OS packages\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote reinstall
            ;;
        10)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote reset-snapper${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo "Remove all backup subvolumes and snapshots created by Snapper"
            echo -e "Force recreate the Snapper configs\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote reset-snapper
            ;;
        11)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update remote reset-audio${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo "Reinstall WirePlumber and Pipewire-support"
            echo "Disable/enable the WirePlumber and Pipewire-support services"
            echo -e "Reset the audio configuration to default\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update remote reset-audio
            ;;
esac

I named it Garuda-Update Now (gun.sh), because I thought it would be humorous to tell people to “gun it” when they needed to update their system.

I’m no coder, and this was my first attempt at using dialog, so it’s far from a pro job. I also didn’t spend any effort testing for bugs, but I think it works just fine. Give it a try.

Save the script as:

/usr/local/bin/gun.sh

Make the script executable:

sudo chmod +x  /usr/local/bin/gun.sh

To test it out without the extra steps, you can simply copy/paste the entire script into any terminal window and run it there.

Edit:

Corrected a few typos/omissions I spotted after posting.

See revised version of the script:

10 Likes