#!/bin/sh

VOLUME_FILE=/etc/current_volume
VOLUME_DEFAULT_VALUE=50

# Check args
if [ ${#} -ne 0 ]; then
    echo "Usage: $(basename ${0})"
    exit 1
fi

# Sanity check: File does not exist
if [ ! -f ${VOLUME_FILE} ]; then
    rw
    echo ${VOLUME_DEFAULT_VALUE} > ${VOLUME_FILE}
    ro
fi

# Sanity check: Check if integer
volume=$(cat "${VOLUME_FILE}")
if ! [ ! "${volume}" -ne "${volume}" ] 2> /dev/null; then
    rw
    echo ${VOLUME_DEFAULT_VALUE} > ${VOLUME_FILE}
    ro
    volume=${VOLUME_DEFAULT_VALUE}
fi
echo ${volume}
exit 0
