#!/usr/bin/env bash # # gnf – Friendly wrapper around 'sudo dnf' # Version 1.2 # Author: You # # Features: # • Implicit '-y' on install/remove/reinstall/downgrade (toggle with -n/--no-confirm) # • 'gnf update' pipeline: # - dnf update [-y] [--refresh] # - flatpak update (user + system) # - optional fwupd refresh+update # with its own flags: -r/--refresh, -f/--firmware, -n/--no-confirm, -y/--yes # • Passes any other 'dnf' subcommand straight to sudo dnf # • 'copr' sub-commands get auto '-y' for addrepo/removerepo/enable/disable/list set -euo pipefail PROGRAM=$(basename "$0") VERSION="1.2" usage() { cat <&2 usage exit 1 fi cmd=$1; shift # Treat 'upgrade' as alias for 'update' [[ "$cmd" == "upgrade" ]] && cmd=update # # 2) Dispatch on COMMAND # case "$cmd" in # --------------------------------------------------------------- # install/remove/reinstall/downgrade (auto '-y' unless -n) # --------------------------------------------------------------- install|remove|reinstall|downgrade) dnf_args=() $auto_yes && dnf_args+=(-y) sudo dnf "$cmd" "${dnf_args[@]}" "$@" exit $? ;; # --------------------------------------------------------------- # update pipeline # --------------------------------------------------------------- update) # 2.1) Map any long opts to short ones for getopts mapped=() for arg in "$@"; do case "$arg" in --refresh) mapped+=(-r) ;; --firmware) mapped+=(-f) ;; --no-confirm) mapped+=(-n) ;; --yes) mapped+=(-y) ;; --) mapped+=(--);; *) mapped+=("$arg");; esac done # 2.2) Parse update-specific flags with getopts (supports grouping: -rf) refresh=false firmware=false confirm=$auto_yes OPTIND=1 # note: the leading colon suppresses getopts’ own error msg while getopts ":rfny" opt "${mapped[@]}"; do case "$opt" in r) refresh=true ;; f) firmware=true ;; n) confirm=false ;; y) confirm=true ;; \?) echo "Unknown option '-$OPTARG' for update" >&2; exit 1 ;; esac done shift $((OPTIND - 1)) # 2.3) Run the dnf update dnf_args=() $confirm && dnf_args+=(-y) $refresh && dnf_args+=(--refresh) sudo dnf update "${dnf_args[@]}" "$@" # 2.4) Run flatpak updates (user then system) flatpak update -y sudo flatpak update # 2.5) Optional firmware via fwupd if $firmware; then sudo fwupdmgr refresh sudo fwupdmgr update fi exit $? ;; # --------------------------------------------------------------- # copr sub-commands # --------------------------------------------------------------- copr) if [[ $# -lt 1 ]]; then echo "Error: 'gnf copr' requires a subcommand." >&2 exit 1 fi sub=$1; shift case "$sub" in addrepo|removerepo|enable|disable|list) sudo dnf copr "$sub" -y "$@" ;; *) sudo dnf copr "$sub" "$@" ;; esac exit $? ;; # --------------------------------------------------------------- # anything else → pass straight to sudo dnf # --------------------------------------------------------------- *) sudo dnf "$cmd" "$@" exit $? ;; esac