#!/bin/sh
# This file specifies all componets to be copied or created to target file
# system. '$MKTOP' will map to target '/' directory.
#
# Copyright (c) Realtek Semiconductor Inc. 2003
#
# $Id: app_6104ipc_script,v 1.4 2004/02/24 09:22:40 erwin Exp $
#

# delete old directory
MKTOP=top.6104ipc
export MKTOP

if [ "XX"$MKTOP == "XX" ]; then
	echo "MKTOP variable not setted"
	exit 1
fi

if [ $MKTOP == "/" ]; then
	echo "Can not set to root directory"
	exit 1
fi

if [ -d $MKTOP ]; then
	echo $MKTOP already exist...
	rm -rf $MKTOP
else
#	mkdir $MKTOP
	echo $MKTOP does not exist, created...
fi

mkdir $MKTOP

rm -rf $MKTOP/dev
rm -rf $MKTOP/bin
rm -rf $MKTOP/sbin
rm -rf $MKTOP/usr
rm -rf $MKTOP/etc
rm -rf $MKTOP/var
rm -rf $MKTOP/proc
rm -rf $MKTOP/tmp
rm -rf $MKTOP/lib

# create system directory
mkdir $MKTOP/dev
mkdir $MKTOP/bin
mkdir $MKTOP/sbin
mkdir $MKTOP/usr
mkdir $MKTOP/etc
mkdir $MKTOP/var
mkdir $MKTOP/proc
mkdir $MKTOP/tmp

# mk node for system
mknod -m666 $MKTOP/dev/ttyS0 c 4 64
mknod -m666 $MKTOP/dev/tty c 5 0
mknod -m666 $MKTOP/dev/console c 5 1
mknod -m666 $MKTOP/dev/null c 1 3
mknod -m666 $MKTOP/dev/mtd b 31 0

# for PPPoE
mknod  -m666 $MKTOP/dev/ttyS1 c 4 65
mknod  -m666 $MKTOP/dev/ppp c 108 0
mknod  -m666 $MKTOP/dev/ptyp0 c 2 0
mknod  -m666 $MKTOP/dev/ttyp0 c 3 0

# for led and reset bottom
mknod -m666 $MKTOP/dev/led0 c 166 0
mknod -m666 $MKTOP/dev/led_wlan c 166 5
mknod -m666 $MKTOP/dev/switch c 167 2



mknod  -m666 $MKTOP/dev/ttyp0 c 3 0


#for pptp

mknod  -m666 $MKTOP/dev/ptyp1 c 2 1
mknod  -m666 $MKTOP/dev/ptyp2 c 2 2
mknod  -m666 $MKTOP/dev/ptyp3 c 2 3
mknod  -m666 $MKTOP/dev/ttyp1 c 3 1
mknod  -m666 $MKTOP/dev/ttyp2 c 3 2
mknod  -m666 $MKTOP/dev/ttyp3 c 3 3


mkdir $MKTOP/usr/sbin
ln -s /bin/pppd $MKTOP/usr/sbin/pppd
cp ../ppp-2.4.1/chat/chat $MKTOP/sbin

# copy binary file to target file system

# for uclibc shared library
mkdir $MKTOP/lib
cp ../uClibc-0.9.19/lib/libuClibc-0.9.19.so $MKTOP/lib/libc.so.0
cp ../uClibc-0.9.19/lib/ld-uClibc-0.9.19.so $MKTOP/lib/ld-uClibc.so.0
cp ../uClibc-0.9.19/lib/libpthread-0.9.19.so $MKTOP/lib/libpthread.so.0
cp ../uClibc-0.9.19/lib/libcrypt-0.9.19.so $MKTOP/lib/libcrypt.so.0
cp ../uClibc-0.9.19/lib/libdl-0.9.19.so $MKTOP/lib/libdl.so.0

cp ../uClibc-0.9.19/lib/libutil-0.9.19.so $MKTOP/lib/libutil.so.0

cp ../uClibc-0.9.19/lib/libresolv-0.9.19.so $MKTOP/lib/libresolv.so.0 #for "rdisc

cp ../uClibc-0.9.19/lib/libnsl-0.9.19.so $MKTOP/lib/libnsl.so.0 #for BPALOGIN


# ALG modules
cp -r ../ALG/modules $MKTOP/lib/

