#!/bin/bash

cp $1 /mnt/flash/debug

# Use a lockfile to ensure that only one debug output is
# being printed at a time. This does not ensure that nothing
# else is being printed to the console but it is a best effort.
LOCKFILE="/var/lock/save-debug-log.lock"
exec {LOCK_FD}>"$LOCKFILE"

flock -x ${LOCK_FD}

echo ========== Contents of $1 ==========
cat $1
echo ========== End of $1 ==========

flock -u ${LOCK_FD}