set allow-duplicate-recipes := false
set ignore-comments := true

_default:
	#!/usr/bin/env bash
	/usr/bin/just --list --list-heading $'Available commands:\n' --list-prefix $' - '

reset-gnome-user-custom-keybindings:
	#!/usr/bin/env bash
	dconf reset -f /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/
	dconf reset -f /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings

reorder-gnome-apps:
	#!/usr/bin/env bash
	if which gsettings >/dev/null; then
		gsettings set org.gnome.shell app-picker-layout "[]"
		echo "Reordered!"
		exit 0
	else
		echo "No GNOME installed"
		exit 1
	fi

reboot-to-uefi:
	#!/usr/bin/env bash
	if [ -d /sys/firmware/efi ]; then
		gum confirm "Reboot to UEFI?" && systemctl reboot --firmware-setup
	else
		echo "Rebooting to legacy BIOS from OS is not supported."
	fi

logs-this-boot:
	#!/usr/bin/env bash
	sudo journalctl --no-hostname -b 0

logs-last-boot:
	#!/usr/bin/env bash
	sudo journalctl --no-hostname -b -1


system-update:
	#!/usr/bin/env bash
	echo "== Update Fisher =="
	fish -c "source /usr/share/fish/vendor_conf.d/10-fisher.fish; if type -q fisher; if string length --quiet (fisher list); fisher update >/dev/null; end; end"
	echo "== Update Mise Tools =="
	mise upgrade
	echo "== Update Krew Tools =="
	krew upgrade
	echo "== Update Flatpak Applications =="
	flatpak update --assumeyes --noninteractive
	echo "== Update System Image =="
	sudo bootc upgrade

	key=$(gum choose Quit Reboot Poweroff)
	if [[ $key == "Quit" ]]; then
		break
	elif [[ $key == "Poweroff" ]]; then
		systemctl poweroff
	elif [[ $key == "Reboot" ]]; then
		systemctl reboot
	fi

system-clean:
	#!/usr/bin/env bash
	podman image prune -af
	podman volume prune -f
	sudo docker image prune -af
	sudo docker volume prune -f
	flatpak uninstall --unused --noninteractive --assumeyes

[no-exit-message]
firmware-update:
	#!/usr/bin/env bash
	if gum confirm; then
		fwupdmgr refresh --force
		fwupdmgr update
	fi

changelogs:
	#!/usr/bin/env bash
	rpm-ostree db diff --changelogs

bios-info:
	#!/usr/bin/env bash
	echo "Manufacturer: $(sudo dmidecode -s baseboard-manufacturer)"
	echo "Product Name: $(sudo dmidecode -s baseboard-product-name)"
	echo "Version: $(sudo dmidecode -s bios-version)"
	echo "Release Date: $(sudo dmidecode -s bios-release-date)"

setup-libvirt-group:
	#!/usr/bin/env bash
	sudo groupadd --system -f libvirt
	sudo usermod -a -G libvirt "$(whoami)"

install-steam:
	#!/usr/bin/env fish
	function install-package
		flatpak --noninteractive --assumeyes install $argv[1]
	end
	install-package com.valvesoftware.Steam
	install-package net.davidotek.pupgui2
	install-package org.freedesktop.Platform.VulkanLayer.MangoHud
	install-package org.freedesktop.Platform.VulkanLayer.gamescope

install-recommended-fisher-plugins:
	#!/usr/bin/env fish
	source /usr/share/fish/vendor_conf.d/fisher.fish
	function install-plugin
		fisher install $argv[1]
	end
	install-plugin blackjid/plugin-kubectl
	install-plugin halostatue/fish-chezmoi
	install-plugin jorgebucaran/autopair.fish
	install-plugin jorgebucaran/getopts.fish
	install-plugin jorgebucaran/replay.fish
	install-plugin lewisacidic/fish-git-abbr
	install-plugin nickeb96/puffer-fish
	install-plugin lukasgierth/docker-abbr
	#install-plugin meaningful-ooo/sponge


install-recommended-misetools:
	#!/usr/bin/env bash
	echo "Example for additional tools:"
	echo ""
	echo "mise-install-global calicoctl@latest"
	echo "mise-install-global teleport-community@latest"
	echo "mise-install-global velero@latest"
	echo "mise-install-global flux2@latest"

install-recommended-krewtools:
	#!/usr/bin/env bash
	if which krew >/dev/null; then
		# add extra repo for netshoot
		krew index add netshoot https://github.com/nilic/kubectl-netshoot.git

		krew install cert-manager
		krew install cnpg
		krew install ctx
		krew install konfig
		krew install ktop
		krew install kubescape
		krew install kubetail
		krew install netshoot/netshoot
		krew install node-resource
		krew install ns
		krew install radar
		krew install relay
		krew install stern
	else
		echo "krew not installed!"
		exit 1
	fi

show-toolbox-examples:
	#!/usr/bin/env bash
	echo "Example for Images:"
	echo "toolbox create -c rhel-8 -i registry.access.redhat.com/ubi8/toolbox:latest"
	echo "toolbox create -c rhel-9 -i registry.access.redhat.com/ubi9/toolbox:latest"
	echo "toolbox create -c rhel-10 -i registry.access.redhat.com/ubi10/toolbox:latest"
	echo "toolbox create -c fedora-41 -i registry.fedoraproject.org/fedora-toolbox:41"

show-distrobox-examples:
	#!/usr/bin/env bash
	echo "Example for Images:"
	echo "distrobox create -n alma -i quay.io/toolbx-images/almalinux-toolbox:latest"
	echo "distrobox create -n arch -i ghcr.io/ublue-os/arch-toolbox:latest"
	echo "distrobox create -n centos -i quay.io/toolbx-images/centos-toolbox:latest"
	echo "distrobox create -n debian -i quay.io/toolbx-images/debian-toolbox:unstable"
	echo "distrobox create -n fedora -i ghcr.io/ublue-os/fedora-toolbox:latest"
	echo "distrobox create -n opensuse -i quay.io/toolbx-images/opensuse-toolbox:tumbleweed"
	echo "distrobox create -n ubuntu -i ghcr.io/ublue-os/ubuntu-toolbox:latest"

set-hostname:
	#!/usr/bin/env bash
	if INPUT_STR=$(gum input --placeholder hostname); then
		sudo hostnamectl hostname "${INPUT_STR}"
	fi
