# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n

# Derek Molloy,, page 223
# access to cape manager slots and pinmuxing
export SLOTS=/sys/devices/platform/bone_capemgr/slots
export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins


# echo "Pid=$$, tty=`tty`, date=`date`" >>.profile.log

# Autostart an UniBone device emulation
# - Execution only on one login session of physical UART.
# - Hangs due to missing CPU arbitration if not run
#   in a real PDP-11 system.

case `tty` in

# Who on earth starts a session on "virtual tty" #1 ???
# However, use it to autostart an application
/dev/tty1)
        # install "screen", if not yet there .. make take several minutes!
        if [[ ! -x screen ]]
        then
           apt-get install --yes screen
        fi
        chmod +x ./autostart.sh
	screen -dmS "QUniBone" ./autostart.sh
;;

# ssh connection: check for background "screen" sessions, ask wether to connect
/dev/pts*)
        # background application? check for "QUniBone session"
        hit=`screen -ls | grep --count QUniBone`
        if [ $hit -ne 0 ]
        then
           read -p "Background QUniBone application running. Connect with \"screen\" ? [y/n] " -r
           if [[ $REPLY =~ ^[Yy]$ ]]
           then
             screen -d -r
           fi
        fi


# Serial `tty` under Debian is like "/dev/ttyS1"
#/dev/ttyS1)
#	./rt11.sh
#;;
esac

