mirror of
https://github.com/RasppleII/a2cloud.git
synced 2024-11-27 05:49:25 +00:00
47 lines
1.6 KiB
Bash
47 lines
1.6 KiB
Bash
#! /bin/bash
|
|
# vim: set tabstop=4 shiftwidth=4 expandtab filetype=sh:
|
|
|
|
# called by udev as:
|
|
# ttyusbhandler [add|remove] ttyUSBname
|
|
|
|
# depending on what port ttyUSB adapter was added or removed from,
|
|
# automatically launches or kills ADTPro as needed
|
|
# restarts getty as needed
|
|
|
|
# remove:
|
|
# kill any ADTPro for this port
|
|
# if a getty is on this port, do nothing here, it will be killed and respawn
|
|
# iteself
|
|
|
|
# add:
|
|
# stagger adds by port number to prevent problems during simultaneous add at startup
|
|
# if lower port, solo adapter on lower port USB hub, or lower port of any USB hub,
|
|
# kill any ADTPro, rescan for getty if sleeping, and launch adtPro
|
|
# if upper port, solo adapter on upper port USB hub, or higher port of any USB hub,
|
|
# rescan for getty
|
|
|
|
if [[ $1 == "remove" ]]; then
|
|
rm /tmp/udev-$2-removed &> /dev/null
|
|
touch /tmp/udev-$2-removed
|
|
pkill -f "$2.*ADTPro"
|
|
elif [[ $1 == "add" ]]; then
|
|
[[ $2 == "ttyUSBlower" ]] && sleep 1.5
|
|
[[ ${#2} -gt 11 ]] && sleep "${2:15:2}"
|
|
if [[ $2 == "ttyUSBlower" || \
|
|
$2 == $(ls -1 /dev/ttyUSBlower_hub* 2> /dev/null | head -1 | cut -c 6-) || \
|
|
( ${2:0:12} == "ttyUSBlower_" && $2 != $(ls -1 /dev/ttyUSBupper_hub* 2> /dev/null | tail -1 | cut -c 6-) ) \
|
|
]]; then
|
|
rm /tmp/udev-ttyUSBlower-added &> /dev/null
|
|
touch /tmp/udev-ttyUSBlower-added
|
|
pkill -f "[A]DTPro"
|
|
pkill -f "[u]sbgetty"
|
|
exec /usr/local/adtpro/adtpro.sh headless serial
|
|
else # ttyUSBupper
|
|
rm /tmp/udev-ttyUSBupper-added &> /dev/null
|
|
touch /tmp/udev-ttyUSBupper-added
|
|
pkill -f "[g]etty.*ttyUSB"
|
|
fi
|
|
else
|
|
exit 2
|
|
fi
|