#!/bin/bash

# Check if the system is in live mode by checking the root filesystem type
root_fs_type=$(findmnt -n -o FSTYPE /)

# If the root filesystem is overlay or squashfs, we are likely in live mode
if [ "$root_fs_type" == "overlay" ] || [ "$root_fs_type" == "squashfs" ]; then
    # Path to the live user's Desktop directory
    desktop_dir="/home/pep/Desktop"

    # Create the .desktop file for Calamares
    cat << EOF > "$desktop_dir/Calamares.desktop"
[Desktop Entry]
Type=Application
Name=Install Peppermint
Name[bg]=Инсталиране на Peppermint
Name[es]=Instale Peppermint
Name[fr]= Installer Peppermint
Name[hu]=Telepítse a Peppermint
Name[it]=Installare Peppermint
Name[ja]=インストール  Peppermint
Name[pt]=Instalar Peppermint
Name[pt_BR]=Instalar Peppermint
Name[ru]=Установить Peppermint
Comment=Install Peppermintos
Exec=sudo calamares
Icon=peppermint-inst.png
Terminal=false
Categories=System;
EOF

# Set permissions for the .desktop file
    chmod +x "$desktop_dir/Calamares.desktop"

    # Mark the desktop launcher as trusted (for GNOME/XFCE)
    gio set --type=string "$desktop_dir/Calamares.desktop" metadata::trusted true
    gio set --type=string "$desktop_dir/Calamares.desktop" metadata::xfce-exe-checksum \
        "$(sha256sum "$desktop_dir/Calamares.desktop" | cut -f1 -d' ')"
    
    # Update the timestamp for the .desktop file
    touch "$desktop_dir/Calamares.desktop"
fi
    
