#!/bin/sh

# Creates an "Install Whonix" or "Install Kicksecure" icon on the live session tested with:
# Xfce, LXDE, LXqt, Gnome, KDE, Mate, Cinnamon

set -x

true "$0: START"

set -e

# We query xdg-user-dir because the Desktop directory has different
# names for different languages
DESKTOP=$(xdg-user-dir DESKTOP)

# Create ~/Desktop just in case this runs before the xdg folder
# creation script.
mkdir --parents ~/Desktop

if test -f /usr/share/kicksecure/marker ; then
   project_name="Kicksecure"
elif test -f /usr/share/whonix/marker ; then
   project_name="Whonix-Host"
else
   project_name="unknown-fork"
fi

# Among the Debian desktop environments, LXDE is the only one
# that behaves completely different.
if [ -f /usr/bin/lxsession ]; then
    echo "[Desktop Entry]" > ~/Desktop/install-host.desktop
    echo "Type=Link" >> ~/Desktop/install-host.desktop
    echo "Name=Install ${project_name}" >> ~/Desktop/install-host.desktop
    echo "Icon=install-${project_name}" >> ~/Desktop/install-host.desktop
    echo "URL=/usr/share/applications/install-host.desktop" \
          >> ~/Desktop/install-host.desktop
else
    cp /usr/share/applications/install-host.desktop ~/Desktop
    # Xfce needs this executable otherwise it complains, everything
    # else doesn't seem to care either way.
    chmod +x ~/Desktop/install-host.desktop
fi

## Avoid Xfce "Untrusted application launcher"
## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1037299
## https://forum.xfce.org/viewtopic.php?id=16357
f=~/Desktop/install-host.desktop
gio set -t string "$f" metadata::xfce-exe-checksum "$(sha256sum "$f" | awk '{print $1}')"

true "$0: END"
