Handy scripts you'd like to share

The Arch Linux ISOs make a “beep” from the PC speaker when you get to the initial boot screen. Depending on your computer, it can be pretty loud when the PC speaker beeps, and there is no way to turn it down or redirect to headphones or anything like that.

When you are testing an installation script over and over late at night (while your wife is sleeping in the same room :shushing_face:), that foolish beep sounds like it’s a hundred decibels!

You can disable the beep, but you have to extract the boot images and loader.conf from the ISO, make loader.conf writeable and remove the beep option, add it back into the boot image, and repack the ISO as described here: https://wiki.archlinux.org/title/PC_speaker#Arch_Linux_ISO. It’s kind of a clunky process, plus you have to be mindful where you do it or you’ll litter whatever directory you are in with a bunch of random files that were extracted from the ISO.

Here is the same process converted into a script. It uses a temp directory for extracting files from the ISO and tidies up after itself when it’s done. It will also warn you if you try to run it without installing libisoburn and mtools first.

#!/bin/bash

# Exit on errors
set -e

# Check for required packages
check_package() {
    pacman -Qq "$1" >/dev/null 2>&1 || {
        echo "$1 is not installed."
        exit 1
    }
}
check_package libisoburn
check_package mtools

# Check if the ISO file has been provided as an argument
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <path_to_iso>"
    exit 1
fi

ISO_FILE="$1"
ISO_NAME=$(basename "$ISO_FILE" .iso)
TEMP_DIR=$(mktemp -d)

# Extract boot images and loader.conf
osirrox -indev "$ISO_FILE" -extract_boot_images "$TEMP_DIR" -extract /loader/loader.conf "$TEMP_DIR/loader.conf"

# Make loader.conf writable and remove the beep option
chmod +w "$TEMP_DIR/loader.conf"
sed '/^beep on/d' -i "$TEMP_DIR/loader.conf"

# Add the modified loader.conf to the El Torito UEFI boot image
mcopy -D oO -i "$TEMP_DIR/eltorito_img2_uefi.img" "$TEMP_DIR/loader.conf" ::/loader/

# Repack the ISO using the modified boot image and loader.conf
xorriso -indev "$ISO_FILE" \
    -outdev "${ISO_NAME}-silent.iso" \
    -map "$TEMP_DIR/loader.conf" /loader/loader.conf \
    -boot_image any replay \
    -append_partition 2 0xef "$TEMP_DIR/eltorito_img2_uefi.img"

# Clean up temporary files
rm -rf "$TEMP_DIR"

echo "Repacked ISO created: ${ISO_NAME}-silent.iso"

The way I use it is save it in /usr/local/bin (obviously name it whatever you want; mine is named silent_archiso.sh), then run it from the directory that has the ISO in it like this:

silent_archiso.sh archlinux-2025.02.01-x86_64.iso

The above outputs an ISO named archlinux-2025.02.01-x86_64-silent.iso. :shushing_face:

8 Likes

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).

Give it a try and see what you think of my gun.sh script.

#!/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/ommissions I spotted after posting.

See revised version of the script:

8 Likes
btrfs filesystem usage /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
Overall:
    Device size:		 398.49GiB
    Device allocated:		 398.48GiB
    Device unallocated:		   1.00MiB
    Device missing:		     0.00B
    Device slack:		  16.00EiB
    Used:			 354.58GiB
    Free (estimated):		  42.28GiB	(min: 42.28GiB)
    Free (statfs, df):		  42.28GiB
    Data ratio:			      1.00
    Metadata ratio:		      1.00
    Global reserve:		 486.09MiB	(used: 0.00B)
    Multiple profiles:		        no

Data,single: Size:395.45GiB, Used:353.17GiB (89.31%)

Metadata,single: Size:3.00GiB, Used:1.41GiB (46.85%)

System,single: Size:32.00MiB, Used:64.00KiB (0.20%)
 Device unallocated:		   1.00MiB

sudo btrfs filesystem usage /
Overall:
    Device size:		 398.49GiB
    Device allocated:		 398.48GiB
    Device unallocated:		   1.00MiB
    Device missing:		     0.00B
    Device slack:		     0.00B
    Used:			 354.58GiB
    Free (estimated):		  42.28GiB	(min: 42.28GiB)
    Free (statfs, df):		  42.28GiB
    Data ratio:			      1.00
    Metadata ratio:		      1.00
    Global reserve:		 486.09MiB	(used: 0.00B)
    Multiple profiles:		        no

Data,single: Size:395.45GiB, Used:353.17GiB (89.31%)
   /dev/nvme0n1p5	 395.45GiB

Metadata,single: Size:3.00GiB, Used:1.41GiB (46.85%)
   /dev/nvme0n1p5	   3.00GiB

System,single: Size:32.00MiB, Used:64.00KiB (0.20%)
   /dev/nvme0n1p5	  32.00MiB

Unallocated:
   /dev/nvme0n1p5	   1.00MiB

I am too tired for this :grin:

 btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}'
1.00MiB

I received some feedback from @SGS regarding the scripts method of remaining space calculation.

For some strange reason when @SGS ran my command:

`btrfs filesystem usage / 2> /dev/null | grep -i 'Device unallocated:' | awk '{print $3}'`

