#!/bin/bash
# postinst script

# Read the saved path from the temporary file
default_terminal_path=$(cat /tmp/default_terminal_path)

# Check and restore the path
if [ ! -z "$default_terminal_path" ] && [ "$(readlink -f /usr/bin/x-terminal-emulator)" != "$default_terminal_path" ]; then
   # Restore the previous selection
   update-alternatives --set x-terminal-emulator "$default_terminal_path"
fi

# Clean up: Remove temporary file
rm -f /tmp/default_terminal_path

# Autostart section
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
AUTOSTART_DIR="$USER_HOME/.config/autostart"
if [ ! -d "$AUTOSTART_DIR" ]; then
    mkdir -p "$AUTOSTART_DIR"
fi

# Copy Autostart file to the user's autostart directory
cp /usr/share/applications/autostart/primo-di-tutto-autostart.desktop "$AUTOSTART_DIR/"
chmod +x "$AUTOSTART_DIR/primo-di-tutto-autostart.desktop"