#!/bin/sh
MEM=`free | awk '/Mem/ {print $2}'`
if [ "$MEM" -lt 80000 ] ; then
  rm -f -r /opt/packages/tm_cpps*.ipk > /dev/null 2>&1
fi

DIR=/usr/share/tm_cpps
CFG=/usr/share/tm_cpps_cfg
cfgRestore()
{
  [ -f "$CFG"/"$1" ] && mv -f "$CFG"/"$1" "$DIR"
}
[ -d "$CFG" ] && {
  cfgRestore pars_replace.json
}

chmod 755 /etc/init.d/tm_serverd
chmod 755 /etc/init.d/hwclockd
find /usr/share/tm_cpps -exec chmod 755 {} \;
/etc/init.d/hwclockd enable
/etc/init.d/tm_serverd enable
/etc/init.d/hwclockd start > /dev/null 2>&1
/etc/init.d/tm_serverd start > /dev/null 2>&1

exit 0
