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.
58 lines
1.3 KiB
58 lines
1.3 KiB
#!/bin/sh
|
|
set -e
|
|
|
|
device=
|
|
usbbid=
|
|
usbpid=
|
|
usbvid=
|
|
|
|
usage() {
|
|
echo "usage: $0 [-h] [-r DEVICE | -w [-b BUSID] [-v VENDORID] [-p PRODUCTID] [PATTERN]]" >&2
|
|
}
|
|
|
|
while getopts hwr:b:v:p: 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)";;
|
|
h) usage; exit 0;;
|
|
?) usage; exit 255;;
|
|
esac
|
|
done
|
|
shift $(($OPTIND - 1))
|
|
pattern="$1"
|
|
|
|
case "$action" in
|
|
watch)
|
|
kiekmon-usb -w \
|
|
${usbbid:+-b $usbbid} \
|
|
${usbvid:+-v $usbvid} \
|
|
${usbpid:+-p $usbpid} \
|
|
-c 6 -C 1 -P 1 | \
|
|
rp-get . rm_command | \
|
|
while read -r sysdir && read -r rmcmd; do (
|
|
trap "$rmcmd" INT TERM
|
|
busnum=$(cat "$sysdir/busnum")
|
|
devnum=$(cat "$sysdir/devnum")
|
|
info=$(ptpcam --bus=$busnum --dev=$devnum -i)
|
|
if [ -z "$info" ]; then
|
|
$rmcmd
|
|
exit
|
|
fi
|
|
|
|
if [ -n "$pattern" ]; then
|
|
model="$(printf "%s\n" "$info" | grep '^Model:' | cut -d ' ' -f2-)"
|
|
case "$model" in
|
|
$pattern) ;;
|
|
*) "$rmcmd"; exit;
|
|
esac
|
|
fi
|
|
rp-make "$sysdir" protocol=ptp rm_command="$rmcmd"
|
|
) || true; done
|
|
;;
|
|
remove)
|
|
kiekmonitor-usb -r "$device"
|
|
;;
|
|
esac
|
|
|