#!/bin/bash kill_all() { rm -f /tmp/uartmode* /tmp/ML_BAUD if fuser -k -TERM /dev/ttyS1 2>/dev/null; then sleep 0.1 fuser -k -KILL /dev/ttyS1 2>/dev/null fi # TODO: Find a smarter way to kill only the pids spawned by midilink killall -KILL fluidsynth mpg123 mt32d 2>/dev/null } conn_speed=115200 [ -f /tmp/UART_SPEED ] && conn_speed=$(cat /tmp/UART_SPEED) echo "ttyS1: "$conn_speed if [ "$1" == "1" ]; then if [ ! -f /tmp/uartmode1 ]; then kill_all echo "1" >/tmp/uartmode1 ( while true do if [ -f /media/fat/linux/ppp_options ]; then localip=$(ifconfig 2>/dev/null | sed -En 's/127.0.0.1//;s/169.254.*//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') remoteip=$(ifconfig 2>/dev/null | sed -En 's/127.0.0.1//;s/169.254.*//;s/.*inet (addr:)?(([0-9]*\.){2}[0-9]*).*/\2/p').254 if [ -z $localip ]; then echo cannot get local IP for PPP link. localip=0.0.0.0 remoteip=0.0.0.0 else echo "PPP link: $localip->$remoteip" fi echo "$localip:$remoteip" >/tmp/ppp_options cat /media/fat/linux/ppp_options >>/tmp/ppp_options echo 1 > /proc/sys/net/ipv4/ip_forward taskset 1 pppd $conn_speed file /tmp/ppp_options status=$? case $status in 1|2|3|4|6|7|9|137) echo "pppd exited with fatal error $status"; exit 0;; esac else echo "skip pppd" exit 0 fi [ ! -f /tmp/uartmode1 ] && exit 0 echo respawn pppd sleep 1 done ) & fi elif [ "$1" == "2" ]; then if [ ! -f /tmp/uartmode2 ]; then kill_all echo "1" >/tmp/uartmode2 ( while true do taskset 1 agetty $conn_speed ttyS1 -h & wait $! [ ! -f /tmp/uartmode2 ] && exit 0 echo respawn console sleep 1 done ) & fi elif [ "$1" == "3" ]; then if [ ! -f /tmp/uartmode3 ]; then kill_all echo "1" >/tmp/uartmode3 ( while true do taskset 1 midilink MENU QUIET & wait $! [ ! -f /tmp/uartmode3 ] && exit 0 echo respawn midilink sleep 1 done ) & fi elif [ "$1" == "4" ]; then if [ ! -f /tmp/uartmode4 ]; then kill_all echo "1" >/tmp/uartmode4 ( while true do taskset 1 midilink MENU QUIET & wait $! [ ! -f /tmp/uartmode4 ] && exit 0 echo respawn midilink sleep 1 done ) & fi elif [ "$1" == "5" ]; then if [ ! -f /tmp/uartmode5 ]; then kill_all echo "1" >/tmp/uartmode5 ( while true do taskset 1 midilink UDP QUIET BAUD $conn_speed wait $! [ ! -f /tmp/uartmode5 ] && exit 0 echo respawn midilink sleep 1 done ) & fi elif [ "$1" == "6" ]; then if [ ! -f /tmp/uartmode6 ]; then kill_all echo "1" >/tmp/uartmode6 if [ -f /media/fat/snid ]; then ( while true do RUST_LOG=info taskset 1 /media/fat/snid > /tmp/snid.log 2>&1 wait $! [ ! -f /tmp/uartmode6 ] && exit 0 echo respawn snid sleep 1 done ) & fi fi else if [ -f /tmp/uartmode* ]; then kill_all fi fi