how do your hotplugd(8) scripts look? mine is messy and needs cleaning.

izzy Meyer <[email protected]>
Newsgroups gmane.os.openbsd.misc
Message-ID <[email protected]>
Hello misc@

I have slowly been working on this now-sprawling hotplugd(8) attach
script but I'm not a fan of how messy and complex it has gotten. Any
tips to clean it up and make it more modular? I don't like the usbdevs
hack, it feels uncomfortable to me for some reason. How do your
hotplugd(8) scripts look?

/etc/hotplug $ bat -l sh -pp attach
#!/bin/ksh

DEVCLASS=$1
DEVICE=$2

[ "$DEVCLASS" -eq 0 ] || exit 0

case "$DEVICE" in
    ugen*)
        # printer for CUPS
        if usbdevs -v | grep -q '03f0:dd11'; then

            ugen=$(usbdevs -v | awk '
                /03f0:dd11/ { found=1 }
                found && /driver: ugen[0-9]+/ {
                    sub(/^[[:space:]]*driver: /, "")
                    print
                    exit
                }
            ')

            [ "$DEVICE" = "$ugen" ] || exit 0

            usbctl=$(usbdevs -v | awk -v dev="$ugen" '
                /^Controller \/dev\/usb[0-9]+:/ {
                    ctl=$2
                    sub(":", "", ctl)
                }
                $0 ~ ("driver: " dev "$") {
                    print ctl
                    exit
                }
            ')

            logger -t hotplug "Printer attached"

            if [ -n "$usbctl" ]; then
                chown _cups:_saned /dev/${ugen}.* "$usbctl"
                chmod 660 /dev/${ugen}.* "$usbctl"
            fi
        # usb midi keyboard setup for LMMS
        elif usbdevs -v | grep -q '28e9:0001'; then
            logger -t hotplug "USB Midi Keyboard Attached"
            
            ( midicat -q midi/0 -q midithru/0 ) &
        fi
        ;;
    uvideo*)
        # usb webcam setup for video calls
        logger -t hotplug "USB Webcam attached"

        chown nobody:nobody /dev/video*
        chmod 0777 /dev/video*
        ;;
esac

Thanks for any help.

-- 
iz (she/her)

> I say mundane things
> so the uninteresting
> just might get noticed.

izder456 (dot) neocities (dot) org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.