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

CFG_SAVE="$ADMIN_CFG_FILE.save"

perl ${ADMIN_SCRIPT_PATH}/setvdrconf.pl

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

if [ -s $CFG_SAVE ] && [ "$1" != "-f" ] ; then
   ALL_SCRIPTS=$(diff $ADMIN_CFG_FILE $CFG_SAVE | grep "^< /" | grep -v "setvdrconf\.pl" | cut -b 3- | cut -d ":" -f 1 | sort -u)
else
   ALL_SCRIPTS=$(cat $ADMIN_CFG_FILE | grep "^/" | grep -v "setvdrconf\.pl" | cut -d ":" -f 1 | sort -u)
fi

LAST_SCRIPT=""
echo "perl ${ADMIN_SCRIPT_PATH}/cfgplg.pl 2>&1 >> ${ADMIN_LOG_FILE}" >> $ADMIN_EXEC_SCRIPT

for i in $ALL_SCRIPTS ; do
   if [ -f ${i} ] ; then
      echo "${i} 2>&1 >> $ADMIN_LOG_FILE" >> $ADMIN_EXEC_SCRIPT
   else
      echo "#<${i}> not found" >> $ADMIN_EXEC_SCRIPT
      echo "<${i}> not found"
   fi
done
echo "cp -f $ADMIN_CFG_FILE $CFG_SAVE" >> $ADMIN_EXEC_SCRIPT
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
if [ "$1" = "-f" ] ; then
   sh $ADMIN_EXEC_SCRIPT
fi
