#!/bin/bash

. ${TOOLKIT}-functions.sh

$SOMETHING_CHANGED && {
	restart_service ku-rustdesk-server-hbbr
	restart_service ku-rustdesk-server-hbbs
}

keyfile="/var/lib/rustdesk-server/id_ed25519.pub"

[ -f $keyfile ] && {
	pubkey=$(cat $keyfile)
	outfile=/etc/kusa/conf.d/zz-srv-rustdesk
	tmpfile=srv-rustdesk.tmp
	server=$(uname -n)

	echo "# do not edit - file automatically saved by 'kusa'" >$tmpfile
	echo "#"			>>$tmpfile
	echo "[srv-rustdesk]"		>>$tmpfile
	echo "  pubkey	$pubkey"	>>$tmpfile
	echo "  keyfile	$keyfile"	>>$tmpfile
	echo "  server	$server"	>>$tmpfile

	installfile $tmpfile $outfile root:root 440

	echo
	echo "info saved in $outfile"
	echo
	cat $outfile
	echo

}

exit 0
