2 # functions, strings and other constants for shell scripts
4 # for relation between dit unit and speed in words/min
5 # VVVVV=64, CODEX=60, PARIS=50
7 # default speed [words/minute]
9 # default priority (ROUTINE)
12 # timeout [sec] for fetch operations
15 # maximal source polling interval: a bit more than one day
17 # file for communication with extractor
18 EXTRACTORFILE
=extractor.dat
20 # set directory for temporary files (only if no usable value)
21 if test ! -d "$TMPDIR" -o ! -w "$TMPDIR" -o ! -x "$TMPDIR" -o ! -r "$TMPDIR"
23 # if possible, use ramdisk (on Linux)
25 then TMPDIR
=/dev
/shm
/ambros
26 else TMPDIR
=/tmp
/ambros
29 mkdir
-p $TMPDIR ||
{ echo cannot create tempdir
$TMPDIR ; exit 4 ; }
31 # could be part of temp dir, but may be independent (long-lasting)
32 LOGDIR
=/tmp
/ambros
/log
33 mkdir
-p $LOGDIR ||
{ echo cannot create logdir
$LOGDIR ; exit 4 ; }
34 # logfile generator, argument is log name specification
37 lfile
=$LOGDIR/$1-`date +%W`.log
38 echo "# $lfile `date '+%c, week %W'`" >> $lfile
41 # logging to file=arg1 and to stderr with identification=arg2
47 echo `date +%w%H%M` $id : $@
>> $fn
51 # directory for text sources
53 # suffix for file names
54 SOURCEFILESUFFIX
='.txt'
57 CHANNELCONFIG
=channel.cfg
58 SOURCECONFIG
=source.cfg
61 CHANNELSTATUS
=status.dat
62 SOURCESTATUS
=status.dat
64 # initial values for source status file
68 # signal number to terminate daemons (argument for kill)
71 # function to read config value by name
72 # arguments: configfile name [separators]
73 # value in stdout, exit nonzero if error
74 # if separators are given, will be replaced by SPC in output
75 # (e.g ',;' will result in returning "a,b;c" as "a b c")
76 # WARNING: DO NOT USE '`' in values or separators!
78 local retline retval separators
79 # check if config file readable, else fail
80 test -r "$1" ||
return 2
81 # get last line with name (possibly surrounded by whitespace)
82 # but ignore any line after separator '---'
83 retline
=`sed -e '/^[ ]*---/,$d' "$1"|grep -i "^[ ]*$2[ ]"|tail -n 1`
84 # fail if nothing found
85 test "$retline" != "" ||
return 1
86 # if no separators given, replace ' ' with ' ' ie NOP
88 # return second word from read line and substitute separators by SPC
89 echo $retline |
{ read _ retval _
; echo $retval ; } |
90 sed -e "s\`[$separators]\` \`g"
93 # function to get current time (epoch) in seconds
98 # function for hashing source texts
100 cksum $1 |
{ read cfc _