#!/bin/sh
[ -z "$ROOT" ] && ROOT=/www
CONFIG=$ROOT/config

[ -f $CONFIG/api.conf ] && source $CONFIG/api.conf
[ -f $CONFIG/mqtt.conf ] && source $CONFIG/mqtt.conf
if [ -z "$OPKG_REPO" ] ; then
  OPKG_REPO=`echo $CLOUD_ADDRESS | sed 's|/cloud/api/config|/openwrt|g'`
fi

release=`cat /etc/openwrt_release  | grep DISTRIB_RELEASE | cut -d "'" -f 2`
target=`cat /etc/openwrt_release  | grep DISTRIB_TARGET | cut -d "'" -f 2`
arch=`cat /etc/openwrt_release  | grep DISTRIB_ARCH | cut -d "'" -f 2`

cat > /etc/opkg/distfeeds.conf <<- EOM
src/gz core $OPKG_REPO/$release/targets/$target/packages
src/gz base $OPKG_REPO/$release/packages/$arch/base
src/gz packages $OPKG_REPO/$release/packages/$arch/packages
src/gz routing $OPKG_REPO/$release/packages/$arch/routing
EOM

cat > /etc/opkg.conf <<- EOM
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
EOM