### this file is sourced not run
PKGVER=1.1.1
PKGBUILD=1
PKGARCH=x86_64

# source: step
TARBALL=usbmuxd-$PKGVER.tar.bz2
MD5SUM=7450ab28776dcd10b593c9a4243e6755
SRC_URL=https://github.com/libimobiledevice/usbmuxd/releases/download/$PKGVER/$TARBALL
BUNDLE=

SLACKREQ='libusb
libimobiledevice >= libimobiledevice-1.3.0-x86_64-1
libplist >= libplist-2.2.0-x86_64-1'
SLACKDESC="usbmuxd: usbmuxd $PKGVER (iOS USB multiplexer)
usbmuxd:
usbmuxd: A socket daemon to multiplex connections from and to iOS devices.
usbmuxd:
usbmuxd: http://www.libimobiledevice.org/
usbmuxd: https://github.com/libimobiledevice/usbmuxd
usbmuxd:
usbmuxd:
usbmuxd:
usbmuxd:
usbmuxd:
"
# 20230131 it seems for ipad 1 to be recognized, and /var/lib/lockdown
# to be initialized, usbmuxd must be running before the ipad is plugged
# in for the first time, which will trigger the first udev rule.

# 20230327 with kernel 5.19.17 the apple_mfi_fastcharge module (available
# since k 5.7) gets in udev's way when two apple devices are connected.
# The kernel tries to create the same file in /sys/power (see dmesg log)
# for both devices, and of course it fails for the second device, which
# triggers a remove udev event. Effectively, apple_mfi_fastcharge prevents
# more than one USB idevice to stay connected. So we blacklist the module.

SLACKINSTALL='
getent group plugdev >/dev/null || addgroup -S plugdev

getent passwd usbmux >/dev/null || adduser -S -G plugdev \
	-h /var/lib/usbmux -H -s /sbin/nologin -g "usbmux daemon" usbmux

service usbmuxd start

udevadm control --reload
'
SLACKUNINSTALL='
udevadm control --reload

killall usbmuxd 2> /dev/null
sleep 1
killall -9 usbmuxd 2> /dev/null
'

### default pkg_download
pkg_prepare() {
	pkg_prepare_default &&
	# no systemd
	sed -i -e /systemd/d tmp/usbmuxd-*/udev/39-usbmuxd.rules.in
}

### default pkg_package
### build
pkg_build() {
	CONFFLAGS="$CONFFLAGS --disable-static --without-systemd"
	pkg_build_autoconf &&
	pkg_build_slackdesc &&
	install -m755 -d /etc/init.d /etc/modprobe.d &&
	install -m755 -t /etc/init.d ../pkg/dist/99-usbmuxd &&
	install -m644 -t /etc/modprobe.d ../pkg/dist/usbmuxd.conf &&
	: "all good above"
}

# vim:ft=sh:

