a2cloud/setup/usbgetty.txt

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2015-10-30 12:34:48 +00:00
#! /bin/bash
2016-10-25 17:42:29 +00:00
# vim: set tabstop=4 shiftwidth=4 noexpandtab filetype=sh:
2015-10-30 11:22:38 +00:00
ttyUSB=
pkill -f "sleep 86399"
if [[ $(grep -e '-scanttyUSB' <<< "$*") ]]; then
2016-10-25 17:42:29 +00:00
# called with -scantty isntead of device name?
2015-10-30 11:22:38 +00:00
2016-10-25 17:42:29 +00:00
# if upper USB port
if [[ -c /dev/ttyUSBupper ]]; then
ttyUSB=ttyUSBupper
2015-10-30 11:22:38 +00:00
2016-10-25 17:42:29 +00:00
# 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-)
2015-10-30 11:22:38 +00:00
2016-10-25 17:42:29 +00:00
# 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-)
2015-10-30 11:22:38 +00:00
2016-10-25 17:42:29 +00:00
# no port found eligible for getty
else
sleep 86399
fi
2015-10-30 12:38:31 +00:00
2015-10-30 11:22:38 +00:00
elif [[ $(grep -o 'ttyUSB[^ ]*' <<< "$*") ]]; then
2016-10-25 17:42:29 +00:00
# if specified USB device name is found
ttyUSB=$(grep -o 'ttyUSB[^ ]*' <<< "$*")
2015-10-30 11:22:38 +00:00
else
2016-10-25 17:42:29 +00:00
sleep 86399
2015-10-30 11:22:38 +00:00
fi
if [[ -c /dev/$ttyUSB && ! $(ps aux | grep "[g]etty.*$ttyUSB") ]]; then
2016-10-25 17:42:29 +00:00
# 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/" <<< "$@");
2015-10-30 11:22:38 +00:00
else
2016-10-25 17:42:29 +00:00
sleep 86399
2015-10-30 11:22:38 +00:00
fi