From de699b12b15943d7e0fd0bbcdaef16e6a9dbfe7b Mon Sep 17 00:00:00 2001 From: Alexander Grothe Date: Wed, 15 May 2019 14:47:24 +0200 Subject: [PATCH] Add udiskie to yavdr-desktop role this is used to mount external data devices automatically Add yavdr-i18n to the default packages, so translations using the transale filter will work properly --- Manual.org | 114 ++++++++++++++++++ roles/yavdr-common/tasks/configure_system.yml | 1 + roles/yavdr-desktop/tasks/main.yml | 3 + roles/yavdr-desktop/tasks/udiskie.yml | 26 ++++ .../templates/openbox/autostart.j2 | 1 + .../templates/udiskie/config.yml.j2 | 23 ++++ .../udiskie/udiskie_vdr_mount_helper.j2 | 45 +++++++ .../templates/udiskie/umount_all.j2 | 2 + 8 files changed, 215 insertions(+) create mode 100644 roles/yavdr-desktop/tasks/udiskie.yml create mode 100755 roles/yavdr-desktop/templates/udiskie/config.yml.j2 create mode 100755 roles/yavdr-desktop/templates/udiskie/udiskie_vdr_mount_helper.j2 create mode 100755 roles/yavdr-desktop/templates/udiskie/umount_all.j2 diff --git a/Manual.org b/Manual.org index c630038..be8d7ca 100644 --- a/Manual.org +++ b/Manual.org @@ -774,6 +774,7 @@ yavdr-common executes the following tasks: - wpasupplicant - usbutils - xfsprogs + - yavdr-i18n state: present install_recommends: no @@ -3485,6 +3486,9 @@ exit 0 group: '{{ vdr.group }}' force: no +- name: set up udiskie + include_tasks: udiskie.yml + - name: link /usr/bin/start-desktop to /var/lib/vdr/plugins/desktop/starter file: src: /usr/bin/start-desktop @@ -3498,6 +3502,36 @@ exit 0 enabled: yes state: started #+END_SRC + +**** udiskie.yml +#+BEGIN_SRC yaml :tangle roles/yavdr-desktop/tasks/udiskie.yml :mkdirp yes :padline no +- name: install udiskie + apt: + name: + - udiskie + +- name: create ~/.config/udiskie + file: + name: '{{ vdr.home }}/.config/udiskie' + +- name: expand template for udiskie's config.yml + template: + src: templates/udiskie/config.yml.j2 + dest: '{{ vdr.home }}/.config/udiskie/config.yml' + +- name: expand template for mount helper script + template: + src: templates/udiskie/udiskie_vdr_mount_helper.j2 + dest: '{{ vdr.home }}/bin/udiskie_vdr_mount_helper' + mode: 0755 + owner: vdr + group: vdr + +- name: expand template for udiskie vdr commands + template: + src: templates/udiskie/umount_all.j2 + dest: /usr/share/vdr/command-hooks/commands.udiskie.conf +#+END_SRC *** Templates :PROPERTIES: :ID: 0bbfaf8b-c242-4f0a-9ea0-ea4bfbb438ca @@ -3576,6 +3610,7 @@ fi # start systemd units for the yavdr user session systemctl --user isolate yavdr-desktop.target +udiskie & #+END_SRC ***** rc.xml :PROPERTIES: @@ -5247,6 +5282,85 @@ systemctl --user isolate yavdr-desktop.target +#+END_SRC +**** udiskie +***** config.yml +#+BEGIN_SRC shell :tangle roles/yavdr-desktop/templates/udiskie/config.yml.j2 :mkdirp yes :shebang #!/bin/bash +program_options: + tray: false # [bool] Enable the tray icon. "auto" + menu: flat # ["flat" | "nested"] Set the + automount: true # [bool] Enable automatic mounting. + notify: true # [bool] Enable notifications. + password_cache: false # [int] Password cache in minutes. Caching is + + file_manager: "" + notify_command: "{{ vdr.home }}/bin/udiskie_vdr_mount_helper '{event}' '{device_presentation}' '{mount_path}'" + +device_config: + - is_loop: true + ignore: true + + - is_external: false + ignore: true + +notifications: + device_mounted: 5 # mount notification + device_unmounted: true # unmount notification + device_added: true # device has appeared + device_removed: true # device has disappeared +#+END_SRC + +***** mount helper script +#+BEGIN_SRC shell :tangle roles/yavdr-desktop/templates/udiskie/udiskie_vdr_mount_helper.j2 :mkdirp yes :shebang #!/bin/bash +#!/bin/bash +videodir="{{ vdr.recdir }}" +event="$1" +device_node="$2" +mount_path="$3" + + +logger -t "mount-notification" "event: $event, device: $device_node, mount_path: $mount_path" +case "$event" in + 'device_mounted') + target="${videodir}/$(basename "${mount_path}")" + ln -s -T "$mount_path" "$target" || + { logger -t "vdr recordings found" "mountpoint already exists, aborting"; exit; } + # check if we got a vdr recording on the mountpoint + if [ -n $(find "$mount_path" -name "*.rec" -print -quit 2>/dev/null) ] + then + vdr-dbus-send /Skin skin.QueueMessage string:"$mount_path mounted (with recordings)" + svdrpsend updr + else + vdr-dbus-send /Skin skin.QueueMessage string:"$mount_path' mounted" + fi + ;; + 'device_unmounted') + removed_symlinks=($(find "$videodir" -xtype l -delete -print)) + logger -t "device umounted" "remove unneeded symlinks: $(paste -d " " <<< "${removed_symlinks[@]}")" + vdr-dbus-send /Skin skin.QueueMessage string:"$device_node umounted" + svdrpsend updr + ;; + 'device_removed') + removed_symlinks=($(find "$videodir" -xtype l -delete -print)) + if [ -z "$device_node" ] && exit + logger -t "device removed" "remove unneeded symlinks: $(paste -d " " <<< "${removed_symlinks[@]}")" + vdr-dbus-send /Skin skin.QueueMessage string:"$device_node removed" + svdrpsend updr + ;; + 'job_failed') + if [ -n "$mount_path" ] + then + logger -t "umount failed" "could not unmount $mount_path" + else + logger -t "operation failed" 'could not mount(?) '"$device_node" + fi + ;; +esac +#+END_SRC + +***** udiskie snippet for commands.conf +#+BEGIN_SRC shell :tangle roles/yavdr-desktop/templates/udiskie/umount_all.j2 :mkdirp yes :shebang #!/bin/bash +{{ "Safely remove usb mass storage" | translate }} : echo 'svdrpsend mesg "$(udiskie-umount -a 2>&1 | grep -o "Error unmounting.*")"' | at now #+END_SRC **** Systemd User Session diff --git a/roles/yavdr-common/tasks/configure_system.yml b/roles/yavdr-common/tasks/configure_system.yml index caf56b6..3dd9c1a 100644 --- a/roles/yavdr-common/tasks/configure_system.yml +++ b/roles/yavdr-common/tasks/configure_system.yml @@ -51,6 +51,7 @@ - wpasupplicant - usbutils - xfsprogs + - yavdr-i18n state: present install_recommends: no - name: apt | install extra packages diff --git a/roles/yavdr-desktop/tasks/main.yml b/roles/yavdr-desktop/tasks/main.yml index c5c3bc6..ba5cad1 100644 --- a/roles/yavdr-desktop/tasks/main.yml +++ b/roles/yavdr-desktop/tasks/main.yml @@ -143,6 +143,9 @@ group: '{{ vdr.group }}' force: no +- name: set up udiskie + include_tasks: udiskie.yml + - name: link /usr/bin/start-desktop to /var/lib/vdr/plugins/desktop/starter file: src: /usr/bin/start-desktop diff --git a/roles/yavdr-desktop/tasks/udiskie.yml b/roles/yavdr-desktop/tasks/udiskie.yml new file mode 100644 index 0000000..d914b13 --- /dev/null +++ b/roles/yavdr-desktop/tasks/udiskie.yml @@ -0,0 +1,26 @@ +- name: install udiskie + apt: + name: + - udiskie + +- name: create ~/.config/udiskie + file: + name: '{{ vdr.home }}/.config/udiskie' + +- name: expand template for udiskie's config.yml + template: + src: templates/udiskie/config.yml.j2 + dest: '{{ vdr.home }}/.config/udiskie/config.yml' + +- name: expand template for mount helper script + template: + src: templates/udiskie/udiskie_vdr_mount_helper.j2 + dest: '{{ vdr.home }}/bin/udiskie_vdr_mount_helper' + mode: 0755 + owner: vdr + group: vdr + +- name: expand template for udiskie vdr commands + template: + src: templates/udiskie/umount_all.j2 + dest: /usr/share/vdr/command-hooks/commands.udiskie.conf diff --git a/roles/yavdr-desktop/templates/openbox/autostart.j2 b/roles/yavdr-desktop/templates/openbox/autostart.j2 index 4d98d18..ef3f3d0 100755 --- a/roles/yavdr-desktop/templates/openbox/autostart.j2 +++ b/roles/yavdr-desktop/templates/openbox/autostart.j2 @@ -28,3 +28,4 @@ fi # start systemd units for the yavdr user session systemctl --user isolate yavdr-desktop.target +udiskie & diff --git a/roles/yavdr-desktop/templates/udiskie/config.yml.j2 b/roles/yavdr-desktop/templates/udiskie/config.yml.j2 new file mode 100755 index 0000000..a436f55 --- /dev/null +++ b/roles/yavdr-desktop/templates/udiskie/config.yml.j2 @@ -0,0 +1,23 @@ +#!/bin/bash +program_options: + tray: false # [bool] Enable the tray icon. "auto" + menu: flat # ["flat" | "nested"] Set the + automount: true # [bool] Enable automatic mounting. + notify: true # [bool] Enable notifications. + password_cache: false # [int] Password cache in minutes. Caching is + + file_manager: "" + notify_command: "{{ vdr.home }}/bin/udiskie_vdr_mount_helper '{event}' '{device_presentation}' '{mount_path}'" + +device_config: + - is_loop: true + ignore: true + + - is_external: false + ignore: true + +notifications: + device_mounted: 5 # mount notification + device_unmounted: true # unmount notification + device_added: true # device has appeared + device_removed: true # device has disappeared diff --git a/roles/yavdr-desktop/templates/udiskie/udiskie_vdr_mount_helper.j2 b/roles/yavdr-desktop/templates/udiskie/udiskie_vdr_mount_helper.j2 new file mode 100755 index 0000000..766b780 --- /dev/null +++ b/roles/yavdr-desktop/templates/udiskie/udiskie_vdr_mount_helper.j2 @@ -0,0 +1,45 @@ +#!/bin/bash +#!/bin/bash +videodir="{{ vdr.recdir }}" +event="$1" +device_node="$2" +mount_path="$3" + + +logger -t "mount-notification" "event: $event, device: $device_node, mount_path: $mount_path" +case "$event" in + 'device_mounted') + target="${videodir}/$(basename "${mount_path}")" + ln -s -T "$mount_path" "$target" || + { logger -t "vdr recordings found" "mountpoint already exists, aborting"; exit; } + # check if we got a vdr recording on the mountpoint + if [ -n $(find "$mount_path" -name "*.rec" -print -quit 2>/dev/null) ] + then + vdr-dbus-send /Skin skin.QueueMessage string:"$mount_path mounted (with recordings)" + svdrpsend updr + else + vdr-dbus-send /Skin skin.QueueMessage string:"$mount_path' mounted" + fi + ;; + 'device_unmounted') + removed_symlinks=($(find "$videodir" -xtype l -delete -print)) + logger -t "device umounted" "remove unneeded symlinks: $(paste -d " " <<< "${removed_symlinks[@]}")" + vdr-dbus-send /Skin skin.QueueMessage string:"$device_node umounted" + svdrpsend updr + ;; + 'device_removed') + removed_symlinks=($(find "$videodir" -xtype l -delete -print)) + if [ -z "$device_node" ] && exit + logger -t "device removed" "remove unneeded symlinks: $(paste -d " " <<< "${removed_symlinks[@]}")" + vdr-dbus-send /Skin skin.QueueMessage string:"$device_node removed" + svdrpsend updr + ;; + 'job_failed') + if [ -n "$mount_path" ] + then + logger -t "umount failed" "could not unmount $mount_path" + else + logger -t "operation failed" 'could not mount(?) '"$device_node" + fi + ;; +esac diff --git a/roles/yavdr-desktop/templates/udiskie/umount_all.j2 b/roles/yavdr-desktop/templates/udiskie/umount_all.j2 new file mode 100755 index 0000000..6f3da33 --- /dev/null +++ b/roles/yavdr-desktop/templates/udiskie/umount_all.j2 @@ -0,0 +1,2 @@ +#!/bin/bash +{{ "Safely remove usb mass storage" | translate }} : echo 'svdrpsend mesg "$(udiskie-umount -a 2>&1 | grep -o "Error unmounting.*")"' | at now