You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
5.1 KiB
117 lines
5.1 KiB
#!/bin/bash
|
|
|
|
ENABLED=yes
|
|
[[ ${ENABLED} == yes ]] || exit 0
|
|
DEBUGMODE=no
|
|
|
|
SOURCE=/usr/lib/ublinux/functions; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
|
|
SOURCE=/usr/lib/ublinux/os-config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null || exit 0
|
|
SOURCE=${SYSCONF}/config; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
|
|
SOURCE=${SYSCONF}/desktop; [[ -f ${SOURCE} ]] && . ${SOURCE} 2>/dev/null
|
|
|
|
debug_mode "$0" "$@"
|
|
|
|
systemctl --quiet --wait is-system-running
|
|
if [[ -n ${X11VNC[@]} ]]; then
|
|
OPTION_GLOBAL="-many -shared -no6"
|
|
# OPTION_GLOBAL="-many -shared -no6 -forever -dontdisconnect -noxdamage -xkb -rfbport 590%i "
|
|
if [[ -n ${X11VNC[password]} ]]; then
|
|
[[ -d /root/.vnc ]] || mkdir -p /root/.vnc
|
|
/usr/bin/x11vnc -quiet -storepasswd "$(base64 -d <<< "${X11VNC[password]}")" /root/.vnc/.passwd &>/dev/null
|
|
chmod 600 /root/.vnc/.passwd
|
|
## Show obscured password
|
|
#/usr/bin/x11vnc -showrfbauth /root/.vnc/passwd
|
|
OPTION_PASSWD="-rfbauth /root/.vnc/.passwd"
|
|
fi
|
|
if [[ -z ${X11VNC[disable]} && -z ${X11VNC[nodisplay]} && ${X11VNC[display]} != "disable" && ${X11VNC[display]} != "no" ]]; then
|
|
if systemctl --quiet is-enabled lightdm.service &>/dev/null || systemctl --quiet is-enabled lightdm-plymouth.service &>/dev/null; then
|
|
for ID_DISPLAY in /var/run/lightdm/root/:*; do
|
|
FILE_X11VNC_SERVICE="/usr/lib/systemd/system/x11vnc-ublinux:${ID_DISPLAY##*:}.service"
|
|
OPTION_DISPLAY="-display :${ID_DISPLAY##*:} -auth /var/run/lightdm/root/:${ID_DISPLAY##*:}"
|
|
OPTION_LOG="-o /var/log/x11vnc-ublinux:${ID_DISPLAY##*:}.log"
|
|
OPTION_PORT="-autoport 590${ID_DISPLAY##*:}"
|
|
mkdir -p "${FILE_X11VNC_SERVICE%/*}"
|
|
cat << EOF > "${FILE_X11VNC_SERVICE}"
|
|
[Unit]
|
|
Description=VNC Server for X11:${ID_DISPLAY##*:}
|
|
Requires=graphical.target
|
|
After=graphical.target
|
|
|
|
[Service]
|
|
#ExecStartPre=/bin/sh -c 'while ! pgrep -U "root" Xorg; do sleep 2; done'
|
|
ExecStart=
|
|
ExecStart=/usr/bin/x11vnc ${OPTION_GLOBAL} ${OPTION_PORT} ${OPTION_DISPLAY} ${OPTION_PASSWD} ${OPTION_LOG} ${X11VNC[options]}
|
|
Restart=always
|
|
RestartSec=5
|
|
SuccessExitStatus=2
|
|
|
|
[Install]
|
|
WantedBy=graphical.target
|
|
EOF
|
|
systemctl --quiet is-enabled ${FILE_X11VNC_SERVICE##*/} &>/dev/null && systemctl daemon-reload &>/dev/null
|
|
[[ -f ${FILE_X11VNC_SERVICE} ]] && systemctl --quiet enable ${FILE_X11VNC_SERVICE##*/} &>/dev/null && systemctl --quiet restart ${FILE_X11VNC_SERVICE##*/} &>/dev/null
|
|
done
|
|
elif systemctl --quiet is-enabled gdm.service &>/dev/null || systemctl --quiet is-enabled gdm-plymouth.service &>/dev/null; then
|
|
true
|
|
elif systemctl --quiet is-enabled lxdm.service &>/dev/null || systemctl --quiet is-enabled lxdm-plymouth.service &>/dev/null; then
|
|
true
|
|
elif systemctl --quiet is-enabled sddm.service &>/dev/null || systemctl --quiet is-enabled sddm-plymouth.service &>/dev/null; then
|
|
true
|
|
elif systemctl --quiet is-enabled slim.service &>/dev/null || systemctl --quiet is-enabled slim-plymouth.service &>/dev/null; then
|
|
true
|
|
fi
|
|
fi
|
|
## Создаём сервисы пользовательские
|
|
for X11VNC_NEW in "${!X11VNC[@]}"; do
|
|
if [[ ${X11VNC_NEW} =~ ^new[0-9]{1,2}$ || ${X11VNC_NEW} =~ ^tty[0-9]{1,2}$ ]]; then
|
|
## Настройка VNC для TTY
|
|
if [[ ${X11VNC_NEW} =~ ^tty[0-9]{1,2}$ ]]; then
|
|
NUM_TTY=$(sed "s/tty//" <<< ${X11VNC_NEW})
|
|
X11VNC[${X11VNC_NEW}]="${OPTION_GLOBAL} -rfbauth /root/.vnc/.passwd -rawfb vt${NUM_TTY} ${X11VNC[${X11VNC_NEW}]}"
|
|
fi
|
|
FILE_X11VNC_SERVICE="/usr/lib/systemd/system/x11vnc-ublinux-${X11VNC_NEW}.service"
|
|
OPTION_LOG="-o /var/log/x11vnc-ublinux-${X11VNC_NEW}.log"
|
|
OPTION_PORT="-autoport 5900"
|
|
if NUM_TTY=$(egrep --only-matching -- "-rawfb vt[0-9]{1,2}" <<< ${X11VNC[${X11VNC_NEW}]} | head -1 | sed "s/-rawfb vt//") && [[ -n ${NUM_TTY} ]]; then
|
|
systemctl start getty@tty${NUM_TTY}.service
|
|
fi
|
|
if grep --quiet -- "-display" <<< ${X11VNC[${X11VNC_NEW}]}; then
|
|
SERVICE_UNIT="[Unit]
|
|
Description=VNC Server ${X11VNC_NEW}
|
|
Requires=graphical.target
|
|
After=graphical.target"
|
|
SERVICE_INSTALL="[Install]
|
|
WantedBy=graphical.target"
|
|
else
|
|
SERVICE_UNIT="[Unit]
|
|
Description=VNC Server - ${X11VNC_NEW}"
|
|
SERVICE_INSTALL="[Install]
|
|
WantedBy=multi-user.target"
|
|
fi
|
|
mkdir -p "${FILE_X11VNC_SERVICE%/*}"
|
|
cat << EOF > "${FILE_X11VNC_SERVICE}"
|
|
${SERVICE_UNIT}
|
|
|
|
[Service]
|
|
ExecStart=
|
|
ExecStart=/usr/bin/x11vnc ${OPTION_PORT} ${OPTION_LOG} ${X11VNC[${X11VNC_NEW}]}
|
|
Restart=always
|
|
RestartSec=5
|
|
SuccessExitStatus=2
|
|
|
|
${SERVICE_INSTALL}
|
|
EOF
|
|
systemctl --quiet is-enabled ${FILE_X11VNC_SERVICE##*/} &>/dev/null && systemctl daemon-reload &>/dev/null
|
|
[[ -f ${FILE_X11VNC_SERVICE} ]] && systemctl --quiet enable ${FILE_X11VNC_SERVICE##*/} &>/dev/null && systemctl --quiet restart ${FILE_X11VNC_SERVICE##*/} &>/dev/null
|
|
fi
|
|
done
|
|
else
|
|
## Если в режиме полного сохранения настройку убрали, то отключаем
|
|
for FILE_X11VNC_SERVICE in /usr/lib/systemd/system/x11vnc-ublinux*.service; do
|
|
if [[ -e ${FILE_X11VNC_SERVICE} ]]; then
|
|
systemctl --quiet disable --now ${FILE_X11VNC_SERVICE##*/} &>/dev/null
|
|
rm -f ${FILE_X11VNC_SERVICE}
|
|
fi
|
|
done
|
|
fi
|