#!/bin/sh

has_gui() {
    for dm in gdm gdm3 lightdm sddm xdm lxdm; do
        if systemctl is-active --quiet "$dm" 2>/dev/null || \
           systemctl is-enabled --quiet "$dm" 2>/dev/null; then
            return 0
        fi
    done
    if command -v Xorg &>/dev/null || command -v X &>/dev/null; then
        return 0
    fi
    return 1
}

rm /etc/custom/mydebian_helper/starship.toml
wget -O /etc/custom/mydebian_helper/starship.toml https://download.al1al7.de/vim/starship/starship.toml

if (! has_gui); then
	echo "No GUI - do not install nerd fonts"
	exit 0
fi

if [ ! -d "/usr/share/fonts/custom" ]; then
	mkdir -p /usr/share/fonts/custom
	chmod 0755 /usr/share/fonts/custom
fi

if [ ! -f "/usr/share/fonts/custom/MononokiNerdFont-Bold.ttf" ]; then
	wget -O /usr/share/fonts/custom/MononokiNerdFont-Bold.ttf https://download.al1al7.de/vim/starship/MononokiNerdFont-Bold.ttf
	chmod 644 /usr/share/fonts/custom/MononokiNerdFont-Bold.ttf
	rm -rf /var/cache/fontconfig/*
	fc-cache -fv
fi

exit 0
