KIEKjes Upload System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

#!/bin/sh
set -e
USB_CLASS_STILL_IMAGE=6
USB_SUBCLASS_STILL_IMAGE_DEVICE=1
USB_PROTOCOL_STILL_IMAGE_DEVICE=1
device=
usbbid=
usbpid=
usbvid=
mntprefix=/run/kiekmtp
usage() {
echo "usage: $0 [-h] [-r DEVICE | -w [-b BUSID] [-v VENDORID] [-p PRODUCTID] [-m MNTPREFIX]]" >&2
}
while getopts hwr:b:v:p:m: opt; do
case "$opt" in
w) action=watch;;
r) action=remove; device="$OPTARG";;
b) usbbid="$OPTARG";;
v) usbvid="$(printf "%04x" 0x$OPTARG)";;
p) usbpid="$(printf "%04x" 0x$OPTARG)";;
m) mntprefix="$OPTARG";;
h) usage; exit 0;;
?) usage; exit 255;;
esac
done
shift $(($OPTIND - 1))
case "$action" in
watch)
kiekmon-usb \
${usbbid:+-b $usbbid} \
${usbvid:+-v $usbvid} \
${usbpid:+-p $usbpid} | \
-c $USB_CLASS_STILL_IMAGE -C $USB_SUBCLASS_STILL_IMAGE_DEVICE -P $USB_PROTOCOL_STILL_IMAGE_DEVICE | \
rp-get . rm_command | \
while read -r sysdir && read -r rmcmd; do (
busnum=$(cat "$sysdir/busnum")
devnum=$(cat "$sysdir/devnum")
devvid=$(cat "$sysdir/idVendor")
devpid=$(cat "$sysdir/idProduct")
mkdir -p "$mntprefix/$busnum-$devnum"
if afp-mtp-mount -D $devvid:$devpid "$mntprefix/$busnum-$devnum"; then
rp-make "$mntprefix/$busnum-$devnum" protocol=file rm_command="$0 -r '$mntprefix/$devname@$rmcmd'"
else
rmdir "$mntprefix/$devname"
fi
) || true; done
;;
remove)
printf "%s\n" "$device" | sed -e 's/@/ /' | read -r mntdir usbrmcmd
fusermount -u "$mntdir"
rmdir "$mntdir"
$usbrmcmd
;;
esac