#!/bin/sh

. config/options $1

mkdir -p $INSTALL/usr/bin
  if [ "$OPENELEC_VERSION" = devel ]; then
    cp $PKG_DIR/scripts/autoupdate.devel $INSTALL/usr/bin/autoupdate
  else
    cp $PKG_DIR/scripts/autoupdate.release $INSTALL/usr/bin/autoupdate
  fi

mkdir -p $INSTALL/etc
  if [ -f $PROJECT_DIR/$PROJECT/autoupdate/repo.conf ]; then
    cp $PROJECT_DIR/$PROJECT/autoupdate/repo.conf $INSTALL/etc
  else
    if [ "$OPENELEC_VERSION" = devel ]; then
      cp $PKG_DIR/config/repo.conf.devel $INSTALL/etc/repo.conf
    else
      cp $PKG_DIR/config/repo.conf.release $INSTALL/etc/repo.conf
    fi
  fi

  if [ -f $PROJECT_DIR/$PROJECT/autoupdate/update.key.db ]; then
    cp $PROJECT_DIR/$PROJECT/autoupdate/update.key.db $INSTALL/etc
  fi

  if [ -f $PROJECT_DIR/$PROJECT/autoupdate/update.conf ]; then
    cp $PROJECT_DIR/$PROJECT/autoupdate/update.conf $INSTALL/etc
  else
    mkdir -p $INSTALL/usr/config
    cp $PKG_DIR/config/update.conf $INSTALL/usr/config
  fi

mkdir -p $INSTALL/etc/crontabs
  echo -e "1 */6 * * *\t/usr/bin/autoupdate" >> $INSTALL/etc/crontabs/root

