From 1407719d231048954b541a1755845b55563130cb Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Fri, 30 Oct 2015 04:22:38 -0700 Subject: [PATCH] Add usbgetty to source tree --- setup/usbgetty.txt | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 setup/usbgetty.txt diff --git a/setup/usbgetty.txt b/setup/usbgetty.txt new file mode 100644 index 0000000..8d5b805 --- /dev/null +++ b/setup/usbgetty.txt @@ -0,0 +1,47 @@ +#!/bin/bash + +ttyUSB= + +pkill -f "sleep 86399" + +if [[ $(grep -e '-scanttyUSB' <<< "$*") ]]; then + # called with -scantty isntead of device name? + # echo "-scantty mode" + + # if upper USB port + if [[ -c /dev/ttyUSBupper ]]; then + ttyUSB=ttyUSBupper + + # if hub in upper port, use highest numbered port on hub + elif [[ $(ls -1 /dev/ttyUSBupper_hub* 2> /dev/null | wc -l) -gt 0 ]]; then + ttyUSB=$(ls -1 /dev/ttyUSBupper_hub* 2> /dev/null | tail -1 | cut -c 6-) + + # if hub in lower port with multiple adapters, use highest numbered port on hub + elif [[ $(ls -1 /dev/ttyUSBlower_hub* 2> /dev/null | wc -l) -gt 1 ]]; then + ttyUSB=$(ls -1 /dev/ttyUSBlower_hub* 2> /dev/null | tail -1 | cut -c 6-) + + # no port found eligible for getty + else + # echo "scantty no devices eligible: sleeping" + sleep 86399 + fi + + # echo "result:$ttyUSB" +elif [[ $(grep -o 'ttyUSB[^ ]*' <<< "$*") ]]; then + # echo "device specified" + # if specified USB device name is found + ttyUSB=$(grep -o 'ttyUSB[^ ]*' <<< "$*") +else + # echo "specified device failed: sleeping" + sleep 86399 +fi + +if [[ -c /dev/$ttyUSB && ! $(ps aux | grep "[g]etty.*$ttyUSB") ]]; then + # if adapter seems to exist and doesn't already have a getty, + # kill all USB gettys and start the getty, otherwise do nothing + pkill -f "/sbin/getty.*ttyUSB" + exec /sbin/getty $(sed "s/-scanttyUSB/$ttyUSB/" <<< "$@"); +else + # echo "getty already running or doesn't exist: sleeping" + sleep 86399 +fi