fix: discover non-root username at runtime

Useful when Dom0 has the non-default username, less useful for DomUs.

Fixes: https://github.com/ben-grande/qusal/issues/43
This commit is contained in:
Ben Grande 2024-04-30 16:04:40 +02:00
parent e84959bebb
commit 5722a25779
No known key found for this signature in database
GPG Key ID: 00C64E14F51F9E56
7 changed files with 30 additions and 18 deletions

View File

@ -6,15 +6,17 @@ SPDX-License-Identifier: AGPL-3.0-or-later
{% if grains['nodename'] == 'dom0' -%} {% if grains['nodename'] == 'dom0' -%}
{%- import slsdotpath ~ "/gui-user.jinja" as gui_user -%}
include: include:
- dotfiles.copy-all - dotfiles.copy-all
"{{ slsdotpath }}-xprofile-sourcer": "{{ slsdotpath }}-xprofile-sourcer":
file.managed: file.managed:
- name: /home/user/.config/autostart/xprofile.desktop - name: {{ gui_user.gui_user_home }}/.config/autostart/xprofile.desktop
- source: salt://{{ slsdotpath }}/files/autostart/xprofile.desktop - source: salt://{{ slsdotpath }}/files/autostart/xprofile.desktop
- user: user - user: {{ gui_user.gui_user }}
- group: user - group: {{ gui_user.gui_user }}
- mode: '0644' - mode: '0644'
- makedirs: True - makedirs: True

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. <ben.grande.b@gmail.com> # SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
@ -6,7 +6,7 @@
Name=Xprofile sourcer Name=Xprofile sourcer
Comment=Source User's Xprofile Comment=Source User's Xprofile
Type=Application Type=Application
Exec=/home/user/.config/x11/xprofile Exec=sh -c "exec ${HOME}/.config/x11/xprofile"
Terminal=false Terminal=false
StartupNotify=false StartupNotify=false
Categories=System; Categories=System;

9
salt/dom0/gui-user.jinja Normal file
View File

@ -0,0 +1,9 @@
{#
SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
SPDX-License-Identifier: AGPL-3.0-or-later
#}
{% set gui_user = salt['cmd.shell']("getent group qubes | awk -F '[:,]' '{print $4}'") -%}
{% set gui_user_id = salt['cmd.shell']("getent passwd " ~ gui_user ~ " | awk -F ':' '{print $3}'") -%}
{% set gui_user_home = salt['cmd.shell']("getent passwd " ~ gui_user ~ " | awk -F ':' '{print $6}'") -%}

View File

@ -50,19 +50,19 @@ include:
"{{ slsdotpath }}-activity-notifier": "{{ slsdotpath }}-activity-notifier":
file.managed: file.managed:
- name: /home/user/.config/autostart-scripts/kde-activity-changed-notifier - name: {{ gui_user.gui_user_home }}/.config/autostart-scripts/kde-activity-changed-notifier
- source: salt://{{ slsdotpath }}/files/autostart-scripts/kde-activity-changed-notifier - source: salt://{{ slsdotpath }}/files/autostart-scripts/kde-activity-changed-notifier
- user: user - user: {{ gui_user.gui_user }}
- group: user - group: {{ gui_user.gui_user }}
- mode: '0755' - mode: '0755'
- makedirs: True - makedirs: True
"{{ slsdotpath }}-qubes-kde-win-rules": "{{ slsdotpath }}-qubes-kde-win-rules":
file.managed: file.managed:
- name: /home/user/.local/bin/qubes-kde-win-rules - name: {{ gui_user.gui_user_home }}/.local/bin/qubes-kde-win-rules
- source: salt://{{ slsdotpath }}/files/bin/qubes-kde-win-rules - source: salt://{{ slsdotpath }}/files/bin/qubes-kde-win-rules
- user: user - user: {{ gui_user.gui_user }}
- group: user - group: {{ gui_user.gui_user }}
- mode: '0755' - mode: '0755'
- makedirs: True - makedirs: True

View File

@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
{% if grains['nodename'] == 'dom0' -%} {% if grains['nodename'] == 'dom0' -%}
{%- import slsdotpath ~ "/gui-user.jinja" as gui_user -%}
include: include:
- utils.tools.common.update - utils.tools.common.update
@ -31,16 +33,14 @@ include:
- pkg: "{{ slsdotpath }}-screenshot-installed" - pkg: "{{ slsdotpath }}-screenshot-installed"
## TODO: KDE shortcuts ## TODO: KDE shortcuts
{% set gui_user = salt['cmd.shell']('groupmems -l -g qubes') -%}
{% set gui_user_id = salt['cmd.shell']('id -u ' ~ gui_user) -%}
"{{ slsdotpath }}-screenshot-keyboard-shortcuts-xfce": "{{ slsdotpath }}-screenshot-keyboard-shortcuts-xfce":
cmd.run: cmd.run:
- name: | - name: |
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/{{ gui_user_id }}/bus" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/{{ gui_user.gui_user_id }}/bus"
export DBUS_SESSION_BUS_ADDRESS export DBUS_SESSION_BUS_ADDRESS
xfconf-query -c xfce4-keyboard-shortcuts -p "/commands/custom/Print" -n -s "qvm-screenshot --fullscreen" xfconf-query -c xfce4-keyboard-shortcuts -p "/commands/custom/Print" -n -s "qvm-screenshot --fullscreen"
xfconf-query -c xfce4-keyboard-shortcuts -p "/commands/custom/<Alt>Print" -n -s "qvm-screenshot --region" xfconf-query -c xfce4-keyboard-shortcuts -p "/commands/custom/<Alt>Print" -n -s "qvm-screenshot --region"
- runas: {{ gui_user }} - runas: {{ gui_user.gui_user }}
- require: - require:
- file: "{{ slsdotpath }}-screenshot-script" - file: "{{ slsdotpath }}-screenshot-script"

@ -1 +1 @@
Subproject commit 9954972df34f5159d726c0784f7aac9f8e61daa7 Subproject commit 84bae87dc5da48334f81501e11cf17919ff1504b

View File

@ -27,13 +27,14 @@ Usage:
qvm.start: qvm.start:
- name: {{ qube }} - name: {{ qube }}
{% set gui_user = salt['cmd.shell']('groupmems -l -g qubes') -%} {% import "dom0/gui-user.jinja" as gui_user -%}
"{{ qube }}-sync-appmenus": "{{ qube }}-sync-appmenus":
cmd.run: cmd.run:
- require: - require:
- qvm: {{ qube }}-start - qvm: {{ qube }}-start
- name: qvm-sync-appmenus {{ qube }} - name: qvm-sync-appmenus {{ qube }}
- runas: {{ gui_user }} - runas: {{ gui_user.gui_user }}
{% if running == 0 -%} {% if running == 0 -%}
"{{ qube }}-shutdown": "{{ qube }}-shutdown":