This commit is contained in:
niamtokik
2022-04-09 15:04:46 +00:00
commit 657854ed22
5 changed files with 145 additions and 0 deletions

45
Makefile Normal file
View File

@@ -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 $@

4
README.md Normal file
View File

@@ -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.

33
etc/hotplug/attach.sh Normal file
View File

@@ -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

30
etc/hotplug/detach.sh Normal file
View File

@@ -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

View File

@@ -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