#!/bin/bash


# Libfuse2 for apt based systems
if [ -f /usr/bin/apt ]; then
	REQUIRED_PKG="libfuse2t64"
	echo "Checking for $REQUIRED_PKG..."
	PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG 2>/dev/null | grep "install ok installed")

	if [ "" == "$PKG_OK" ]; then
	  echo "$REQUIRED_PKG not found. Installing now..."
	  pkexec bash -c "apt update && apt install -y $REQUIRED_PKG"
	else
	  echo "$REQUIRED_PKG is already installed. Proceeding..."
	fi
fi

cd $HOME/Downloads
if [ ! -f rustdesk*.AppImage ]; then
	wget https://github.com/rustdesk/rustdesk/releases/download/1.4.6/rustdesk-1.4.6-x86_64.AppImage
fi

# Ensure the RustDesk config directory exists
mkdir -p ~/.config/rustdesk

# Append the server configuration to the TOML file
echo "" > ~/.config/rustdesk/RustDesk2.toml
cat <<EOF >> ~/.config/rustdesk/RustDesk2.toml
rendezvous_server = 'portal.linuxguides.de:21116'

[options]
relay-server = 'portal.linuxguides.de'
custom-rendezvous-server = 'portal.linuxguides.de'
key = 'eWzyGWTUmnm8N6jDZko549upnDUVO0ifXvTNx5XMAOY='
EOF

chmod +x rustdesk-1.4.6-x86_64.AppImage
./rustdesk-1.4.6-x86_64.AppImage

