summary refs log tree commit diff
path: root/nixos/modules/services/networking/hylafax/faxq-wait.sh
blob: 8c39e9d20c1823025b8d11056e6e0404cc3b5786 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! @shell@ -e

# skip this if there are no modems at all
if ! stat -t "@spoolAreaPath@"/etc/config.* >/dev/null 2>&1
then
  exit 0
fi

echo "faxq started, waiting for modem(s) to initialize..."

for i in `seq @timeoutSec@0 -1 0`  # gracefully timeout
do
  sleep 0.1
  # done if status files exist, but don't mention initialization
  if \
    stat -t "@spoolAreaPath@"/status/* >/dev/null 2>&1 \
    && \
    ! grep --silent --ignore-case 'initializing server' \
    "@spoolAreaPath@"/status/*
  then
    echo "modem(s) apparently ready"
    exit 0
  fi
  # if i reached 0, modems probably failed to initialize
  if test $i -eq 0
  then
    echo "warning: modem initialization timed out"
  fi
done