#!/bin/sh /etc/rc.common
START=99
OPKG_PATH=/mnt/usb_disk1/opkg-install

start() {
LAN_INF=$(uci -q -P /var/state get network.lan.ifname)
 sed -i "/^USHARE_IFACE/s:^.*$:USHARE_IFACE=$LAN_INF:" /etc/ushare.conf
 ushare_enable=$(uci -q get ushare.@ushare[0].enabled)
 if [ "$ushare_enable" = "1" ]; then
    ushare &
 fi
}

stop() {
killall -9 ushare
}

install() {   
	. /sbin/vigorcode.sh
   remove
   opkg -V2 --nodeps -dest usb install "$PKG_SERVER"libfaad2_2.6.1-1_arm.ipk   
   opkg -V2 --nodeps -dest usb install "$PKG_SERVER"libffmpeg_20080419-1_arm.ipk
   opkg -V2 --nodeps -dest usb install "$PKG_SERVER"libdlna_0.2.3-1_arm.ipk
   opkg -V2 --nodeps -dest usb install "$PKG_SERVER"libupnp_1.6.6-1_arm.ipk
   opkg -V2 --nodeps -dest usb install "$PKG_SERVER"ushare_1.1a-1_arm.ipk
   
   ln -s $OPKG_PATH/usr/lib/libavcodec.so.51.55.0 /usr/lib/libavcodec.so.51
   ln -s $OPKG_PATH/usr/lib/libavformat.so.52.13.0 /usr/lib/libavformat.so.52
   ln -s $OPKG_PATH/usr/lib/libdlna.so.0.2.3 /usr/lib/libdlna.so.0
   ln -s $OPKG_PATH/usr/lib/libixml.so.2.0.4 /usr/lib/libixml.so.2
   ln -s $OPKG_PATH/usr/lib/libupnp.so.3.0.5 /usr/lib/libupnp.so.3
   ln -s $OPKG_PATH/usr/lib/libavdevice.so.52.0.0 /usr/lib/libavdevice.so.52
   ln -s $OPKG_PATH/usr/lib/libavutil.so.49.6.0 /usr/lib/libavutil.so.49
   ln -s $OPKG_PATH/usr/lib/libfaad.so.1.0.0 /usr/lib/libfaad.so.1
   ln -s $OPKG_PATH/usr/lib/libthreadutil.so.2.2.3 /usr/lib/libthreadutil.so.2
   
   cp $OPKG_PATH/usr/bin/ushare /usr/bin/ushare
   
}

remove() {
stop
rm -rf $OPKG_PATH/etc/ushare.conf
rm -rf $OPKG_PATH/etc/config/ushare
rm -rf $OPKG_PATH/etc/init.d/ushare
rm -rf $OPKG_PATH/usr/bin/ushare
rm -rf $OPKG_PATH/usr/lib/libavcodec.so.51.55.0
rm -rf $OPKG_PATH/usr/lib/libavformat.so.52.13.0
rm -rf $OPKG_PATH/usr/lib/libdlna.so.0.2.3
rm -rf $OPKG_PATH/usr/lib/libixml.so.2.0.4
rm -rf $OPKG_PATH/usr/lib/libupnp.so.3.0.5
rm -rf $OPKG_PATH/usr/lib/libavdevice.so.52.0.0
rm -rf $OPKG_PATH/usr/lib/libavutil.so.49.6.0
rm -rf $OPKG_PATH/usr/lib/libfaad.so.1.0.0
rm -rf $OPKG_PATH/usr/lib/libthreadutil.so.2.2.3
}

boot() {
	[ -e /usr/lib/libavcodec.so.51 ] || ln -s $OPKG_PATH/usr/lib/libavcodec.so.51.55.0 /usr/lib/libavcodec.so.51
	[ -e /usr/lib/libavformat.so.52 ] || ln -s $OPKG_PATH/usr/lib/libavformat.so.52.13.0 /usr/lib/libavformat.so.52
	[ -e /usr/lib/libdlna.so.0 ] || ln -s $OPKG_PATH/usr/lib/libdlna.so.0.2.3 /usr/lib/libdlna.so.0
	[ -e /usr/lib/libixml.so.2 ] || ln -s $OPKG_PATH/usr/lib/libixml.so.2.0.4 /usr/lib/libixml.so.2
	[ -e /usr/lib/libupnp.so.3 ] || ln -s $OPKG_PATH/usr/lib/libupnp.so.3.0.5 /usr/lib/libupnp.so.3
	[ -e /usr/lib/libavdevice.so.52 ] || ln -s $OPKG_PATH/usr/lib/libavdevice.so.52.0.0 /usr/lib/libavdevice.so.52
	[ -e /usr/lib/libavutil.so.49 ] || ln -s $OPKG_PATH/usr/lib/libavutil.so.49.6.0 /usr/lib/libavutil.so.49
	[ -e /usr/lib/libfaad.so.1 ] || ln -s $OPKG_PATH/usr/lib/libfaad.so.1.0.0 /usr/lib/libfaad.so.1
	[ -e /usr/lib/libthreadutil.so.2 ] || ln -s $OPKG_PATH/usr/lib/libthreadutil.so.2.2.3 /usr/lib/libthreadutil.so.2
	[ -e/usr/bin/ushare ] || cp $OPKG_PATH/usr/bin/ushare /usr/bin/ushare
	start
}