extractor now also calculates duration, to speed up later stages
[ambros.git] / src / constants.sh
blob347e0d09b66b7ba624355acd747ec49408442308
1 #!/bin/sh
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
6 SPEEDBASE=50
7 # default speed [words/minute]
8 DEFAULTWPM=23
9 # default priority (ROUTINE)
10 DEFAULTPRIORITY=42
12 # timeout [sec] for fetch operations
13 FETCHTIMEOUT=50
15 # maximal source polling interval: a bit more than one day
16 MAXPOLLING=99999
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"
22 then
23 # if possible, use ramdisk (on Linux)
24 if test -d /dev/shm
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
35 logfile () {
36 local lfile
37 lfile=$LOGDIR/$1-`date +%W`.log
38 echo "# $lfile `date '+%c, week %W'`" >> $lfile
39 echo $lfile
41 # logging to file=arg1 and to stderr with identification=arg2
42 logit () {
43 local fn id
44 fn=$1
45 id=$2
46 shift 2
47 echo `date +%w%H%M` $id : $@ >> $fn
48 echo : $id : $@ >&2
51 # directory for text sources
52 SOURCEDIR=textsources
53 # suffix for file names
54 SOURCEFILESUFFIX='.txt'
56 # configfiles
57 CHANNELCONFIG=channel.cfg
58 SOURCECONFIG=source.cfg
60 # statusfiles
61 CHANNELSTATUS=status.dat
62 SOURCESTATUS=status.dat
64 # initial values for source status file
65 MININDEX=100
66 MAXINDEX=99999
68 # signal number to terminate daemons (argument for kill)
69 DAEMONTERMINATE=15
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!
77 configread () {
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
87 separators=${3:-' '}
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
94 nowsec () {
95 date +%s
98 # function for hashing source texts
99 hashfunction () {
100 cksum $1 | { read cfc _
101 echo $cfc