devi@70: #!/bin/sh devi@70: devi@70: devi@70: _l3_start() devi@70: { devi@70: L3_TTY=`tty` devi@70: proc_on_the_term=`w | grep "${L3_TTY##/dev/}" | awk '{print $8;}'` devi@70: # freeBSD: devi@70: [ -n "$bsd" ] && \ devi@70: proc_on_the_term=`w | grep "${L3_TTY##/dev/tty}" | awk '{print $6;}'` devi@70: devi@70: if [ -n "$proc_on_the_term" ] && echo $proc_on_the_term | grep -qv script devi@70: then devi@70: _l3_start_session devi@70: _l3_run_script devi@70: else devi@70: _l3_env devi@70: _l3_prompt devi@70: fi devi@70: } devi@70: devi@70: _l3_env() devi@70: { devi@71: trap _l3_close_session 2 devi@71: trap _l3_close_session EXIT devi@70: true devi@70: } devi@70: devi@70: _l3_prompt() devi@70: { devi@74: export PS1='\[v2#\!#$?#$UID#$$#$(date +%s)#$PWD#\033[1024D\033[K\][\u@\h:\W]\$ ' devi@74: # export PS1='\[` devi@74: # a="$?"; devi@74: # HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\ devi@74: # +"%j$(cat ${LMHOME}/lab 2>/dev/null) %H:%M:%S"); devi@74: # echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ ' devi@70: } devi@70: devi@70: _l3_start_session() devi@70: { devi@71: export L3_SESSION_ID=${L3_TTY##*/}-$$ devi@71: export L3_HOME=~/.lilalo/ devi@70: mkdir -p $L3_HOME devi@70: devi@70: uname -a | grep -qi bsd && bsd=yes devi@70: parent=`cat /proc/$PPID/cmdline 2> /dev/null` devi@70: system=`uname -rs` devi@70: login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'` devi@70: #[ -n "$bsd" ] && login_from="" #FIXME! devi@70: start_time=`date +%s` devi@70: hostname=`hostname -f 2> /dev/null` devi@70: [ -n "$bsd" ] && hostname=`hostname` devi@70: devi@70: cat < $L3_HOME/$L3_SESSION_ID.info devi@70: devi@70: $L3_SESSION_ID devi@70: $hostname devi@70: $USER devi@70: $UID devi@70: $login_from devi@70: $tty devi@70: $system devi@70: $parent devi@70: $PPID devi@70: $$ devi@70: $start_time devi@70: devi@70: INFO devi@70: devi@70: unset parent system login_from start_time hostname devi@70: } devi@70: devi@70: _l3_run_script() devi@70: { devi@70: uname -a | grep -qi bsd && bsd=yes devi@70: flush="-f" #linux devi@70: [ -n "$bsd" ] && flush="-t 0" #freebsd devi@70: exec script $flush -q $L3_HOME/${L3_SESSION_ID}.script devi@70: } devi@70: devi@70: _l3_close_session() devi@70: { devi@71: ( devi@71: echo '' devi@71: history | sed 's/&/\&/; s//\>/g' devi@71: echo '' devi@71: ) >> $L3_HOME/$L3_SESSION_ID.info devi@70: } devi@70: