#############main app####################
ThisFilePath=$(cd `dirname $0`; pwd)
if [ -f "${ThisFilePath}/sample_avenc" ]; then
rm /mnt/mtd/sample_avenc
cp ${ThisFilePath}/sample_avenc /mnt/mtd
fi

################usr lib do here#################
###########*.so reflesh here################
if [ -f "${ThisFilePath}/libvendor_ai_pub.so" ]; then
rm -rf /usr/lib/libvendor_ai_pub.so
cp -rf ${ThisFilePath}/libvendor_ai_pub.so /usr/lib
fi

if [ -f "${ThisFilePath}/libvendor_ai.so" ]; then
rm -rf /usr/lib/libvendor_ai.so
cp -rf ${ThisFilePath}/libvendor_ai.so /usr/lib
fi

if [ -f "${ThisFilePath}/libprebuilt_ai.so" ]; then
rm -rf /usr/lib/libprebuilt_ai.so
cp -rf ${ThisFilePath}/libprebuilt_ai.so /usr/lib
fi


###########*.ko do here################
if [ -f "${ThisFilePath}/nvp6158_kdrv.ko" ]; then
	rm -rf /lib/modules/4.9.118/hdal/nvp6158/nvp6158_kdrv.ko
	cp -rf ${ThisFilePath}/nvp6158_kdrv.ko /lib/modules/4.9.118/hdal/nvp6158
fi

if [ -f "${ThisFilePath}/hi_rtc.ko" ]; then
	rm -rf /mnt/mtd/hi_rtc.ko
	rm -rf /lib/modules/4.9.118/hdal/hi_rtc_4k/hi_rtc.ko
	cp -rf ${ThisFilePath}/hi_rtc.ko /lib/modules/4.9.118/hdal/hi_rtc_4k
fi

if [ -f "${ThisFilePath}/option.ko" ]; then
rm -rf /mnt/mtd/option.ko
rm -rf /lib/modules/4.9.118/kernel/drivers/usb/serial/option.ko
cp -rf ${ThisFilePath}/option.ko /lib/modules/4.9.118/kernel/drivers/usb/serial
fi

if [ -f "${ThisFilePath}/8192cu.ko" ]; then
rm -rf /mnt/mtd/8192cu.ko
cp -rf ${ThisFilePath}/8192cu.ko /mnt/mtd
fi



################net share ,do here###################
if [ -f "${ThisFilePath}/iptables.tar.gz" ]; then
rm -rf /usr/bin/ip6tabl*
rm -rf /usr/bin/iptabl*
rm -rf /usr/bin/xtables-multi
tar xzf ${ThisFilePath}/iptables.tar.gz -C /usr/bin
fi

if [ -f "${ThisFilePath}/iptables.lib.tar.gz" ]; then
rm -rf /usr/lib/libip*
rm -rf /usr/lib/libmnl*
rm -rf /usr/lib/libftn*
rm -rf /usr/lib/libxtabl*
tar xzf ${ThisFilePath}/iptables.lib.tar.gz -C /usr/lib
fi

if [ -f "${ThisFilePath}/net_share" ]; then
rm -rf /usr/bin/net_share
cp -rf ${ThisFilePath}/net_share /usr/bin/net_share
fi

############wifi and ap do here####################
if [ -d "${ThisFilePath}/wifi" ]; then
### /mnt/mtd ###
rm -rf /mnt/mtd/udhcp
cp -rf ${ThisFilePath}/wifi/udhcp /mnt/mtd

rm -rf /mnt/mtd/udhcpc
cp -rf ${ThisFilePath}/wifi/udhcpc /mnt/mtd

rm -rf /mnt/mtd/wpa-psk-tkip.conf
cp -rf ${ThisFilePath}/wifi/wpa-psk-tkip.conf /mnt/mtd

rm -rf /mnt/mtd/hostapd.conf
cp -rf ${ThisFilePath}/wifi/hostapd.conf /mnt/mtd