# copy etc script file
cp -R -p ../etc.adm/* $MKTOP/etc
rm $MKTOP/etc/profile.ap -f
rm -f $MKTOP/etc/init.d/rcS
mv  $MKTOP/etc/init.d/rcS.IPC $MKTOP/etc/init.d/rcS

# script files
cp ../script/*.sh $MKTOP/bin
cp -f ../script/wpa.sh.6104ipc $MKTOP/bin/wpa.sh
cp -f ../script/wlan.sh.6104ipc $MKTOP/bin/wlan.sh
cp -f ../script/init.sh.6104ipc $MKTOP/bin/init.sh
cp -f ../script/reboot.sh.6104ipc $MKTOP/bin/reboot.sh
cp -f ../script/upnp.sh.adm $MKTOP/bin/upnp.sh
cp -f ../script/monitor.sh.6104ipc $MKTOP/bin/monitor.sh
cp -f ../script/bridge.sh.6104ipc $MKTOP/bin/bridge.sh

# busybox, bridge utility and iptables

cp -R -p ../busybox-1.00-pre2/_install/* $MKTOP

# busybox 1.0 put route to /sbin
ln -s ../../bin/busybox  $MKTOP/usr/bin/route

#cp -R -p ../busybox-0.60.1/_install/* $MKTOP
cp ../bridge-utils/brctl/brctl $MKTOP/bin
#cp ../iptables-1.2.6a/iptables $MKTOP/bin
cp ../iptables-1.2.8/iptables $MKTOP/bin

# web server & flash tool
cp ../goahead-2.1.1/LINUX/webs-gw $MKTOP/bin/webs
cp ../goahead-2.1.1/LINUX/flash-gw $MKTOP/bin/flash

# wireless LAN configure tool
#cp ../wireless_tools.25/iwpriv $MKTOP/bin
#cp ../wireless_tools.25/iwconfig $MKTOP/bin

# udhcp DHCP client
cp ../udhcp-0.9.9-pre/udhcpc $MKTOP/bin
mkdir $MKTOP/usr/share
mkdir $MKTOP/usr/share/udhcpc
cp ../udhcp-0.9.9-pre/mips-scripts/* $MKTOP/usr/share/udhcpc
mkdir $MKTOP/etc/udhcpc

# udhcpd DHCP server
cp ../udhcp-0.9.9-pre/udhcpd $MKTOP/bin
mkdir $MKTOP/var/lib
mkdir $MKTOP/var/lib/misc

# add DNS relay (dnrd)
cp ../dnrd-2.10/src/dnrd $MKTOP/bin
mkdir $MKTOP/etc/dnrd

# PPPoE
cp ../ppp-2.4.1/pppd/pppd $MKTOP/bin
cp ../rp-pppoe-3.5/src/pppoe $MKTOP/bin

# L2TP
cp ../rp-l2tp-0.3/l2tpd $MKTOP/bin
mkdir $MKTOP/etc/l2tp
#cp ../rp-l2tp-0.3/l2tp.conf /$MKTOP/bin
mkdir $MKTOP/bin/handlers/
cp ../rp-l2tp-0.3/handlers/sync-pppd.so $MKTOP/bin/handlers/
cp ../rp-l2tp-0.3/handlers/l2tp-control $MKTOP/bin/handlers/
cp ../rp-l2tp-0.3/handlers/cmd.so $MKTOP/bin/handlers/

#Telstra Big Pond
cp ../bpalogin-2.0.2/bpalogin $MKTOP/bin
#cp ../bpalogin-2.0.2/bpalogin.conf /$MKTOP/bin

#Router Discover
cp ../iputils/rdisc $MKTOP/bin

#mkdir $MKTOP/etc/ppp
touch $MKTOP/etc/ppp/pap-secrets
chmod 600 $MKTOP/etc/ppp/pap-secrets
touch $MKTOP/etc/ppp/chap-secrets
chmod 600 $MKTOP/etc/ppp/chap-secrets

# copy var
cp -R -p ../var/* $MKTOP/var


# PPtP
cp ../pptp-1.31/pptp $MKTOP/bin
mkdir $MKTOP/var/lock

#cp ../iproute2/ip/ip $MKTOP/bin

#sntp
cp ../clockspeed-0.62/sntpclock $MKTOP/bin

#tools
#cp ../ftp/ftp/ftp $MKTOP/bin

#DDNS
cp ../ez-ipupdate-3.0.10/ez-ipupdate $MKTOP/bin

#cp ../IntersilFB/islpci.o $MKTOP/bin
#cp ../IntersilFB/setoid $MKTOP/bin
#cp ../IntersilFB/getoid $MKTOP/bin
cp ../IPC_11B/* $MKTOP/bin

#cp ../wireless_tools.26/iwconfig $MKTOP/bin
cp ../wireless_tools.26/iwpriv $MKTOP/bin
cp ../../image/config-gw.bin $MKTOP/etc/config.bin

mkdir $MKTOP/web
#cp -Rf ../goahead-2.1.1/web-6104wg/* $MKTOP/web
cp -Rf ../goahead-2.1.1/web/* $MKTOP/web

# ALG modules
#cp -r ../ALG/modules $MKTOP/lib/

# Diagd
cp ../Diagd/diagd-gw $MKTOP/bin/diagd

# copy version file
cp $VERSION_FILE $MKTOP/etc/version

#copy compiler_date file
cp $COMPILER_DATE_FILE $MKTOP/etc/compiler_date

# copy setup
cp ../console/setup $MKTOP/bin/setup

# copy dhis
cp ../dhid-5.1/dhid $MKTOP/bin/dhid

# copy upnp
mkdir $MKTOP/usr/lib
cp ../upnp_adm/libupnp-1.2.1/upnp/bin/* $MKTOP/usr/lib
cp ../upnp_adm/IGD/upnpd $MKTOP/usr/sbin
mkdir $MKTOP/etc/linuxigd
cp -Rf ../upnp_adm/IGD/etc/* $MKTOP/etc/linuxigd

# mount fspts
mkdir $MKTOP/dev/pts
mknod -m 666 $MKTOP/dev/ptmx c 5 2

# use insmod replace modprobe
#rm -f $MKTOP/sbin/modprobe
#ln -s insmod $MKTOP/sbin/modprobe


echo "clean CVS....."
find $MKTOP/ -name CVS -print | xargs -i rm -rf {}
