commit 657854ed229539d94d3101299c36791b91a301cd Author: niamtokik Date: Sat Apr 9 15:04:46 2022 +0000 init diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ffb8c34 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +# hotplugd urndis OpenBSD Makefile deploy +# +# Copyright (c) 2020 Mathieu Kerjouan +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +.PHONY += help +help: + @echo "Usage: make [install|help]" + +.PHONY += install +install: /etc/hotplug/attach /etc/hotplug/detach /etc/hotplug/device/urndis + rcctl enable hotplugd + rcctl start hotplugd + +/etc/hotplug: + mkdir $@ + +/etc/hotplug/device: /etc/hotplug + mkdir $@ + +/etc/hotplug/class: /etc/hotplug + mkdir $@ + +/etc/hotplug/attach: /etc/hotplug + cp etc_hotplug_attach.sh $@ + chmod +x $@ + +/etc/hotplug/detach: /etc/hotplug + cp etc_hotplug_detach.sh $@ + chmod +x $@ + +/etc/hotplug/device/urndis: /etc/hotplug/device + cp etc_hotplug_device_urndis.sh $@ + chmod +x $@ diff --git a/README.md b/README.md new file mode 100644 index 0000000..46d6048 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# sbin/hotplugd + +The Makefile was not tested, it was created only to give you an example of the command I would use to deploy it. + diff --git a/etc/hotplug/attach.sh b/etc/hotplug/attach.sh new file mode 100644 index 0000000..84104d1 --- /dev/null +++ b/etc/hotplug/attach.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Copyright (c) 2020 Mathieu Kerjouan +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +DEVCLASS="${1}" +DEVNAME="${2}" +DEVDRIVER=$(echo ${DEVNAME} | sed -E 's/^([a-z]+)([0-9]+$)/\1/') +DEVINDEX=$(echo ${DEVNAME} | sed -E 's/^([a-z]+)([0-9]+$)/\2/') + +if test -x /etc/hotplug/device/${DEVNAME} +then + logger execute /etc/hotplug/device/${DEVNAME} + /etc/hotplug/device/${DEVNAME} attach ${*} +elif test -x /etc/hotplug/device/${DEVDRIVE} +then + logger execute /etc/hotplug/device/${DEVDRIVER} + /etc/hotplug/device/${DEVDRIVER} attach ${*} +elif test -x /etc/hotplug/class/${DEVCLASS} +then + logger execute /etc/hotplug/class/${DEVCLASS} + /etc/hotplug/class/${DEVCLASS} attach ${*} +fi diff --git a/etc/hotplug/detach.sh b/etc/hotplug/detach.sh new file mode 100644 index 0000000..29993b8 --- /dev/null +++ b/etc/hotplug/detach.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Copyright (c) 2020 Mathieu Kerjouan +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +DEVCLASS="${1}" +DEVNAME="${2}" +DEVDRIVER=$(echo ${DEVNAME} | sed -E 's/^([a-z]+)([0-9]+$)/\1/') +DEVINDEX=$(echo ${DEVNAME} | sed -E 's/^([a-z]+)([0-9]+$)/\2/') + +if test -x /etc/hotplug/device/${DEVNAME} +then + /etc/hotplug/device/${DEVNAME} detach ${*} +elif test -x /etc/hotplug/device/${DEVDRIVER} +then + /etc/hotplug/device/${DEVDRIVER} detach ${*} +elif test -x /etc/hotplug/class/${DEVCLASS} +then + /etc/hotplug/class/${DEVCLASS} detach ${*} +fi diff --git a/etc/hotplug/device/urndis.sh b/etc/hotplug/device/urndis.sh new file mode 100644 index 0000000..42e4001 --- /dev/null +++ b/etc/hotplug/device/urndis.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Copyright (c) 2020 Mathieu Kerjouan +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +EVENT="${1}" +DEVCLASS="${2}" +DEVNAME="${3}" + +_attach() { + logger attach ${DEVNAME} + dhclient ${DEVNAME} +} + +_detach() { + logger detach ${DEVNAME} + sh /etc/netstart +} + +case "${EVENT}" +in + attach) _attach;; +esac