### /usr/bin/ ###
rm -rf /usr/bin/hostapd*
cp -rf ${ThisFilePath}/wifi/hostapd /usr/bin/
cp -rf ${ThisFilePath}/wifi/hostapd_cli /usr/bin/

rm -rf /usr/bin/ifdown-wlan
cp -rf ${ThisFilePath}/wifi/ifdown-wlan /usr/bin/

rm -rf /usr/bin/ifup-wlan
cp -rf ${ThisFilePath}/wifi/ifup-wlan /usr/bin/

rm -rf /usr/bin/ifup-hotspot
cp -rf ${ThisFilePath}/wifi/ifup-hotspot /usr/bin/

rm -rf /usr/bin/iwconfig
cp -rf ${ThisFilePath}/wifi/iwconfig /usr/bin/

rm -rf /usr/bin/iwgetid
cp -rf ${ThisFilePath}/wifi/iwgetid /usr/bin/

rm -rf /usr/bin/iwlist
cp -rf ${ThisFilePath}/wifi/iwlist /usr/bin/

rm -rf /usr/bin/tc
cp -rf ${ThisFilePath}/wifi/tc /usr/bin/

rm -rf /usr/bin/wpa_cli
cp -rf ${ThisFilePath}/wifi/wpa_cli /usr/bin/

rm -rf /usr/bin/wpa_passphrase
cp -rf ${ThisFilePath}/wifi/wpa_passphrase /usr/bin/

rm -rf /usr/bin/wpa_supplicant
cp -rf ${ThisFilePath}/wifi/wpa_supplicant /usr/bin/

###/usr/lib###

rm -rf /usr/lib/iwlib.so
cp -rf ${ThisFilePath}/wifi/iwlib.so /usr/lib

rm -rf /usr/lib/libnl.s*
cp -rf ${ThisFilePath}/wifi/libnl.so.1.1.4 /usr/lib
ln -s /usr/lib/libnl.so.1.1.4 /usr/lib/libnl.so.1

fi




################sh or app or resouse file##########

###start logo ###
if [ -f "${ThisFilePath}/logo.png" ]; then
rm -rf /mnt/mtd/pic/logo.png
cp -rf ${ThisFilePath}/logo.png /mnt/mtd/pic
fi

if [ -f "${ThisFilePath}/net_3g.png" ]; then
rm -rf /mnt/mtd/pic/net_3g.png
cp -rf ${ThisFilePath}/net_3g.png /mnt/mtd/pic
fi

if [ -f "${ThisFilePath}/net_box1.png" ]; then
rm -rf /mnt/mtd/pic/net_box1.png
cp -rf ${ThisFilePath}/net_box1.png /mnt/mtd/pic
fi

if [ -f "${ThisFilePath}/netfocusbox1.png" ]; then
rm -rf /mnt/mtd/pic/netfocusbox1.png
cp -rf ${ThisFilePath}/netfocusbox1.png /mnt/mtd/pic
fi

if [ -f "${ThisFilePath}/cfg_DVR_8CH.dtb" ]; then
rm -rf /mnt/mtd/cfg_DVR_8CH.dtb
cp -rf ${ThisFilePath}/cfg_DVR_8CH.dtb /mnt/mtd
fi

###net config ###

if [ -f "${ThisFilePath}/sample.renew" ]; then
rm -rf /mnt/mtd/udhcp/sample.renew
cp -rf ${ThisFilePath}/sample.renew /mnt/mtd/udhcp/sample.renew
fi

##mdev.conf#
if [ -f "${ThisFilePath}/mdev.conf" ]; then
rm -rf /mnt/mtd/mdev.conf
cp -rf ${ThisFilePath}/mdev.conf /mnt/mtd
fi

###run ctrl sh file,important ###
if [ -f "${ThisFilePath}/vg_boot.sh" ]; then
rm -rf /mnt/mtd/vg_boot.sh
cp -rf ${ThisFilePath}/vg_boot.sh /mnt/mtd
fi

