-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenable-remote-desktop
More file actions
executable file
·124 lines (103 loc) · 2.66 KB
/
enable-remote-desktop
File metadata and controls
executable file
·124 lines (103 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash -eu
#
# Enable remote desktop
#
function keyring_is_locked()
{
python3 -c "
import sys
import secretstorage
conn = secretstorage.dbus_init()
coll = secretstorage.get_default_collection(conn)
sys.exit(0 if coll.is_locked() else 1)
"
}
function usage()
{
cat <<EOF
Usage: $(basename "${0}") [-h] [-v]
Enable GNOME remote desktop.
Environment variables:
PASSWORD Password for the current user. If not set, prompt for it.
Optional arguments:
-h, --help Show this help text and exit.
-v, --virtual Create a virtual monitor rather than mirroring the primary
monitor.
EOF
}
if [ "$(id -u)" -eq 0 ] ; then
echo "You cannot run this tool as root" >&2
exit 1
fi
virtual=0
while [ ${#} -gt 0 ] ; do
case "${1}" in
-h|--help)
usage
exit
;;
-v|--virtual)
virtual=1
;;
*)
echo "Invalid argument: ${1}" >&2
exit 2
;;
esac
shift
done
if ! python3 -c 'import secretstorage' >/dev/null 2>&1 ; then
echo "python3 secretstorage module is not available/installed" >&2
exit 1
fi
password=${PASSWORD:-}
if [ -z "${password}" ] ; then
read -r -s -p "Password for user ${USER}: " password
echo
fi
# Unlock the GNOME keyring
if keyring_is_locked ; then
echo "-- Unlock GNOME keyring"
killall -u "${USER}" gnome-keyring-daemon
echo -n "${password}" | $(which gnome-keyring-daemon) --daemonize --login
$(which gnome-keyring-daemon) --start
fi
# Disable screen blank
echo "-- Disable screen blanking"
gsettings set org.gnome.desktop.session idle-delay "uint32 0"
# Disable automatic suspend
#gsettings set org.gnome.settings-daemon.plugins.power \
# sleep-inactive-ac-type "nothing"
echo "-- Configure and enable RDP"
if [ ${virtual} -eq 1 ] ; then
# Create a virtual monitor
gsettings set org.gnome.desktop.remote-desktop.rdp \
screen-share-mode "extend"
else
# FIXME: do we need 'loginctl unlock-sessions'
# Mirror the primary monitor (default)
gsettings set org.gnome.desktop.remote-desktop.rdp \
screen-share-mode "mirror-primary"
fi
# Set RDP TLS certificate and key
d=${HOME}/.local/share/gnome-remote-desktop
tls_crt=${d}/rdp-tls.crt
tls_key=${d}/rdp-tls.key
if ! [ -e "${tls_crt}" ] ; then
echo "-- Generate RDP TLS certitificate and key"
mkdir -p "${d}"
openssl req -nodes -new -x509 -keyout "${tls_key}" -out "${tls_crt}" \
-days 1000 -subj "/CN=GNOME/C=US"
fi
grdctl rdp set-tls-cert "${tls_crt}"
grdctl rdp set-tls-key "${tls_key}"
# Allow full control and enable RDP
grdctl rdp set-credentials "${USER}" "${password}"
grdctl rdp disable-view-only
grdctl rdp enable
# Restart the service
echo "-- Restart RDP daemon"
systemctl --user restart gnome-remote-desktop
# Show status
echo "-- Status"
grdctl status