#!/bin/bash

OS_TYPE="unknown"
if [ -f /etc/os-release ]; then
    . /etc/os-release
    if [[ "$ID" == "arch" ]] || [[ "$ID_LIKE" == *"arch"* ]]; then
        OS_TYPE="arch"
    else
        OS_TYPE="debian_ubuntu"
    fi
fi

echo "Resetting RustDesk password..."

if [[ "$OS_TYPE" == "debian_ubuntu" ]]; then
    sudo runuser -l stellarmate -c "rustdesk &"
    sleep 2
    sudo rustdesk --password stellar@Mate123!
    sudo pkill rustdesk

elif [[ "$OS_TYPE" == "arch" ]]; then
    sudo -u stellarmate rustdesk &
    sleep 2
    sudo rustdesk --password stellar@Mate123!
    sudo pkill rustdesk
fi

sudo systemctl stop rustdesk 2>/dev/null
sudo systemctl disable rustdesk 2>/dev/null