###AI DSM ADAS BSD and so on ctrl here ###
if [ -f "${ThisFilePath}/active_safety_param.json" ]; then
rm -rf /mnt/mtd/active_safety_param.json
cp -rf ${ThisFilePath}/active_safety_param.json /mnt/mtd
fi

###AI DSM ADAS BSD and so on license ###
if [ -f "${ThisFilePath}/sign.bin" ]; then
rm -rf /mnt/mtd/sign.bin
cp -rf ${ThisFilePath}/sign.bin /mnt/mtd
fi

if [ -f "${ThisFilePath}/dsm_face_landmarks_detect.bin" ]; then
rm -rf /mnt/mtd/dsm_face_landmarks_detect.bin
cp -rf ${ThisFilePath}/dsm_face_landmarks_detect.bin /mnt/mtd
fi

if [ -f "${ThisFilePath}/dsm_mask_detect.bin" ]; then
rm -rf /mnt/mtd/dsm_mask_detect.bin
cp -rf ${ThisFilePath}/dsm_mask_detect.bin /mnt/mtd
fi
if [ -f "${ThisFilePath}/cargo_detect.bin" ]; then
rm -rf /mnt/mtd/cargo_detect.bin
cp -rf ${ThisFilePath}/cargo_detect.bin /mnt/mtd
fi

if [ -f "${ThisFilePath}/belt_detect.bin" ]; then
rm -rf /mnt/mtd/belt_detect.bin
cp -rf ${ThisFilePath}/belt_detect.bin /mnt/mtd
fi

if [ -f "${ThisFilePath}/fisheye_bsd_detect.bin" ]; then
rm -rf /mnt/mtd/fisheye_bsd_detect.bin
cp -rf ${ThisFilePath}/fisheye_bsd_detect.bin /mnt/mtd
fi

if [ -f "${ThisFilePath}/imagefusion_calibration.bin" ]; then
rm -rf /mnt/mtd/imagefusion_calibration.bin
cp -rf ${ThisFilePath}/imagefusion_calibration.bin /mnt/mtd
fi

### font ###
if [ -d "${ThisFilePath}/font" ]; then
rm -rf /mnt/mtd/font
cp -rf ${ThisFilePath}/font /mnt/mtd
fi

##unicom for diff 4g module###
if [ -f "${ThisFilePath}/unicom" ]; then
rm -rf /mnt/mtd/unicom
cp -rf ${ThisFilePath}/unicom /mnt/mtd
fi

### gps_nrtip ###
if [ -f "${ThisFilePath}/gps_nrt.json" ]; then
rm -rf /mnt/mtd/gps_nrt.json
cp -rf ${ThisFilePath}/gps_nrt.json /mnt/mtd
fi

### 360_pan_calibration ### 
if [ -f "${ThisFilePath}/360_pan_calibration.json" ]; then
rm -rf /mnt/mtd/360_pan_calibration.json
cp -rf ${ThisFilePath}/360_pan_calibration.json /mnt/mtd
fi

### wifi Ext by USB###
if [ -f "${ThisFilePath}/monitWlan" ]; then
rm -rf /usr/bin/monitWlan
cp -rf ${ThisFilePath}/monitWlan /usr/bin
fi

###tts so and resouse here####
if [ -f "${ThisFilePath}/libprebuilt_ai.so" ]; then
rm -rf /usr/lib/libmsc.so
cp -rf ${ThisFilePath}/libmsc.so /usr/lib
fi

if [ -d "${ThisFilePath}/msc" ]; then
rm -rf /mnt/mtd/msc
cp -rf ${ThisFilePath}/msc /mnt/mtd
fi


########reset to default##########
#i2c_access I2C2 0xa0  w 0x00 0x00 0x10
#i2c_access I2C2 0xa0  w 0x00 0x00 
#i2c_access I2C2 0xa0  r 0x03  


######sync to flash#############
sync

