jens-maus/cuxd

View on GitHub
ccux86/update_script

Summary

Maintainability
Test Coverage
#!/bin/sh

cuxd/cuxd -v 2>/dev/null;if [ "$?" -ne "0" ];then echo "wrong binary";exit 2;fi

ADDON_DIR=/usr/local/addons/cuxd
CONFIG_DIR=/usr/local/etc/config
RCD_DIR=$CONFIG_DIR/rc.d

# make sure the addon and rc.d dir exist
mkdir -p $ADDON_DIR
chmod 755 $ADDON_DIR
mkdir -p $RCD_DIR
chmod 755 $RCD_DIR

# remove old stuff
rm -f $ADDON_DIR/fw.tar.gz
rm -f $ADDON_DIR/*.ko
rm -f $ADDON_DIR/lib*.so*
rm -f $ADDON_DIR/*.ccc
rm -f $ADDON_DIR/hm_addons.cfg.*
rm -f $ADDON_DIR/cuxd_addon.cfg
rm -f $ADDON_DIR/extra/curl
rm -f $ADDON_DIR/extra/socat
rm -f $ADDON_DIR/libusb-1.0.*

# remove daemon
rm -f $ADDON_DIR/cuxd

# disable debugging
rm -f $ADDON_DIR/cuxd.dbg
# enable debugging after installation "LOGLEVEL LOGFILE"
#echo "10 /tmp/cuxddbglog.txt" >$ADDON_DIR/cuxd.dbg

# remove link to website
rm -f $CONFIG_DIR/addons/www/cuxd

# save current configuration
if [ -f "$ADDON_DIR/cuxd.ps" ]; then
  cp -af $ADDON_DIR/cuxd.ps $ADDON_DIR/cuxd.ps.old
fi

# copy addon
cp -af cuxd/* $ADDON_DIR/

# copy startup script
cp -af rc.d/* $RCD_DIR/

# link to website
ln -sf $ADDON_DIR $CONFIG_DIR/addons/www/cuxd

# add menu
touch $CONFIG_DIR/hm_addons.cfg
# $ADDON_DIR/update_addon cuxd $ADDON_DIR/cuxd_addon.cfg
./update_addon cuxd cuxd_addon.cfg

# sync filesystems to make sure all changes are written to disk
sync

PSPID=`ps -o pid,comm | awk '{if($2=="ReGaHss"){print $1}}'`
if [ "$PSPID" != "" ]
then
  if [ -f /etc/config/InterfacesList.xml ]
  then
    grep "<name>CUxD</name>" /etc/config/InterfacesList.xml
    rc=$?

    if [ $rc -ne 0 ]
    then
# stop ReGa
      /etc/init.d/S??ReGaHss stop
    fi

# restart CUxD
    $RCD_DIR/cuxdaemon stop
    $RCD_DIR/cuxdaemon start

    if [ $rc -ne 0 ]
    then
# start ReGa
      /etc/init.d/S??ReGaHss start
    fi

  fi
fi

# all CCUs perform a reboot after installing
# addons via WebUI.
exit 0