#!/bin/sh
. /etc/openwrt_release
BRANCH=${DISTRIB_RELEASE%.*}
SOC=${DISTRIB_TARGET#*/}
FEED="https://openwrt.132lan.ru/packages/${BRANCH}/packages/${DISTRIB_ARCH}/modemfeed"
KMOD="https://openwrt.132lan.ru/packages/${BRANCH}/packages/${DISTRIB_ARCH}/kmods/${DISTRIB_RELEASE}/${SOC}"
cd /tmp
if [ ! "$(grep modemfeed /etc/opkg/customfeeds.conf)" ]; then
	wget -q ${FEED}/Packages.gz -O /dev/null
	case $? in
		0)
			echo "src/gz modemfeed $FEED" >> /etc/opkg/customfeeds.conf
			wget https://openwrt.132lan.ru/packages/${BRANCH}/packages/repo.pub
			opkg-key add repo.pub
		;;
		*) echo "Failed add repository modemfeed!"
	esac
	wget -q ${KMOD}/Packages.gz -O /dev/null
	case $? in
		0) echo "src/gz modem_kmod $KMOD >> /etc/opkg/customfeeds.conf" ;;
		*) echo "Failed add repository modem_kmod!"
	esac
	opkg update
fi
