packaging: only apply rule if file exists 37/270537/2
authorMateusz Majewski <m.majewski2@samsung.com>
Fri, 4 Feb 2022 07:34:42 +0000 (08:34 +0100)
committerMateusz Majewski <m.majewski2@samsung.com>
Fri, 4 Feb 2022 13:03:27 +0000 (14:03 +0100)
Change-Id: I8b29a8ea266c98672080436854e9fe3c0ce44b5e

packaging/apply-peripheral-io-perms [new file with mode: 0644]
packaging/capi-system-peripheral-io.spec
packaging/peripheral-io.udev.rules

diff --git a/packaging/apply-peripheral-io-perms b/packaging/apply-peripheral-io-perms
new file mode 100644 (file)
index 0000000..6729982
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+[ $# -lt 2 ] && exit 1
+
+DIR="$1"
+shift
+
+for FILE in "$@"; do
+       # Let's make sure that the file really exists.
+       [ -e "$DIR/$FILE" ] || continue
+
+       chown root:priv_peripheralio "$DIR/$FILE"
+       chmod 0660 "$DIR/$FILE"
+       chsmack -a '*' "$DIR/$FILE"
+done
index 7c24610fe2e457b2b2924e97a00c6ef4f3cf3ba4..1d35aeea3e361402b6f597f7a3327a6b5fa2d7bb 100644 (file)
@@ -8,6 +8,7 @@ Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}.manifest
 Source10:   peripheral-io.udev.rules
 Source11:   peripheral-io.tmpfiles.conf
+Source12:   apply-peripheral-io-perms
 #Conflicts:  peripheral-bus
 BuildRequires:  awk
 BuildRequires:  cmake
@@ -48,6 +49,7 @@ Tizen Peripheral Input & Output Test Programs (test)
 cp %{SOURCE1} ./%{name}.manifest
 cp %{SOURCE10} .
 cp %{SOURCE11} .
+cp %{SOURCE12} .
 
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
@@ -59,6 +61,8 @@ mkdir -p %{buildroot}/usr/lib/tmpfiles.d
 install -m0644 peripheral-io.tmpfiles.conf %{buildroot}/usr/lib/tmpfiles.d/peripheral-io.conf
 mkdir -p %{buildroot}/usr/lib/udev/rules.d
 install -m0644 peripheral-io.udev.rules %{buildroot}/usr/lib/udev/rules.d/90-peripheral-io.rules
+mkdir -p %{buildroot}/%{_libexecdir}/peripheral-io
+install -m0755 apply-peripheral-io-perms %{buildroot}/%{_libexecdir}/peripheral-io/apply-peripheral-io-perms
 
 %post -p /sbin/ldconfig
 
@@ -70,6 +74,7 @@ install -m0644 peripheral-io.udev.rules %{buildroot}/usr/lib/udev/rules.d/90-per
 %{_libdir}/lib%{name}.so*
 /usr/lib/tmpfiles.d/peripheral-io.conf
 /usr/lib/udev/rules.d/90-peripheral-io.rules
+%{_libexecdir}/peripheral-io/apply-peripheral-io-perms
 %license LICENSE.APLv2
 
 %files devel
index 4d038b578db3d89ec4128260c868620fa34ab013..61de265149981e0eb91dfec324ec67cdabeea4ff 100644 (file)
@@ -1,35 +1,11 @@
 SUBSYSTEM=="gpio", KERNEL=="gpiochip[0-9]*", ACTION=="add",\
  MODE="0660", OWNER="root", GROUP="priv_peripheralio", SECLABEL{smack}="*"
 
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/value",\
- RUN+="/bin/chmod 0660 /sys%p/value",\
- RUN+="/bin/chsmack -a * /sys%p/value"
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/direction",\
- RUN+="/bin/chmod 0660 /sys%p/direction",\
- RUN+="/bin/chsmack -a * /sys%p/direction"
-SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/edge",\
- RUN+="/bin/chmod 0660 /sys%p/edge",\
- RUN+="/bin/chsmack -a * /sys%p/edge"
+SUBSYSTEM=="gpio", KERNEL=="gpio[0-9]*", ACTION=="add",\
+ RUN+="/usr/libexec/peripheral-io/apply-udev-file /sys%p value direction edge"
 
 SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/period",\
- RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/period",\
- RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/period"
-SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/duty_cycle",\
- RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/duty_cycle",\
- RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/duty_cycle"
-SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/polarity",\
- RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/polarity",\
- RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/polarity"
-SUBSYSTEM=="pwm", KERNEL=="pwm*", ACTION=="change",\
- RUN+="/bin/chown root:priv_peripheralio /sys%p/%E{EXPORT}/enable",\
- RUN+="/bin/chmod 0660 /sys%p/%E{EXPORT}/enable",\
- RUN+="/bin/chsmack -a * /sys%p/%E{EXPORT}/enable"
+ RUN+="/usr/libexec/peripheral-io/apply-udev-file /sys%p/%E{EXPORT} period duty_cycle polarity enable"
 
 SUBSYSTEM=="i2c-dev", KERNEL=="i2c-*", ACTION=="add", \
  MODE="0660", OWNER="root", GROUP="priv_peripheralio", SECLABEL{smack}="*"