From 4c4b444f21ff8794a94aae4f83647412a7d53f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 21 Jan 2021 19:06:56 +0100 Subject: [PATCH] debian: Generate postinst devices list automatically at gbp import phase Alternatively provide a script to keep the post-inst script updated --- debian/README.source | 23 +++++++---------------- debian/gbp-post-import-hook.sh | 8 ++++++++ debian/gbp.conf | 2 +- debian/libfprint-2-2.postinst | 4 +++- debian/libfprint-2-2.postinst.in | 17 +++++++++++++++++ debian/update-udev-triggers.sh | 31 +++++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 18 deletions(-) create mode 100755 debian/gbp-post-import-hook.sh create mode 100644 debian/libfprint-2-2.postinst.in create mode 100755 debian/update-udev-triggers.sh diff --git a/debian/README.source b/debian/README.source index 4f4c2670..1a73d019 100644 --- a/debian/README.source +++ b/debian/README.source @@ -1,19 +1,10 @@ -The libfprint0 postinst script calls udevadmin trigger for all the supported -USB readers. The list of readers used in that file is generated by calling the -following awk script: +The libfprint-2-2 postinst script calls udevadmin trigger for all the supported +USB readers. The list of readers used in that file is generated using the gbp +import hook when `gbp import-orig` (via --uscan or with a tarball) is used. - /plugdev/ { - printf ("\tudevadm trigger --action=add " ) - for (i=1;i<=NF; i++){ - if (match($i,/idVendor/)>0) { - match($i, /"[^"]*"/); printf ("--attr-match=idVendor=%s ",substr($i,RSTART+1,RLENGTH-2)) - } - if (match($i,/idProduct/)>0) { - match($i, /"[^"]*"/); printf ("--attr-match=idProduct=%s",substr($i,RSTART+1,RLENGTH-2)) - } - }; - printf("\n") - } +Alternatively it can be called manually by using: + + GBP_SOURCES_DIR=. debian/update-udev-triggers.sh When preparing a new upstream release, this script should be called against the -udev .rules file generated during the build of the package +upstream provided .hwdb file. diff --git a/debian/gbp-post-import-hook.sh b/debian/gbp-post-import-hook.sh new file mode 100755 index 00000000..3d6d1dcb --- /dev/null +++ b/debian/gbp-post-import-hook.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +dch -v"$GBP_DEBIAN_VERSION" "New upstream release" +git add debian/changelog +debcommit + +debian/update-udev-triggers.sh diff --git a/debian/gbp.conf b/debian/gbp.conf index d6c944c3..e5e0f9c2 100644 --- a/debian/gbp.conf +++ b/debian/gbp.conf @@ -10,7 +10,7 @@ sign-tags = True multimaint-merge = True [import-orig] -postimport = dch -v%(version)s New upstream release; git add debian/changelog; debcommit +postimport = debian/gbp-post-import-hook.sh [pq] patch-numbers = False diff --git a/debian/libfprint-2-2.postinst b/debian/libfprint-2-2.postinst index 6a400bc6..afdd587a 100644 --- a/debian/libfprint-2-2.postinst +++ b/debian/libfprint-2-2.postinst @@ -5,10 +5,12 @@ set -e #DEBHELPER# if [ "$1" = "configure" -o "$1" = "upgrade" ] && command -V udevadm >/dev/null 2>&1; then - # apply udev rules at package installation, see + # apply hwdb rules at package installation, see # # NOTA BENE: after the DEBHELPER section since dh_installudev # adds stuff there + # The devices ID list is auto-generated using the gbp postimport hook + # see debian/README.sources for more details. udevadm trigger --action=add --attr-match=idVendor=147e --attr-match=idProduct=2016 udevadm trigger --action=add --attr-match=idVendor=147e --attr-match=idProduct=2020 udevadm trigger --action=add --attr-match=idVendor=138a --attr-match=idProduct=0010 diff --git a/debian/libfprint-2-2.postinst.in b/debian/libfprint-2-2.postinst.in new file mode 100644 index 00000000..480a21c0 --- /dev/null +++ b/debian/libfprint-2-2.postinst.in @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +#DEBHELPER# + +if [ "$1" = "configure" -o "$1" = "upgrade" ] && command -V udevadm >/dev/null 2>&1; then + # apply hwdb rules at package installation, see + # + # NOTA BENE: after the DEBHELPER section since dh_installudev + # adds stuff there + # The devices ID list is auto-generated using the gbp postimport hook + # see debian/README.sources for more details. +${UDEVADM_TRIGGERS} +fi + +exit 0 diff --git a/debian/update-udev-triggers.sh b/debian/update-udev-triggers.sh new file mode 100755 index 00000000..f86f05ec --- /dev/null +++ b/debian/update-udev-triggers.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +srcdir="${GBP_SOURCES_DIR:-.}" +debpath="$(dirname "$0")" +autosuspend_file="$srcdir/data/autosuspend.hwdb" +commands_lines=() + +while IFS= read -r line; do + if [[ $line =~ ^usb:v([A-Fa-f0-9]{4})p([A-Fa-f0-9]{4}) ]]; then + vendor="$(echo "${BASH_REMATCH[1]}" | tr '[:upper:]' '[:lower:]')" + product="$(echo "${BASH_REMATCH[2]}" | tr '[:upper:]' '[:lower:]')" + commands_lines+=("\tudevadm trigger --action=add --attr-match=idVendor=$vendor --attr-match=idProduct=$product") + fi +done < "$autosuspend_file" + +export UDEVADM_TRIGGERS=$( IFS=$'\n'; echo -e "${commands_lines[*]}" ) + +for i in $debpath/libfprint-*.post*.in; do + out="${i%.in}" + envsubst < "$i" > "$out" + + if [ -n "$GBP_BRANCH" ]; then + if ! git diff-index --quiet HEAD -- "$out"; then + git add "$out" + dch "${out#$srcdir}: Devices triggers updated" + git add debian/changelog + debcommit + fi + fi +done