#!/bin/bash

# This script checks if the modem is present and ready

# Make sure we have a sane PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin

devfile="/dev/modem"
statusfile="/dev/.modem-data/status"

if [ ! -c "$devfile" ]; then
    echo "Modem device not present" >&2
    exit 1
fi

if [ ! -s "$statusfile" ]; then
    echo "no modem status found" >&2
    exit 1
fi

status="$(< "$statusfile")"
if [ "$status" != "READY" ]; then
    echo "modem not ready (status = '$status')" >&2
    exit 1
fi

exit 0
