#!/bin/bash


# Mimic behavior of old openSUSE-welcome with "Show on next boot" unchecked
cp /etc/xdg/xdg/autostart/org.opensuse.opensuse_welcome_mini.desktop ${HOME}.config/autostart/org.opensuse.opensuse_welcome_mini.desktop

# Override also the original's openSUSE-welcome startup
# User can tick/untick it in case that if it pops up as a fallback at the end
cp /etc/xdg/xdg/autostart/org.opensuse.opensuse_welcome.desktop ${HOME}.config/autostart/org.opensuse.opensuse_welcome.desktop

detect_de() {
    if [ -n "$XDG_CURRENT_DESKTOP" ]; then
        echo "$XDG_CURRENT_DESKTOP" | tr '[:upper:]' '[:lower:]'
    elif [ -n "$DESKTOP_SESSION" ]; then
        echo "$DESKTOP_SESSION" | tr '[:upper:]' '[:lower:]'
    else
        echo ""
    fi
}

de=$(detect_de)
welcome_binary=""

# Prefer Session specific greeter
if [[ "$de" == *plasma* ]]; then
    welcome_binary=$(command -v plasma-welcome)
elif [[ "$de" == *gnome* ]]; then
    welcome_binary=$(command -v gnome-tour)
fi

# Fallback to opensuse-welcome if nothing else is found
if [[ -z "$welcome_binary" ]]; then
    welcome_binary=$(command -v opensuse-welcome)
else
fi

if [[ -z "$welcome_binary" ]]; then
    $welcome_binary
else
    echo "No welcome tool available, however, we can't leave it like this!"
    echo "So let me tell you at least Welcome and Have a lot of fun!"
fi
