#!/bin/sh
source /etc/conf.d/vdr.admin.cfg

CFG_SAVE="$ADMIN_CFG_FILE.save"

rm -rf $ADMIN_EXEC_SCRIPT > /dev/null 2>&1
echo "#!/bin/sh" > $ADMIN_EXEC_SCRIPT

if [ -s $CFG_SAVE ] ; then
   ALL_SCRIPTS=`diff $ADMIN_CFG_FILE $CFG_SAVE | grep "^< /" | cut -b 3- | grep -v "/cfgvar.sh:" | cut -d ":" -f 1 | sort`
else
   ALL_SCRIPTS=`cat $ADMIN_CFG_FILE | grep "^/" | grep -v "/cfgvar.sh:" | cut -d ":" -f 1 | sort`
fi

LAST_SCRIPT=""
echo "sh ${ADMIN_SCRIPT_PATH}/cfgvar.sh 2>&1 >> ${ADMIN_LOG_FILE}" >> $ADMIN_EXEC_SCRIPT

for i in $ALL_SCRIPTS ; do
   if [ "${i}" != "$LAST_SCRIPT" ] ; then
      if [ -f ${i} ] ; then
         echo "sh ${i} 2>&1 >> $ADMIN_LOG_FILE" >> $ADMIN_EXEC_SCRIPT
      else
         echo "<${i}> not found" >> $ADMIN_EXEC_SCRIPT
         echo "<${i}> not found"
      fi
   fi
   LAST_SCRIPT=${i}
done
cp -f $ADMIN_CFG_FILE $CFG_SAVE
echo "depscan.sh >/dev/null 2>&1" >> $ADMIN_EXEC_SCRIPT
echo "rm -f $ADMIN_EXEC_SCRIPT >/dev/null 2>&1" >> $ADMIN_EXEC_SCRIPT
chmod +x $ADMIN_EXEC_SCRIPT
#echo "at -f $TODO_FILE now"
#at -f $TODO_FILE now
