summaryrefslogtreecommitdiff
path: root/roles/streaming/mpv-headless/tasks/main.yml
blob: 225c10e0195869b95e21f060fa076c80960b7428 (plain) (blame)
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
---
- name: install packages
  apt:
    name:
    - alsa-utils
    - ffmpeg
    - mpv
    - socat
    state: present

- name: install intel/vaapi specific packages
  when: "'raspios' not in group_names"
  apt:
    name:
    - intel-gpu-tools
    - vainfo
    - va-driver-all
    - firmware-linux
    - drm-info
    state: present

- name: install non-free vaapi drivers for intel
  when:
  - "'raspios' not in group_names"
  - "'non-free' in (apt_repo_components | default([])) "
  apt:
    name:
    - i965-va-driver-shaders
    - intel-media-va-driver-non-free
    state: present

- name: create player user
  user:
    name: player
    home: /var/lib/player
    create_home: no
    shell: /bin/sh
    system: yes
    groups:
    - video
    - render
    - audio
    state: present

- name: create empty user dir for player
  file:
    path: /var/lib/player
    state: directory
    owner: player
    group: player

- name: Generate authorized_keys file for player
  authorized_key:
    user: player
    key: |-
      {% for key in  mpv_headless_ssh_keys %}
      no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding,no-user-rc,command="/var/lib/player/ssh-forced.sh" {{ key }}
      {% endfor %}

- name: install .profile
  copy:
    content: |
      if [ -z "$DISPLAY" ]; then
        case $(tty) in
          /dev/tty1)
            setterm --clear=all --cursor off --background black
            exec mpv --osd-level=0 --no-osc --audio-device='{{ mpv_headless_audio_device }}' --vo=gpu --hwdec={{ mpv_headless_hwdec }} --gpu-context=drm --drm-mode='{{ mpv_headless_video_mode }}' --force-window=immediate --input-ipc-server=/var/lib/player/ctl.sock --idle
            ;;
        esac
      fi
    dest: /var/lib/player/.profile
    owner: player
    group: player

- name: install ssh forced command
  template:
    src: ssh-forced.sh.j2
    dest: /var/lib/player/ssh-forced.sh
    mode: 0755

- name: create override direcotry for getty@tty1 service unit
  file:
    path: /etc/systemd/system/getty@tty1.service.d
    state: directory

- name: generate override for getty@tty1 service unit
  copy:
    content: |
      [Service]
      ExecStart=
      ExecStart=-/sbin/agetty --autologin player --noclear %I $TERM
      RestartSec=2
      StartLimitInterval=5
      StartLimitBurst=3
    dest: /etc/systemd/system/getty@tty1.service.d/autologin.conf

- name: make sure getty@tty1 service unit is enabled and started
  systemd:
    daemon_reload: yes
    name: getty@tty1.service
    state: started
    enabled: yes

- name: prepare storage volume for /srv/media
  when: mpv_headless_media_storage is defined
  vars:
    storage_volume: "{{ mpv_headless_media_storage | combine({'dest': '/srv/media'}) }}"
  include_role:
    name: "storage/{{ mpv_headless_media_storage.type }}/volume"