Handy scripts you'd like to share

Sometimes it happens, so: toggle-chaotic-r2

#!/bin/bash
cml='/etc/pacman.d/chaotic-mirrorlist' cdn='Server = https://cdn-mirror.chaotic.cx'
case "$1" in
  off) sed -Ei 's|^\s*'"$cdn"'|#&|' $cml ;;
   on) sed -Ei 's|^\s*#\s*('"$cdn"'.*)|\1|' $cml ;;
    *) echo "usage: sudo ${0##*/} on|off"
       grep -q '^\s*#\s*'"$cdn" $cml && echo 'R2 disabled' || echo 'R2 enabled'
esac

Move grep down one line to always report enabled/disabled after toggling.

Yes, final ;; is missing and bash is happy with it. Even shellcheck does not complain.

The gods would curse me if I don’t invoke sed often enough :slight_smile:

3 Likes