@echo off
SET PATH=c:\tizen-studio\tools;%PATH%

sdb root on

sdb shell mkdir -p /tmp/patchtmp
sdb shell mount -o remount,rw /
timeout /t 1 /nobreak
sdb shell mount -o remount.rw /hal

FOR /F %%g IN ('sdb shell uname -m') do SET ARCH=%%g
ECHO %ARCH%

ECHO ---- Install drvier (sdb push) ----
sdb shell rpm -e --nodeps wlandrv-plugin-tizen

sdb push ./noarch/connectivity/wifi-mesh/* /usr/lib/firmware/

IF %ARCH% == aarch64 ( CALL :push_64bit_plugins ) ELSE (
	IF %ARCH% == armv7l ( CALL :push_32bit_plugins) ELSE (
		ECHO Unknown Arch : %ARCH%
		ECHO Failed to install plugins
		EXIT /B -1
	)
)

sdb shell rpm -Uvh --force --nodeps /tmp/patchtmp/wlandrv-plugin-tizen*.rpm
sdb shell rm -rf /tmp/patchtmp

ECHO ----- Sync and reboot -----
sdb shell sync
sdb shell reboot

EXIT /B 0

:push_64bit_plugins
ECHO ----- push 64bit plugins -----
sdb push ./64bit/connectivity/wlandrv-plugin-tizen*.rpm /tmp/patchtmp
EXIT /B 0

:push_32bit_plugins
ECHO ----- push 32bit plugins -----
FOR /F %%g IN ('sdb shell rpm -q --queryformat="%{ARCH}" glibc') do SET ARCH_NAME=%%g
ECHO %ARCH_NAME%

IF %ARCH_NAME% == armv7hl ( 
	sdb push ./32bit/connectivity/wlandrv-plugin-tizen*.armv7hl.rpm /tmp/patchtmp 
) ELSE ( IF %ARCH_NAME% == armv7l (
	sdb push ./32bit/connectivity/wlandrv-plugin-tizen*.armv7l.rpm /tmp/patchtmp
	) ELSE (
		ECHO Unknown Arch : %ARCH_NAME%
		ECHO Failed to install plugins
		EXIT /B -1 
	)
)

EXIT /B 0
