commit b51c10e9d69b0d8ccddc2fd08f01de541e5ef50a Author: Skylar Ittner Date: Tue Oct 22 21:18:36 2024 -0600 Init repository diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fcb152 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out diff --git a/build_debian.sh b/build_debian.sh new file mode 100755 index 0000000..3072743 --- /dev/null +++ b/build_debian.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +function clean_exit() { + echo "Cleaning up" + sed -i "s/$VERSION/VERSION/" debian/DEBIAN/control + sed -i "s/$INSTALLSIZE/INSTALLSIZE/" debian/DEBIAN/control + exit 0 +} +trap "clean_exit" 2 + +mkdir -p out + +VERSION=$(cat version) +REVISION=1 +FILENAME="usb-udev-helper_$VERSION-${REVISION}_all.deb" +INSTALLSIZE=0 + +sed -i "s/VERSION/$VERSION/" debian/DEBIAN/control + +INSTALLSIZE=$(du -ks debian|cut -f 1) + +sed -i "s/INSTALLSIZE/$INSTALLSIZE/" debian/DEBIAN/control + +chmod 755 debian/usr/bin/getudevid +chown root:root debian/usr/bin/getudevid + +mkdir -p out + +dpkg-deb -b debian "out/$FILENAME" + +clean_exit diff --git a/debian/DEBIAN/control b/debian/DEBIAN/control new file mode 100644 index 0000000..8f0feb7 --- /dev/null +++ b/debian/DEBIAN/control @@ -0,0 +1,9 @@ +Package:usb-udev-helper +Version:VERSION +Installed-Size:INSTALLSIZE +Maintainer:Netsyms Technologies LLC +Section:misc +Homepage:https://netsyms.com +Priority:optional +Description:Assign predictable paths in /dev/usb/by-id to USB printers and Human Interface Devices, and adjust permissions to make them usable by the plugdev group. +Architecture:all diff --git a/debian/DEBIAN/copyright b/debian/DEBIAN/copyright new file mode 100644 index 0000000..9c28ef5 --- /dev/null +++ b/debian/DEBIAN/copyright @@ -0,0 +1,9 @@ +Copyright (c) 2024 Netsyms Technologies LLC + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/debian/DEBIAN/postinst b/debian/DEBIAN/postinst new file mode 100755 index 0000000..d0b6b22 --- /dev/null +++ b/debian/DEBIAN/postinst @@ -0,0 +1,9 @@ +#!/bin/sh + +# Ensure new udev rules take effect immediately +echo "Reloading and triggering udev." +udevadm control --reload || true +udevadm trigger || true + +echo "Adding $SUDO_USER to plugdev group." +usermod -aG plugdev $SUDO_USER || true \ No newline at end of file diff --git a/debian/etc/udev/rules.d/50-usb-udev-helper.rules b/debian/etc/udev/rules.d/50-usb-udev-helper.rules new file mode 100644 index 0000000..1623795 --- /dev/null +++ b/debian/etc/udev/rules.d/50-usb-udev-helper.rules @@ -0,0 +1,10 @@ +# +# Allow user-level access to some "raw" USB devices. +# Also assigns a permanent path for each device so it won't change if things are unplugged or rebooted. +# + +# USB printers +SUBSYSTEMS=="usb", DRIVERS=="usblp", MODE:="0660", GROUP="plugdev", PROGRAM="/usr/bin/getudevid $devpath" SYMLINK+="usb/by-id/printer_$result" + +# Scales, barcode scanners, etc +KERNEL=="hidraw*", MODE:="0660", GROUP="plugdev", PROGRAM="/usr/bin/getudevid $devpath" SYMLINK+="usb/by-id/hidraw_$result" diff --git a/debian/usr/bin/getudevid b/debian/usr/bin/getudevid new file mode 100755 index 0000000..6cd8413 --- /dev/null +++ b/debian/usr/bin/getudevid @@ -0,0 +1,9 @@ +#!/bin/bash + +# Get the vendor and product ID for a USB device path. +# Used in udev rules. + +PRODUCTID=$(udevadm info --attribute-walk --path=$1 | grep -m 1 "ATTRS{idProduct}==" | sed 's/^.*=="//' | sed 's/"$//') +VENDORID=$(udevadm info --attribute-walk --path=$1 | grep -m 1 "ATTRS{idVendor}==" | sed 's/^.*=="//' | sed 's/"$//') + +echo "$VENDORID:$PRODUCTID" \ No newline at end of file diff --git a/version b/version new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.0