91 lines
2.7 KiB
Bash
91 lines
2.7 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# install_anydesk_unattended.sh
|
|
# Installs AnyDesk on Linux Mint (Ubuntu/Debian based) from the official
|
|
# repository and sets a password for unattended access.
|
|
#
|
|
# Usage:
|
|
# sudo ./install_anydesk_unattended.sh
|
|
# sudo ANYDESK_PASSWORD='YourStrongPassword' ./install_anydesk_unattended.sh
|
|
#
|
|
# If ANYDESK_PASSWORD is not set, you will be prompted for it (input hidden).
|
|
|
|
set -euo pipefail
|
|
|
|
# ---------- Checks ----------
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script must be run as root. Try: sudo $0" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v apt-get >/dev/null 2>&1; then
|
|
echo "apt-get not found. This script is intended for Linux Mint / Debian / Ubuntu." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# ---------- Get the password ----------
|
|
PASSWORD="${ANYDESK_PASSWORD:-}"
|
|
|
|
if [[ -z "$PASSWORD" ]]; then
|
|
read -r -s -p "Enter unattended access password: " PASSWORD
|
|
echo
|
|
read -r -s -p "Confirm password: " PASSWORD2
|
|
echo
|
|
if [[ "$PASSWORD" != "$PASSWORD2" ]]; then
|
|
echo "Passwords do not match." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [[ ${#PASSWORD} -lt 10 ]]; then
|
|
echo "Password must be at least 10 characters (use a long, unique one)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# ---------- Add the official AnyDesk repository ----------
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt-get update -qq
|
|
apt-get install -y -qq ca-certificates curl gnupg
|
|
|
|
install -d -m 0755 /etc/apt/keyrings
|
|
curl -fsSL https://keys.anydesk.com/repos/DEB-GPG-KEY \
|
|
| gpg --dearmor --yes -o /etc/apt/keyrings/anydesk.gpg
|
|
chmod 0644 /etc/apt/keyrings/anydesk.gpg
|
|
|
|
echo "deb [signed-by=/etc/apt/keyrings/anydesk.gpg] https://deb.anydesk.com/ all main" \
|
|
> /etc/apt/sources.list.d/anydesk-stable.list
|
|
|
|
# ---------- Install ----------
|
|
apt-get update -qq
|
|
apt-get install -y anydesk
|
|
|
|
# ---------- Make sure the service is running ----------
|
|
systemctl enable --now anydesk.service
|
|
|
|
# Give the service a few seconds to initialise
|
|
for _ in {1..15}; do
|
|
if anydesk --get-id >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# ---------- Set the unattended access password ----------
|
|
# The password is piped via stdin so it never appears in the process list.
|
|
if ! printf '%s\n' "$PASSWORD" | anydesk --set-password; then
|
|
echo "Failed to set the AnyDesk password." >&2
|
|
exit 1
|
|
fi
|
|
unset PASSWORD PASSWORD2
|
|
|
|
# ---------- Done ----------
|
|
ID="$(anydesk --get-id 2>/dev/null || echo 'unavailable (try again in a moment)')"
|
|
echo
|
|
echo "AnyDesk installed and unattended access password set."
|
|
echo "AnyDesk ID: $ID"
|
|
echo
|
|
echo "Notes:"
|
|
echo " - Linux Mint should use an X11 session (the default); AnyDesk does not support Wayland."
|
|
echo " - To connect after a reboot, the machine must be on and at the login screen or logged in."
|