@SGS recieved an output of 1.00MiB of freespace, which was obviously completely incorrect. So, instead of grepping unallocated space I think it would be best to display the output of Free (estimated) space which outputs correctly on his system.

I’m thinking I’ll revise the section of the script relating to the free space calculation to this:

echo -e "\nAlways ensure you have adequate free space before initiating a system update"
echo "BTRFS space calculations are inexact, you appear to have the following range of values:"
echo -e "\n$(btrfs filesystem usage /  2> /dev/null | grep -i 'estimated')"

Which outputs this:

Always ensure you have adequate free space before initiating a system update
BTRFS space calculations are inexact, you appear to have the following range of values:

Free (estimated):             29.44GiB      (min: 16.73GiB)

Any comments/tips regarding the garuda-update-now script would be appreciated. Anyone with better bash skills than myself, please offer up your suggestions for code improvements. I’m sure there are others far more capable at using bash than myself that could find ways to improve this.

2 Likes

maybe garuda-update – -u could be added as “FixRounded” or something. i also know 0 things about bash anymore im full fish where i know = 0 about. lol other then basic layout

2 Likes

I’m not sure what you mean by this. Using the --u or -u parameter returns:

/usr/bin/garuda-update: invalid option 

To my knowledge there is no “u” option/parameter in the garuda-update documentation.

Please give me some further insight on your suggestion @elite .

1 Like

ah my bad I meant garuda-update -- -u its whats being suggested to users when rounded corners stops showing the outline. A quick way to rebuild it against a kwin/plasma update if for some reason its missed during a normal garuda-update.

1 Like

Ah, that works better. I was unaware of this bug, as I use a standard KDE breeze dark theme with the KDE Lite edition.

No fancy schmancy ounded corners on my comuters. :smiley:

Sure thing, that’s an easy thing to add to the script @elite .

2 Likes

I didn’t know it was a command tell recently either I used to just rebuild it from git when i saw a plasma change since plasma 6. maybe in some way it could be added to rani down the line as well. but great job on the tui it looks cool.

1 Like

This is an updated version of gun.sh (Garuda Update Now) incorperating your suggestion @elite .

#!/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 + refresh mirrorlist"
         2 "garuda-update + Chaotic AUR + AUR updates + refresh mirrorlist"
         3 "garuda-update - skip refresh mirrorlist"
         4 "garuda-update + Chaotic AUR + AUR updates - skip refresh mirrorlist"
         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"
        12 "garuda-update -- -u")

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

clear
case $CHOICE in
        1)
            echo -e "\nAlways ensure you have adequate free space before initiating a system update..."
            echo "BTRFS space calculations are inexact, you appear to have the following range of values:"
            echo -e "\n$(btrfs filesystem usage /  2> /dev/null | grep -i 'estimated')"
            echo -e "\n${lt_blue}You have selected the ${red}garuda-update${default} ${lt_blue}command, which executes:${default}"
            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)
            echo -e "\nAlways ensure you have adequate free space before initiating a system update..."
            echo "BTRFS space calculations are inexact, you appear to have the following range of values:"
            echo -e "\n$(btrfs filesystem usage /  2> /dev/null | grep -i 'estimated')"
            echo -e "\n${lt_blue}You have selected the ${red}garuda-update -a${default} ${lt_blue}command, which executes:${default}"
            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)
            echo -e "\nAlways ensure you have adequate free space before initiating a system update..."
            echo "BTRFS space calculations are inexact, you appear to have the following range of values:"
            echo -e "\n$(btrfs filesystem usage /  2> /dev/null | grep -i 'estimated')"
            echo -e "\n${lt_blue}You have selected the ${red}garuda-update --skip-mirrorlist${default} ${lt_blue}command, which executes:${default}"
            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)
            echo -e "\nAlways ensure you have adequate free space before initiating a system update..."
            echo "BTRFS space calculations are inexact, you appear to have the following range of values:"
            echo -e "\n$(btrfs filesystem usage /  2> /dev/null | grep -i 'estimated')"
            echo -e "\n${lt_blue}You have selected the ${red}garuda-update -a --skip-mirrorlist${default} ${lt_blue}command, which executes:${default}"
            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
            ;;
         12)
            echo -e "\n${lt_blue}You have selected ${red}garuda-update -- -u${default}"
            echo -e "This command will perform the following operation(s):\n"
            echo -e "Undocumented parameter to fix some update issues when receiving a warning about downgrading\n"
            echo -e "${red}Enter your sudo password to proceed... or press CTRL+C to cancel${default}\n"
            garuda-update -- -u
            ;;
esac


I modified the “free space check” language and command, as well as removing the free space pop-up warning.

2 Likes

skip-mirrorlist needs a extra - --skip-mirrorlist but testing it manually its not currently working when you just run the command garuda-update --skip-mirriorlistalso with -a” so something else might be happening there.


I would copy paste the text but vert manager wont let me.

2 Likes
garuda-update --skip-mirrorlist

Works for me^^

The command in my script garuda-update –skip-mirrorlist was copied directly from the documentation (garuda-update -h).

Thanks so much for your feedback @elite .

I have revised the script again. The problem I think happens when copying directly from the documentation that two dashes -- when pasted appears as one dash -. Not sure what’s up with that.

4 Likes

i think it might have to do with discloser itself maybe some markdown thing but glad it got all fixed up.

~Edit tested all but reinstall, all working. :+1:

1 Like