summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-06-15 20:09:03 +0200
committerGravatar Nikias Bassen2017-06-15 20:09:03 +0200
commitb1bc747824c21749d3d09c1aa6b1ce71087cd8cd (patch)
treeea0eecf5d717fe3c95a250ded5843e0d2f7c4772
parentc2c463af0fe7988c465f88403a50a45af8cb2777 (diff)
downloadlibirecovery-b1bc747824c21749d3d09c1aa6b1ce71087cd8cd.tar.gz
libirecovery-b1bc747824c21749d3d09c1aa6b1ce71087cd8cd.tar.bz2
Add udev rules file to allow non-root users access DFU/Recovery mode devices
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac54
-rw-r--r--udev/39-libirecovery.rules.in5
-rw-r--r--udev/Makefile.am21
4 files changed, 82 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 021066e..0ddd6f7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = src include tools
+SUBDIRS = src include tools udev
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libirecovery.pc \ No newline at end of file
+pkgconfig_DATA = libirecovery.pc
diff --git a/configure.ac b/configure.ac
index 422e527..e13c571 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,59 @@ if test "$enable_largefile" != no; then
fi
AC_SUBST(LFS_CFLAGS)
+AC_ARG_WITH([udev],
+ AS_HELP_STRING([--with-udev],
+ [Configure and install udev rules file for DFU/Recovery mode devices]),
+ [],
+ [if $($PKG_CONFIG --exists udev); then with_udev=yes; else with_udev=no; fi])
+
+AC_ARG_WITH([udevrulesdir],
+ AS_HELP_STRING([--with-udevrulesdir=DIR],
+ [Directory for udev rules (implies --with-udev)]),
+ [with_udev=yes],
+ [with_udevrulesdir=auto])
+
+AC_ARG_WITH([udevrule],
+ AS_HELP_STRING([--with-udevrule="RULE"],
+ [udev activation rule (implies --with-udev)]),
+ [with_udev=yes],
+ [with_udevrule=auto])
+
+if test "x$with_udev" = "xyes"; then
+ if test "x$with_udevrule" = "xauto"; then
+ for I in plugdev storage disk staff; do
+ if grep $I /etc/group >/dev/null; then
+ USEGROUP=$I
+ break
+ fi
+ done
+ if test "x$USEGROUP" != "x"; then
+ if ! groups |grep $USEGROUP >/dev/null; then
+ AC_MSG_WARN([The group '$USEGROUP' was determined to be used for the udev rule, but the current user is not member of this group.])
+ fi
+ else
+ AC_MSG_ERROR([Could not determine an appropriate user group for the udev activation rule.
+ Please manually specify a udev activation rule using --with-udevrule=<RULE>
+ Example: --with-udevrule="OWNER=\\"root\\", GROUP=\\"myusergroup\\", MODE=\\"0660\\""])
+ fi
+ with_udevrule="OWNER=\"root\", GROUP=\"$USEGROUP\", MODE=\"0660\""
+ fi
+
+ if test "x$with_udevrulesdir" = "xauto"; then
+ udevdir=$($PKG_CONFIG --silence-errors --variable=udevdir udev)
+ if test "x$udevdir" != "x"; then
+ with_udevrulesdir=$udevdir"/rules.d"
+ else
+ with_udevrulesdir="\${prefix}/lib/udev/rules.d"
+ AC_MSG_WARN([Could not determine default udev rules directory. Using $with_udevrulesdir.])
+ fi
+ fi
+
+ AC_SUBST([udev_activation_rule], [$with_udevrule])
+ AC_SUBST([udevrulesdir], [$with_udevrulesdir])
+fi
+AM_CONDITIONAL(WITH_UDEV, test "x$with_udev" = "xyes")
+
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
AC_OUTPUT([
@@ -155,6 +208,7 @@ src/Makefile
include/Makefile
tools/Makefile
libirecovery.pc
+udev/Makefile
])
echo "
diff --git a/udev/39-libirecovery.rules.in b/udev/39-libirecovery.rules.in
new file mode 100644
index 0000000..3f1e906
--- /dev/null
+++ b/udev/39-libirecovery.rules.in
@@ -0,0 +1,5 @@
+# Handle iOS devices in DFU and Recovery mode - for use with libirecovery
+
+# Change group and permissions of iOS devices in DFU, legacy WTF, and Recovery mode
+ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05ac", ATTR{idProduct}=="122[27]|128[0-3]", @udev_activation_rule@
+
diff --git a/udev/Makefile.am b/udev/Makefile.am
new file mode 100644
index 0000000..2a7ad98
--- /dev/null
+++ b/udev/Makefile.am
@@ -0,0 +1,21 @@
+if WITH_UDEV
+edit = \
+ $(SED) -r \
+ -e 's|@udev_activation_rule[@]|$(udev_activation_rule)|g' \
+ < $< > $@ || rm $@
+
+udevrules_DATA = \
+ 39-libirecovery.rules
+
+39-libirecovery.rules: 39-libirecovery.rules.in
+ $(edit)
+
+EXTRA_DIST = \
+ 39-libirecovery.rules.in
+
+MAINTAINERCLEANFILES = \
+ 39-libirecovery.rules
+
+CLEANFILES = \
+ 39-libirecovery.rules
+endif