#!/bin/bash

max_sleep=$1
shift

serial=$( /home/product/code/firmware/current/bin/get_serial.sh )
if [ -z "$serial" ]; then
  serial=$( cat /etc/barracuda/serial )
fi
if [ -z "$serial" ]; then
  serial=1
fi

sleep_amount=$(( ${serial} % ${max_sleep} ))
echo "Sleeping for '$sleep_amount' seconds" >&2
sleep ${sleep_amount}
exec "$@"
