Wait for Linux RustDesk service before setting password
This commit is contained in:
@@ -198,6 +198,30 @@ EOF
|
|||||||
|
|
||||||
systemctl restart rustdesk
|
systemctl restart rustdesk
|
||||||
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not start.'
|
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not start.'
|
||||||
|
wait_for_rustdesk_server
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_rustdesk_server() {
|
||||||
|
local attempt
|
||||||
|
local candidate_id
|
||||||
|
|
||||||
|
# `systemctl is-active` only confirms that the launcher is alive. On Linux
|
||||||
|
# it still needs to start the `--server` process for the greeter account.
|
||||||
|
# Calling `rustdesk --password` during that short window returns successfully
|
||||||
|
# but does not persist a password for the remote-access process.
|
||||||
|
for attempt in $(seq 1 20); do
|
||||||
|
if systemctl is-active --quiet rustdesk \
|
||||||
|
&& pgrep -f '/usr/share/rustdesk/rustdesk --server' >/dev/null 2>&1; then
|
||||||
|
candidate_id=$(rustdesk --get-id 2>/dev/null | tail -n 1 | tr -d '[:space:]')
|
||||||
|
if [[ $candidate_id =~ ^[0-9]+$ ]]; then
|
||||||
|
RUSTDESK_ID=$candidate_id
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
fail 'The RustDesk greeter-side server did not become ready within 20 seconds.'
|
||||||
}
|
}
|
||||||
|
|
||||||
set_access_password() {
|
set_access_password() {
|
||||||
@@ -214,29 +238,17 @@ set_access_password() {
|
|||||||
chmod 600 "$secret_path"
|
chmod 600 "$secret_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rustdesk --password "$ACCESS_PASSWORD" >/dev/null
|
local password_result
|
||||||
|
wait_for_rustdesk_server
|
||||||
|
password_result=$(rustdesk --password "$ACCESS_PASSWORD" 2>&1) \
|
||||||
|
|| fail "RustDesk rejected the permanent password update: $password_result"
|
||||||
|
[[ $password_result == *Done!* ]] \
|
||||||
|
|| fail "RustDesk did not acknowledge the permanent password update: $password_result"
|
||||||
rustdesk --option verification-method use-permanent-password >/dev/null
|
rustdesk --option verification-method use-permanent-password >/dev/null
|
||||||
rustdesk --option approve-mode password >/dev/null
|
rustdesk --option approve-mode password >/dev/null
|
||||||
if id lightdm >/dev/null 2>&1; then
|
|
||||||
local lightdm_uid
|
|
||||||
lightdm_uid=$(id -u lightdm)
|
|
||||||
runuser -u lightdm -- env HOME=/var/lib/lightdm \
|
|
||||||
XDG_CONFIG_HOME=/var/lib/lightdm/.config \
|
|
||||||
XDG_RUNTIME_DIR="/run/user/${lightdm_uid}" \
|
|
||||||
/usr/share/rustdesk/rustdesk --password "$ACCESS_PASSWORD" >/dev/null
|
|
||||||
runuser -u lightdm -- env HOME=/var/lib/lightdm \
|
|
||||||
XDG_CONFIG_HOME=/var/lib/lightdm/.config \
|
|
||||||
XDG_RUNTIME_DIR="/run/user/${lightdm_uid}" \
|
|
||||||
/usr/share/rustdesk/rustdesk --option verification-method use-permanent-password >/dev/null
|
|
||||||
runuser -u lightdm -- env HOME=/var/lib/lightdm \
|
|
||||||
XDG_CONFIG_HOME=/var/lib/lightdm/.config \
|
|
||||||
XDG_RUNTIME_DIR="/run/user/${lightdm_uid}" \
|
|
||||||
/usr/share/rustdesk/rustdesk --option approve-mode password >/dev/null
|
|
||||||
fi
|
|
||||||
systemctl restart rustdesk
|
systemctl restart rustdesk
|
||||||
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not restart after setting its permanent password.'
|
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not restart after setting its permanent password.'
|
||||||
RUSTDESK_ID=$(rustdesk --get-id 2>/dev/null | tail -n 1 | tr -d '[:space:]')
|
wait_for_rustdesk_server
|
||||||
[[ $RUSTDESK_ID =~ ^[0-9]+$ ]] || fail "RustDesk returned an invalid device ID: $RUSTDESK_ID"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register_with_controller() {
|
register_with_controller() {
|
||||||
|
|||||||
Reference in New Issue
Block a user