#!/bin/bash
BASEDIR=$(dirname "$0")
export BKLIST_PATH=/data/tmp/tmp

export DEFRUNHOST=raspberrypi
export RUNHOST=$(hostname)

cd ${BASEDIR}

. ./profile
if [ -e "./profile.${RUNHOST}" ]; then
	. ./profile.${RUNHOST}
fi

do_flg=ON
st_file=${BKLIST_PATH}/status.txt
err_file=${BKLIST_PATH}/error.txt
log_file=${BKLIST_PATH}/status.log
history_file=${BKLIST_PATH}/status_history.txt
if [ -f "${st_file}" ]; then
	flg=`cat ${st_file} | grep ok`
	if [[ "${flg}" != "ok" ]]; then
		cat $log_file >> $history_file	
	fi	
	cat $st_file >> $history_file
	rm -f $st_file
	if [ -f "${err_file}" ]; then
		cat ${err_file} >> $history_file
		rm -f ${err_file}
	fi
fi
if [ -f "${log_file}" ]; then
	rm -f $log_file
fi
