Last active
August 16, 2024 18:16
-
-
Save j1cs/b9e84a05c676149b51c351b61620b50e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Config file for /etc/init.d/tigervnc | |
# Add the user(s) Xvnc(1) should be run for to /etc/tigervnc/vncserver.users | |
# DISPLAYS is no loger used. | |
# Optionally override the default Xsession file | |
# TIGERVNC_XSESSION_FILE="/usr/share/sddm/scripts/Xsession" | |
# TIGERVNC_XSESSION_FILE="/etc/gdm/Xsession" | |
# TIGERVNC_XSESSION_FILE="/etc/lightdm/Xsession" | |
# TIGERVNC_XSESSION_FILE="/usr/share/slim/Xsession" | |
# vncsession no longer supports VNC_OPTS | |
# Use /etc/tigervnc/vncserver-config-defaults or $HOME/.config/tigervnc/config instead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sbin/openrc-run | |
# Copyright 1999-2022 Gentoo Authors | |
# Distributed under the terms of the GNU General Public License, v2 or later | |
# shellcheck shell=sh | |
# Create symlinks for all displays. | |
# For example for display :1, run `ln -s tigervnc /etc/init.d/tigervnc.1` | |
# Then `rc-update add tigervnc.1 default` | |
# For compatibility, /etc/init.d/tigervnc will start all displays. | |
DISPLAYS=${SVCNAME#*.} | |
if [ "$DISPLAYS" = "tigervnc" ]; then | |
should_warn=1 | |
DISPLAYS=$(grep -v "^#" /etc/tigervnc/vncserver.users | sed -e 's/=.*//' -e 's/^://') | |
fi | |
depend() { | |
need net | |
} | |
checkconfig() { | |
if [ -n "${DISPLAYS}" ]; then | |
if [ "$1" = "start" ]; then | |
for display in $DISPLAYS; do | |
user="$(grep "^:${display}" /etc/tigervnc/vncserver.users)" | |
user=${user#*=} | |
if [ -z "${user}" ]; then | |
eerror "User is not defined for display :${display} in /etc/tigervnc/vncserver.users" | |
return 1 | |
elif [ -e "/tmp/.X11-unix/X${display}" ]; then | |
eerror "Display :${display} appears to be already in use because of /tmp/.X11-unix/X${display}" | |
eerror "Remove this file if there is no X server for :${display}" | |
return 1 | |
elif [ -e "/tmp/.X${display}-lock" ]; then | |
eerror "Display :${display} appears to be already in use because of /tmp/.X${display}-lock" | |
eerror "Remove this file if there is no X server for :${display}" | |
return 1 | |
# bug #690046 | |
# The default config directory is now ~/.config/tigervnc, but still supports ~/.vnc if not found | |
# Only warn if password is missing, do not error out. See bug #936442 | |
elif ! runuser -l "${user}" -s /bin/bash -c \ | |
"[[ ( -d ${XDG_CONFIG_HOME:-~/.config}/tigervnc && -f ${XDG_CONFIG_HOME:-~/.config}/tigervnc/passwd ) || ( ! -d ${XDG_CONFIG_HOME:-~/.config}/tigervnc && -f ~/.vnc/passwd ) ]]"; then | |
ewarn "There are no passwords defined for user ${user}. The server may not start." | |
fi | |
FREEDISPLAYS="${FREEDISPLAYS} ${display}" | |
done | |
fi | |
return 0 | |
else | |
eerror 'There are no displays configured in /etc/tigervnc/vncserver.users' | |
return 1 | |
fi | |
} | |
checkwarn() { | |
if [ "${should_warn}" = "1" ]; then | |
ewarn 'Running /etc/init.d/tigervnc in compatibility mode' | |
ewarn 'Please migrate to one service per display as detailed here:' | |
ewarn 'https://wiki.gentoo.org/wiki/TigerVNC#Migrating_from_1.13.1-r2_or_lower:' | |
fi | |
} | |
start() { | |
checkwarn | |
FREEDISPLAYS="" | |
checkconfig start || return 1 | |
for display in $FREEDISPLAYS; do | |
[ -n "${TIGERVNC_XSESSION_FILE}" ] && export TIGERVNC_XSESSION_FILE | |
ebegin "Starting TigerVNC server :${display}" | |
start-stop-daemon --start --pidfile=/run/vncsession-":${display}".pid /usr/sbin/vncsession "${user}" ":${display}" | |
eend $? | |
done | |
} | |
stop() { | |
checkconfig stop || return 2 | |
for display in $DISPLAYS; do | |
ebegin "Stopping TigerVNC server :${display}" | |
start-stop-daemon --stop --pidfile=/run/vncsession-":${display}".pid | |
eend $? | |
done | |
# Do not fail if a server is missing | |
/bin/true | |
} | |
restart() { | |
svc_stop | |
svc_start | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TigerVNC User assignment | |
# | |
# This file assigns users to specific VNC display numbers. | |
# The syntax is <display>=<username>. E.g.: | |
# | |
# :2=andrew | |
# :3=lisa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# | |
# Copyright 2019 Pierre Ossman for Cendio AB | |
# | |
# This is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This software is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this software; if not, write to the Free Software | |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
# USA. | |
# | |
# | |
# Set in /usr/libexec/vncsession-start | |
# | |
USERSFILE="/etc/tigervnc/vncserver.users" | |
if [ $# -ne 1 ]; then | |
echo "Syntax:" >&2 | |
echo " $0 <display>" >&2 | |
exit 1 | |
fi | |
if [ ! -f "${USERSFILE}" ]; then | |
echo "Users file ${USERSFILE} missing" >&2 | |
exit 1 | |
fi | |
DISPLAY="$1" | |
USER=`grep "^ *${DISPLAY}=" "${USERSFILE}" 2>/dev/null | head -1 | cut -d = -f 2- | sed 's/ *$//g'` | |
if [ -z "${USER}" ]; then | |
echo "No user configured for display ${DISPLAY}" >&2 | |
exit 1 | |
fi | |
exec "/usr/sbin/vncsession" "${USER}" "${DISPLAY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment