
push_64bit_plugins() {
	echo "\n\n----- push 64bit plugins -----\n"
	sdb push ./64bit/connectivity/wlandrv-plugin-tizen*.rpm /tmp/patchtmp
}

push_32bit_plugins() {
	local arch_name=`sdb shell rpm -q --queryformat="%{ARCH}" glibc`

	echo "\n\n----- push $arch_name plugins -----\n"

	if [ "$arch_name" = "armv7hl" ]; then
		sdb push ./32bit/connectivity/wlandrv-plugin-tizen*.armv7hl.rpm /tmp/patchtmp
	elif [ "$arch_name" = "armv7l" ]; then
		sdb push ./32bit/connectivity/wlandrv-plugin-tizen*.armv7l.rpm /tmp/patchtmp
	else
		echo "Unknown Arch : $arch_name"
		echo "Failed to install plugins \n\n"
		exit 1
	fi
}


############ Start Here
#set -x

sdb root on

#create repository for patch files
sdb shell mkdir -p /tmp/patchtmp
sdb shell mount -o remount,rw /
sleep 1
sdb shell mount -o remount,rw /hal

arch_ver=`sdb shell "uname -m"`
arch_ver="$(echo "${arch_ver}" | sed -e 's/[[:space:]]*$//')"
echo "arch : ${arch_ver}"

sdb shell rpm -e --nodeps wlandrv-plugin-tizen

echo "\n\n---- Install drvier (sdb push) ----"

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

if [ "$arch_ver" = "aarch64" ]; then
	push_64bit_plugins
elif [ "$arch_ver" = "armv7l" ]; then
	push_32bit_plugins
else
	echo "Unknown Arch : $arch_ver"
	echo "Failed to install plugins \n\n"
	exit 1
fi

echo "\n\n----- install plugins -----\n"
sdb shell rpm -Uvh --force --nodeps /tmp/patchtmp/wlandrv-plugin-tizen*.rpm
sdb shell rm -rf /tmp/patchtmp

echo "\n\n----- Sync & Reboot -----\n"
sdb shell sync
sdb shell reboot
