#!/bin/sh

cd /tmp
opkg remove breakout-server
wget http://firmware.dptechnics.com/dptv1/5/packages/breakout-server_1.0-1_ar71xx.ipk
opkg install breakout-server_1.0-1_ar71xx.ipk
rm breakout-server_1.0-1_ar71xx.ipk
wget http://firmware.dptechnics.com/dptv1/5.1/bbserver.txt
rm /etc/config/breakout-server
mv /tmp/bbserver.txt /etc/config/breakout-server
wget http://firmware.dptechnics.com/dptv1/5.1/packages/unzip_6.0-2_ar71xx.ipk
opkg install unzip_6.0-2_ar71xx.ipk
rm unzip_6.0-2_ar71xx.ipk
rm -r /www/
mkdir /www
cd /tmp
wget http://firmware.dptechnics.com/dptv1/5.1/iface.zip
unzip iface.zip -d /www
cd /tmp
wget http://firmware.dptechnics.com/dptv1/5.1/packages/libpcre_8.37-2_ar71xx.ipk
opkg install libpcre_8.37-2_ar71xx.ipk
rm libpcre_8.37-2_ar71xx.ipk
wget http://firmware.dptechnics.com/dptv1/5.1/packages/nginx_1.9.5-5_ar71xx.ipk
opkg install nginx_1.9.5-5_ar71xx.ipk
rm nginx_1.9.5-5_ar71xx.ipk
rm /etc/nginx/mime.types
rm /etc/nginx/nginx.conf
cd /etc/nginx
wget http://firmware.dptechnics.com/dptv1/5.1/mime.types
wget http://firmware.dptechnics.com/dptv1/5.1/nginx.conf
cd /tmp
wget http://firmware.dptechnics.com/dptv1/5.1/packages/libwebsockets_2015-04-29-3ae1badae7a05e0982e0dfbcb078da3d4b92a81d_ar71xx.ipk
opkg install libwebsockets_2015-04-29-3ae1badae7a05e0982e0dfbcb078da3d4b92a81d_ar71xx.ipk
rm libwebsockets_2015-04-29-3ae1badae7a05e0982e0dfbcb078da3d4b92a81d_ar71xx.ipk
wget http://firmware.dptechnics.com/dptv1/5.1/packages/espruino_1.80-1_ar71xx.ipk
opkg install espruino_1.80-1_ar71xx.ipk
rm espruino_1.80-1_ar71xx.ipk
wget http://firmware.dptechnics.com/dptv1/5.1/packages/dpt-webideserver_1_ar71xx.ipk
opkg install dpt-webideserver_1_ar71xx.ipk
rm dpt-webideserver_1_ar71xx.ipk

echo 'mkdir /var/log/nginx' > /etc/rc.local
echo 'mkdir /var/lib' >> /etc/rc.local
echo 'mkdir /var/lib/nginx' >> /etc/rc.local
echo 'mkdir /var/lib/nginx/body' >> /etc/rc.local
echo 'nginx' >> /etc/rc.local
echo 'dpt-web-ide-server' >> /etc/rc.local
echo 'breakout-server' >> /etc/rc.local
echo 'exit 0' >> /etc/rc.local
