example source config
[ambros.git] / src / ambros
blob8cfe728a18a28da5f2906b56c3e112bbeac2cf34
1 #!/bin/sh
2 # ambros:
3 # control script for one channel
5 if test "$1" = ""
6 then cat <<EOT
7 usage: $0 <configfile>
9 start AMBROS control instance configured by <configfile>
10 EOT
11 exit 1
14 # save directories of scripts and instance ("root", configuration file)
15 # is somewhat complicated to correctly handle relative paths
16 # (not using $OLDPWD etc to keep better portability)
17 owd=`pwd`
18 cd `dirname $0`
19 SCRIPTDIR=`pwd`
20 echo SCRIPTDIR: $SCRIPTDIR
21 cd "$owd"
22 cd `dirname $1`
23 ROOTDIR=`pwd`
24 echo ROOTDIR: $ROOTDIR
25 AMBROSCONFIG=`basename $1`
27 cd $SCRIPTDIR || { echo "cannot access scripts in $SCRIPTDIR" ; exit 3 ; }
28 # read global settings
29 . ./constants.sh
30 # (re)generate morse code table
31 cd morse && ./chargen.sh
33 if test ! -d "$ROOTDIR" -o ! -x "$ROOTDIR" -o ! -r "$ROOTDIR" -o ! -w "$ROOTDIR"
34 then echo "base directory ($ROOTDIR) is not usable, aborting!"
35 exit 2
38 echo
40 # get channel list
41 cd "$ROOTDIR"
42 echo working in channel $ROOTDIR
43 lchannels=`configread $AMBROSCONFIG CHANNELS '.,:;/'`
44 echo listed channels: $lchannels
46 # collect channel directory names
47 unset channels
48 for ch in $lchannels
50 if test -d $ch -a -x $ch -a -r $ch -a -w $ch
51 then channels="$ch $channels"
52 else echo "channel $ch is not read/write/accessible directory, ignoring!"
54 done
56 echo
58 GLOBALSPEED=`configread $AMBROSCONFIG WPM`
59 GLOBALSPEED=${GLOBALSPEED:-12}
60 echo global speed $GLOBALSPEED Words/min
62 cd "$ROOTDIR"
63 if test ! -d "$SOURCEDIR" -o ! -x "$SOURCEDIR" -o ! -r "$SOURCEDIR" -o ! -w "$SOURCEDIR"
64 then echo "source directory ($ROOTDIR/$SOURCEDIR) is unusable, aborting!"
65 exit 2
68 # handler for aborting
69 finish () {
70 echo
71 echo received abort signal: stopping all subprocesses
72 # if no PID is set, use 1 (init) as a dummy argument
73 /bin/kill -TERM ${pidassembler:-1} $pidchannelchief
74 echo and ending main control loop
75 date +"at %c"
76 AMBROSABORT=1
78 AMBROSABORT=0
80 trap finish INT TERM STOP
82 echo entering main control loop with PID $$
84 tmpf=${TMP:-/tmp}/ambros$$.tmp
86 while test $AMBROSABORT -eq 0
87 do : # main control loop
88 echo
89 echo passing main control loop
90 date +"at %c"
92 # collect source names
93 for ch in $channels
95 csources=`configread "$ch/$CHANNELCONFIG" SOURCES '.,:;/'`
96 lsources="$csources $lsources"
97 done
98 #echo listed sources: $lsources
99 cd $ROOTDIR/$SOURCEDIR
101 for ls in $lsources
102 do echo $ls
103 done
104 } | sort -r | uniq | {
105 while read sc
107 if test -d "$sc" -a -x "$sc" -a -r "$sc" -a -w "$sc"
108 then echo $sc
110 done
111 } > $tmpf
112 sources=`cat $tmpf`
113 echo currently valid sources: $sources
115 # fetch and process sources
116 $SCRIPTDIR/extractor $sources
118 # start&control `assembler`
119 # start&control `channelchief`
121 AMBROSABORT=99
123 done
125 rm -f $tmpf
127 echo
128 echo finished.