diff --git a/Manual.html b/Manual.html index 8a61d21..02b09e2 100644 --- a/Manual.html +++ b/Manual.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- +A User wants to install yaVDR without customization and relies on full automation. @@ -554,24 +554,24 @@ Several roles are used to tie everything together:
One of the major problems we faced with customized Ubuntu ISO files as installation media for prior yaVDR versions has been the limited hardware support and the time consuming process to create and update them. An interesting alternative to this approach is to enable the user to choose the installation medium by himself, so point releases, kernel versions and additional drivers can be chosen deliberately. After the basic setup is complete (and a working internet connection is available), a fully customizable install script completes the yaVDR installation.
This is an experimental feature which allows to set up a yaVDR installation based on a normal Ubuntu Server 16.04.x installation using Ansible. @@ -606,8 +606,8 @@ We use a callback to generate tags for all roles autmatically:
set -e @@ -652,12 +652,12 @@ ansible-playbook yavdr07-headless.yml -b -i 'localhost_
The yavdr07.yml
playbook sets up a fully-featured yaVDR installation:
@@ -710,8 +710,8 @@ The yavdr07.yml
playbook sets up a fully-featured yaVDR installatio
For a headless server installation yavdr07-headless.yml
is a good choice
@@ -749,8 +749,8 @@ For a headless server installation yavdr07-headless.yml
is a good c
This playbook can either be used to run the installation on the localhost or any other PC in the network that can be accessed via ssh. Simply add the host names or IP addresses to the hosts file in the respective section: @@ -764,12 +764,12 @@ This playbook can either be used to run the installation on the localhost or any
--- @@ -781,14 +781,14 @@ This playbook can either be used to run the installation on the localhost or any repositories: - '{{ ppa_owner }}/{{branch}}-main' - '{{ ppa_owner }}/{{branch}}-vdr' + - '{{ ppa_owner }}/{{branch}}-kodi' #- '{{ ppa_owner }}/{{branch}}-yavdr' - #- '{{ ppa_owner }}/{{branch}}-kodi'
# properties of the user vdr and vdr-related options @@ -814,8 +814,8 @@ This playbook can either be used to run the installation on the localhost or any
# dictionary of directories for (shared) files. Automatically exported via NFS and Samba if those roles are enabled @@ -830,8 +830,8 @@ This playbook can either be used to run the installation on the localhost or any
nfs:
@@ -840,8 +840,8 @@ This playbook can either be used to run the installation on the localhost or any
samba:
@@ -851,8 +851,8 @@ This playbook can either be used to run the installation on the localhost or any
# additional packages you want to install @@ -871,8 +871,8 @@ This playbook can either be used to run the installation on the localhost or any
frontend: vdr
@@ -886,8 +886,8 @@ This playbook can either be used to run the installation on the localhost or any
# Serial device to configure for a homebrew receiver. @@ -899,20 +899,20 @@ This playbook can either be used to run the installation on the localhost or any
---
@@ -930,19 +930,19 @@ This playbook can either be used to run the installation on the localhost or any
install nvidia-396 from ppa:graphics-drivers/ppa
---
@@ -971,15 +971,15 @@ install nvidia-396 from ppa:graphics-drivers/ppa
This role is used to set up a basic yaVDR installation. It creates the directories, installs the vdr and other useful packages.
This section is for reference only, please use the files in
You can set a list of package repositories which provide the necessary packages. Feel free to use own PPAs if you need special customization to the VDR and it’s plugins.
@@ -1009,7 +1009,7 @@ You can set a list of package repositories which provide the necessary packages.
global_vars
for customizations.
@@ -992,7 +992,7 @@ This section is for reference only, please use the files in global_vars
-
+
Automatically installed drivers can be very useful, but if you know you need a certain driver, you can simply set it’s value to true. If you don’t want a driver to be installed, set it’s value to false. @@ -1022,7 +1022,7 @@ Automatically installed drivers can be very useful, but if you know you need a c
Add additional packages you would like to have on your installation to this list @@ -1036,7 +1036,7 @@ Add additional packages you would like to have on your installation to this list
This section allows you to set the recording directory, the user and group that runs the vdr and it’s home directory. @@ -1069,15 +1069,15 @@ This section allows you to set the recording directory, the user and group that
yavdr-common executes the following tasks:
---
@@ -1095,7 +1095,7 @@ yavdr-common executes the following tasks:
This task prevents apt to automatically install all recommended dependencies for packages: @@ -1112,7 +1112,7 @@ This task prevents apt to automatically install all recommended dependencies for
- name: add PPAs
@@ -1132,7 +1132,7 @@ This task prevents apt to automatically install all recommended dependencies for
- name: use bash instead of dash
@@ -1144,15 +1144,15 @@ This task prevents apt to automatically install all recommended dependencies for
- name: disable release-upgrade notifications
@@ -1174,7 +1174,7 @@ This task prevents apt to automatically install all recommended dependencies for
-
- name: apt | install basic packages
@@ -1205,7 +1205,7 @@ This task prevents apt to automatically install all recommended dependencies for
- name: apt | install extra packages
@@ -1218,15 +1218,15 @@ This task prevents apt to automatically install all recommended dependencies for
Stop vdr before entering suspend and unload dvb modules, reverse this operation on resume @@ -1237,8 +1237,8 @@ Stop vdr before entering suspend and unload dvb modules, reverse this operation
{{ ansible_managed | comment('c') }} @@ -1249,7 +1249,7 @@ APT::Install-Suggests "0";
#!/bin/bash
@@ -1290,7 +1290,7 @@ Allow the vdr user to restart vdr.service
and reboot the system
#!/usr/bin/env python3
@@ -1377,12 +1377,12 @@ Allow the vdr user to restart vdr.service
and reboot the system
first_run: False
@@ -1390,12 +1390,12 @@ Allow the vdr user to restart vdr.service
and reboot the system
- name: get information about usb and pci hardware and loaded kernel modules
@@ -1444,16 +1444,16 @@ Allow the vdr user to restart vdr.service
and reboot the system
---
@@ -1471,7 +1471,7 @@ Allow the vdr user to restart vdr.service
and reboot the system
- name: add svdrp and svdrp-disc to /etc/services
@@ -1486,7 +1486,7 @@ Allow the vdr user to restart vdr.service
and reboot the system
- name: create vdr recdir
@@ -1521,7 +1521,7 @@ Allow the vdr user to restart vdr.service
and reboot the system
The additional plugins to install can be set in the variable {{vdr_plugins}}
in the group variables
@@ -1537,7 +1537,7 @@ The additional plugins to install can be set in the variable {{vdr_plugins
- name: ensure vdr is stopped
@@ -1568,7 +1568,7 @@ The additional plugins to install can be set in the variable {{vdr_plugins
- name: create directory for vdr.service systemd drop-in files
@@ -1589,8 +1589,8 @@ The additional plugins to install can be set in the variable {{vdr_plugins
Start after network-online.target @@ -1602,12 +1602,12 @@ Start after network-online.target
LIRC.Up KEY_UP @@ -1742,7 +1742,7 @@ XKeySym.Next XF86AudioNext
# Remote control key macros for VDR @@ -1768,12 +1768,12 @@ User0 @osdteletext
install_avahi: true @@ -1781,8 +1781,8 @@ User0 @osdteletext
---
@@ -1850,12 +1850,12 @@ User0 @osdteletext
---
@@ -1877,8 +1877,8 @@ User0 @osdteletext
<?xml version="1.0" encoding="UTF-8"?>
@@ -1937,17 +1937,17 @@ User0 @osdteletext
---
@@ -1975,12 +1975,12 @@ User0 @osdteletext
/srv *(rw,fsid=0,sync,no_subtree_check,all_squash,anongid={{ vdr.gid }},anonuid={{ vdr.uid }})
@@ -1991,7 +1991,7 @@ User0 @osdteletext
<?xml version="1.0" standalone='no'?> @@ -2012,15 +2012,15 @@ User0 @osdteletext
The role yavdr-remote
sets up the foundation for using eventlircd, lircd2uinput and the pre-configuration for remote receivers which can be detected by udev.
lircd0_socket: /var/run/lirc/lircd0
@@ -2028,8 +2028,8 @@ The role yavdr-remote
sets up the foundation for using eventlircd,
---
@@ -2100,12 +2100,12 @@ The role yavdr-remote
sets up the foundation for using eventlircd,
{% if frontend != 'kodi' %}
@@ -2116,7 +2116,7 @@ The role yavdr-remote
sets up the foundation for using eventlircd,
[Service]
@@ -2126,7 +2126,7 @@ The role yavdr-remote
sets up the foundation for using eventlircd,
{{ ansible_managed | comment }} @@ -2318,12 +2318,12 @@ ati_remote rc-medion-x10-digitainer /lib/udev/rc_keymaps/rc-medion-x10-digi
---
@@ -2345,8 +2345,8 @@ ati_remote rc-medion-x10-digitainer /lib/udev/rc_keymaps/rc-medion-x10-digi
# Use PulseAudio by default @@ -2368,20 +2368,20 @@ ati_remote rc-medion-x10-digitainer /lib/udev/rc_keymaps/rc-medion-x10-digi
-The X-Server is started by using the two systemd units xlogin@.service
and x@.service
provided by the package xlogin. The former is enabled (and started) for the vdr user - which results (using the default settings for the user vdr with the uid 666) in the activation of xlogin@vdr.service
when reaching the graphical.target. To simplify starting and stopping the X-server and the desktop session a yavdr-xorg.service
is provided by the package yavdr-xorg
, which depends on the two units mentioned before.
+The X-Server is started by using the two systemd units xlogin@.service
and x@.service
provided by the package xlogin. The former is enabled (and started) for the vdr user - which results (using the default settings for the user vdr with the uid 666) in the activation of xlogin@vdr.service
when reaching the graphical.target. To simplify starting and stopping the X-server and the desktop session a yavdr-xorg.service
is provided by the package yavdr-xorg
, which depends on the two units mentioned before.
x@vt7.service
is started automatically as a dependency of xlogin@vdr.service
and starts the X-server. xlogin@vdr.service
also starts a systemd user session using user@666.service
.
-In order to use the keyboard layout configured during installation for the X-Server the script write-x11-keyboard-config
reads the keyboard configuration from /etc/default/keyboard
when starting x@.service
and writes the file /etc/X11/xorg.conf.d/00-keyboard.conf
(because systemd for Ubuntu (and Debian) has been patched not to create /etc/X11/xorg.conf.d/00-keyboard.conf
according to the localectl
settings).
+In order to use the keyboard layout configured during installation for the X-Server we are using a script write-x11-keyboard-config,
which reads the keyboard configuration from /etc/default/keyboard
when starting x@.service
and writes the file /etc/X11/xorg.conf.d/00-keyboard.conf
(because systemd for Ubuntu (and Debian) has been patched not to automatically create the configuration file /etc/X11/xorg.conf.d/00-keyboard.conf
according to the localectl
settings).
@@ -2402,8 +2402,8 @@ In order to achive a clean shutdown of the session, x@t7.service
is
first_run: False
@@ -2426,12 +2426,12 @@ In order to achive a clean shutdown of the session, x@t7.service
is
---
@@ -2444,7 +2444,7 @@ In order to achive a clean shutdown of the session, x@t7.service
is
--- @@ -2493,6 +2493,12 @@ In order to achive a clean shutdown of the session,x@t7.service
is - '-w alsa-driver-broken' # - '-a pulse' # do we need this with our existing asound.conf? +- name: vdr-config | use vaapi for softhddevice if we got an intel IGP + lineinfile: + path: /etc/vdr/conf.avail/softhddevice.conf + line: '-v va-pi' + state: present if intel_detected else absent + - name: add a login shell for the user vdr user: name: '{{ vdr.user }}' @@ -2556,7 +2562,7 @@ In order to achive a clean shutdown of the session,x@t7.service
is
---
@@ -2736,11 +2742,15 @@ In order to achive a clean shutdown of the session, x@t7.service
is
when:
- intel_detected
+- name: server flags config snippet to disable screen blanking
+ template:
+ src: templates/10-serverflags.conf.j2
+ dest: /etc/X11/xorg.conf.d/10-serverflags.conf
KMS drivers (like for intel (i915) and amd (radeon)) require additional configuration besides a customized xorg.conf
- for a „static“ output configuration (which works if the TV or AV receiver is not turned on) we need to force loading the display(s) EDID early during the boot process.
@@ -2788,12 +2798,12 @@ Please note that rescanning the connected displays works only after removing the
{{ ansible_managed | comment }} @@ -2803,11 +2813,11 @@ Please note that rescanning the connected displays works only after removing the
# file: roles/yavdr-xorg/templates/systemd/system/x-verbose@.service.j2 @@ -2823,7 +2833,7 @@ Please note that rescanning the connected displays works only after removing the
[Unit]
@@ -2849,7 +2859,7 @@ Please note that rescanning the connected displays works only after removing the
{{ ansible_managed | comment }} @@ -2861,7 +2871,7 @@ Please note that rescanning the connected displays works only after removing the
{{ ansible_managed | comment }} @@ -2876,25 +2886,45 @@ EndSection
{{ ansible_managed | comment }} - -{% set output = xorg.primary.connector|replace("-", "") %} +{% set primary_output = xorg.primary.connector|replace("-", "") %} +{% if xorg.secondary is defined %} + {% set secondary_output = xorg.secondary.connector|replace("-", "") %} +{% endif %} Section "Device" Identifier "Device0" Driver "intel" Option "TearFree" "true" - - Option "UseEDID" "true" - Option "CustomEDID" "{{ output }}:{{ xorg.primary.edid }}" +{% if xorg.secondary is defined %} + Option "ZaphodHeads" "{{ primary_output }}" + Screen 0 +{% endif %} EndSection + +{% if xorg.secondary is defined %} +Section "Device" + Identifier "Device1" + Driver "intel" + Option "TearFree" "true" + Option "ZaphodHeads" "{{ secondary_output }}" + Screen 1 +EndSection + +Section "ServerLayout" + Identifier "Layout0" + Screen 0 "Screen0" 0 0 + Screen 1 "Screen1" RightOf "Screen0" +EndSection +{% endif %} + Section "Screen" Identifier "Screen0" Device "Device0" - Monitor "{{ output }}" + Monitor "{{ primary_output }}" DefaultDepth 24 SubSection "Display" Depth 24 @@ -2905,8 +2935,26 @@ Section "Screen" {% endif %} EndSubSection EndSection + +{% if xorg.secondary is defined %} +Section "Screen" + Identifier "Screen1" + Device "Device1" + Monitor "{{ secondary_output }}" + DefaultDepth 24 + SubSection "Display" + Depth 24 +{% if xorg.secondary.mode %} + Modes "{{ xorg.secondary.mode }}" +{% else %} + Modes "1920x1080_50" "1920x1080_60" "1920x1080_24" +{% endif %} + EndSubSection +EndSection + +{% endif %} Section "Monitor" - Identifier "{{ output }}" + Identifier "{{ primary_output }}" {% if xorg.primary.modelines %} {% for modeline in xorg.primary.modelines %} {{ modeline }} @@ -2918,8 +2966,23 @@ Section "Monitor" {% endif %} EndSection +{% if xorg.secondary is defined %} +Section "Monitor" + Identifier "{{ secondary_output }}" +{% if xorg.secondary.modelines %} +{% for modeline in xorg.secondary.modelines %} + {{ modeline }} +{% endfor %} +{% else %} + Modeline "1920x1080_24" 74.230 1920 2560 2604 2752 1080 1084 1089 1125 +hsync +vsync + Modeline "1920x1080_50" 148.500 1920 2448 2492 2640 1080 1084 1089 1125 +hsync +vsync + Modeline "1920x1080_60" 148.500 1920 2008 2056 2200 1080 1084 1089 1125 +hsync +vsync +{% endif %} +EndSection + +{% endif %} {% for connector, data in xrandr["Screen 0:"].iteritems() %} -{% if not data.is_connected or connector != xorg.primary.connector %} +{% if not data.is_connected or connector != xorg.primary.connector or (xorg.secondary is defined and connector != xorg.secondary.connector) %} Section "Monitor" Identifier "{{ connector|replace("-","") }}" Option "Ignore" "true" @@ -2931,7 +2994,7 @@ EndSection
{{ ansible_managed | comment }} @@ -3257,9 +3320,24 @@ EndSection
{{ ansible_managed | comment }} +Section "ServerFlags" + Option "NoPM" "true" + Option "blank time" "0" + Option "standby time" "0" + Option "suspend time" "0" + Option "off time" "0" +EndSection ++
Set environment variables for system locale and user session on startup @@ -3275,12 +3353,12 @@ Set environment variables for system locale and user session on startup
#!/bin/bash @@ -3305,16 +3383,16 @@ exit 0
---
@@ -3481,16 +3559,16 @@ exit 0
xterm*background: Black @@ -3513,7 +3591,7 @@ XTerm.vt100.font: 7x13
#!/bin/bash @@ -3525,11 +3603,11 @@ XTerm.vt100.font: 7x13 -
# forward environment variables to an environment file and the systemd user session @@ -3565,7 +3643,7 @@ systemctl --user isolate yavdr-desktop.target
<?xml version="1.0" encoding="UTF-8"?> @@ -4412,7 +4490,7 @@ systemctl --user isolate yavdr-desktop.target
<?xml version="1.0" encoding="UTF-8"?> @@ -5241,11 +5319,11 @@ systemctl --user isolate yavdr-desktop.target -
[Unit] @@ -5258,7 +5336,7 @@ systemctl --user isolate yavdr-desktop.target
#!/bin/bash @@ -5287,7 +5365,7 @@ systemctl --user isolate yavdr-desktop.target
This script exchanges the primary and secondary screen. It needs access to the systemd user session. @@ -5306,7 +5384,7 @@ frontend-dbus-send start
[Unit]
@@ -5328,7 +5406,7 @@ frontend-dbus-send start
[Unit]
@@ -5351,7 +5429,7 @@ frontend-dbus-send start
[Unit]
@@ -5370,7 +5448,7 @@ frontend-dbus-send start
[Unit]
@@ -5389,7 +5467,7 @@ frontend-dbus-send start
-
irexec.service starts irexec for the user session @@ -5422,12 +5500,12 @@ end
---
@@ -5448,12 +5526,12 @@ end
---
@@ -5478,16 +5556,16 @@ end
{{ ansible_managed | comment }} @@ -5561,7 +5639,8 @@ end # This option controls how unsuccessful authentication attempts are mapped # to anonymous connections - map to guest = bad user + map to guest = bad password + guest account = nobody {% if samba.windows_compatible %} # disable unix extensions and enable following symlinks @@ -5573,7 +5652,7 @@ end
{% for name, path in media_dirs.iteritems() %} @@ -5595,7 +5674,7 @@ end
include = /etc/samba/smb.conf.custom @@ -5608,15 +5687,15 @@ end
It would be nice to be able to detect if it is suitable to install those drivers:
Vendor-IDs: @@ -5627,7 +5706,7 @@ Vendor-IDs:
https://github.com/s-moch/linux-saa716x - kann man den relevanten Teil als dkms-Paket bauen? @@ -5647,15 +5726,15 @@ Vendor-IDs:
The tool ubuntu-drivers is used to install the matching driver version for nvidia graphics cards, virtualbox guest additions and Intel and AMD microcode updates.
---
@@ -5678,8 +5757,8 @@ The tool ubuntu-drivers is used to install the matching driver version for nvidi
This role installs the guest additions for virtualbox guests on Ubuntu 18.04 @@ -5728,12 +5807,12 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
---
@@ -5745,8 +5824,8 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
---
@@ -5788,8 +5867,8 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
{{ ansible_managed | comment }} @@ -5818,12 +5897,12 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
---
@@ -5834,8 +5913,8 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
---
@@ -5877,8 +5956,8 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
{{ ansible_managed | comment }} @@ -5906,15 +5985,15 @@ This role installs the guest additions for virtualbox guests on Ubuntu 18.04
If a Sat>IP Server responds to a discovery request, the package vdr-plugin-satip is installed.
---
@@ -5938,12 +6017,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -5959,12 +6038,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -5980,12 +6059,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6001,12 +6080,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6022,8 +6101,8 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6038,12 +6117,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6054,8 +6133,8 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6096,12 +6175,12 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6112,8 +6191,8 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6123,8 +6202,8 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
---
@@ -6174,15 +6253,15 @@ If a Sat>IP Server responds to a discovery request, the package vdr-plugin-sa
How to get a driver for the TT-6400 FF card? Needed firmware files are in the yavdr-firmware
package.
--- @@ -6193,8 +6272,8 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
--- @@ -6212,12 +6291,12 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
--- @@ -6228,8 +6307,8 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
--- @@ -6249,12 +6328,12 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
--- @@ -6265,8 +6344,8 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
--- @@ -6282,19 +6361,19 @@ How to get a driver for the TT-6400 FF card? Needed firmware files are in the
This role preconfigures the system for serial „homebrew“ receivers. Newer kernel versions provide serial_ir
which acts as a rc-core driver, so we don’t need lircd - eventlircd can use the device directly.
-As configured in the role yavdr-remote (/etc/rc_maps.cfg) a keytable for a RC-6 MCE remote is loaded by default. You can choose a different keymap which may also use another ir-protocol. +As configured in the role yavdr-remote (/etc/rc_maps.cfg) a keytable for a RC-6 MCE remote is loaded by default. You can choose a different keymap which may also use another ir-protocol.
--- @@ -6305,8 +6384,8 @@ As configured in the role yavdr-remote (/etc/rc_maps.cfg
--- @@ -6334,12 +6413,12 @@ As configured in the role yavdr-remote (/etc/rc_maps.cfg
{{ ansible_managed | comment }} @@ -6349,7 +6428,7 @@ serial_ir
{{ ansible_managed | comment }} @@ -6368,7 +6447,7 @@ install serial_ir setserial /dev/{{setserial options
+- setserial options
{{ ansible_managed | comment }} @@ -6387,21 +6466,21 @@ install serial_ir setserial /dev/{{ -7.32 kodi
++7.32 kodi
--7.32.1 tasks
++7.32.1 tasks
-
- Install KODI
+- Install KODI
-
- main.yml
-+- main.yml
+- import_tasks: install-kodi.yml tags: @@ -6417,7 +6496,7 @@ install serial_ir setserial /dev/{{install-kodi.yml
+- install-kodi.yml
---- @@ -6427,6 +6506,7 @@ install serial_ir setserial /dev/{{name: - kodi - kodi-pvr-vdr-vnsi + - python3-lxml state: present install_recommends: no @@ -6448,7 +6528,7 @@ install serial_ir setserial /dev/{{configure-kodi.yml
+- configure-kodi.yml
+
@@ -6497,12 +6582,12 @@ install serial_ir setserial /dev/{{ -- name: create kodi.service for the user session @@ -6488,7 +6568,12 @@ install serial_ir setserial /dev/{{group: '{{ vdr.group }}' mode: "0664" force: no -# TODO: Add configuration files + +- name: expand template for set-kodi-display + template: + src: 'templates/set-kodi-display.j2' + dest: '/usr/bin/set-kodi-display' + mode: "0755"7.32.2 templates
+- set-kodi-diplay
++++This is a version-dependent script to force KODI to use the display set by the environment variable
+DISPLAY
. The following Version is intended for KODI 18. +++#!/usr/bin/env python3 +""" +{{ ansible_managed }} + +This Script changes the monitor in KODI's guisettings.xml to the wanted output +according to the DISPLAY environment variable. It works with KODI 18 (not KODI 17!). + +In order to change the display we need to modify the settings/videoscreen nodes. + +Basic algorithm: + - get the current videoscreen.monitor + - check if it needs to be changed + - create a backup of the videoscreen nodes in /var/lib/vdr/.kodi/.display_cache/{CONNETOR}-videoscreen.xml + - check if there is an existing backup for the new CONNECTOR + - parse the backup of the videoscreen nodes + - replace the videoscreen nodes with the backup data +""" + +import copy +import os +import sys +import subprocess +from lxml import etree as ET + + +GUISETTINGS = '/var/lib/vdr/.kodi/userdata/guisettings.xml' +CACHE_DIR = '/var/lib/vdr/.kodi/.display_cache' +VIDEOSCREEN_TEMPLATE = """<settings version="2"> + <setting id="videoscreen.monitor">{}</setting> +</settings>""" + + +def create_cache_dir(): + try: + os.makedirs(CACHE_DIR, exist_ok=True) + except PermissionError: + sys.exit(f"Error: insufficient permissions to create cachedir {CACHE_DIR}") + except Exception as e: + sys.exit(f"Unexpected Error when trying to create {CACHE_DIR}:", e) + + + +def get_output_name(): + """ + get display name from xrandr output for given DISPLAY environment variable + """ + try: + xrandr_output = [ + l for l in subprocess.check_output( + ["xrandr"], + env={"DISPLAY": os.environ["DISPLAY"]} + ).decode("utf-8").splitlines() + ] + return next(l.split()[0] for l in xrandr_output if " connected " in l) + except Exception as e: + sys.exit("could not determine output name", e) + + +def parse_template(template_path, template, output=""): + """read videoscreen settings from backup or create a stub file""" + try: + xml_tree = ET.parse(template_path) + except OSError: + print(f"{template_path} not found, creating stub file", file=sys.stderr) + xml_template = ET.fromstring(template.format(output)) + xml_tree = ET.ElementTree(xml_template) + finally: + xml_tree.write(template_path) + return xml_tree + + +def main(output): + guisettings = parse_template(GUISETTINGS, VIDEOSCREEN_TEMPLATE, "Default") + + # parse guisettings Etree for display name an backup videoscreen data + root = guisettings.getroot() + old_output = root.find("./setting[@id='videoscreen.monitor']").text + if old_output == output: + print("no changes necessary, exiting", file=sys.stderr) + sys.exit() + + # create a minimal guisettings etree + xml_path = os.path.join(CACHE_DIR, f'{old_output}-videoscreen.xml') + base_tree = ET.fromstring('<settings version="2"></settings>') + xml_tree = ET.ElementTree(base_tree) + backup_root = xml_tree.getroot() + + # copy videoscreen elements to backup etree + videoscreen_elements = root.xpath( + "./setting[starts-with(@id, 'videoscreen.')]") + for element in videoscreen_elements: + backup_root.append(copy.deepcopy(element)) + element.getparent().remove(element) + xml_tree.write(xml_path) + print(f"written backup for {old_output} to {xml_path}", file=sys.stderr) + + # change videoscreen node to content of backup file + xml_path = os.path.join(CACHE_DIR, f'{output}-videoscreen.xml') + videodir_xml = parse_template(xml_path, VIDEOSCREEN_TEMPLATE, output) + videodir_root = videodir_xml.getroot() + videoscreen = videodir_root.find("./setting[@id='videoscreen.monitor']") + # copy videoscreen.* elements from Backup + videoscreen_elements = videodir_root.xpath( + "./setting[starts-with(@id, 'videoscreen.')]") + for element in videoscreen_elements: + new_element = copy.deepcopy(element) + root.append(new_element) + guisettings.write(GUISETTINGS) + + +if __name__ == '__main__': + create_cache_dir() + output = get_output_name() + try: + main(output) + except Exception as e: + print("Could not change videoscreen.* settings:", str(e), file=sys.stderr) ++