1#!/bin/sh
2# $1: mounted path.
3
4
5APPS_INSTALL_FOLDER=`nvram get apps_install_folder`
6APPS_INSTALL_PATH=$1/$APPS_INSTALL_FOLDER
7check_dir="$1/asusware"
8check_file="$1/asusware/lib/ipkg/info/ipkg-opt.control"
9f=`nvram get apps_install_folder`
10case $f in
11	"asusware.arm")
12		pkg_type=`echo $f|sed -e "s,asusware\.,,"`
13		# fall through
14		;;
15	"asusware.big")
16		pkg_type="mipsbig"
17		if [ -d "$APPS_INSTALL_PATH" ]; then
18			echo "Already have the correct installed APP folder."
19			exit 0
20		fi
21		;;
22	"asusware.mipsbig")
23		pkg_type=`echo $f|sed -e "s,asusware\.,,"`
24		if [ -d "$APPS_INSTALL_PATH" ]; then
25			echo "Already have the correct installed APP folder."
26			exit 0
27		fi
28		;;
29	"asusware")
30		pkg_type="mipsel"
31		;;
32	*)
33		echo "Unknown apps_install_folder: $f"
34		exit 1
35		;;
36esac
37
38
39if [ -z "$1" ]; then
40	echo "Usage: app_check_folder.sh <mounted path>"
41	exit 1
42fi
43
44if [ ! -d "$check_dir" ]; then
45	echo "No conflict APP folder."
46	exit 0
47elif [ ! -f "$check_file" ]; then
48	echo "No conflict ipkg-opt.control."
49	exit 0
50fi
51
52field_gone=`grep "Architecture: " $check_file`
53if [ -z "$field_gone" ]; then
54	echo "No Architecture field in the $check_file."
55	exit 1
56fi
57
58field_value=`grep "Architecture: " $check_file |awk '{print $2}'`
59if [ "$field_value" == "mipsel" ]; then
60	echo "exist the correct MIPS APP folder."
61	exit 0
62fi
63
64echo "field_value=$field_value, platform=$pkg_type."
65mv $check_dir $APPS_INSTALL_PATH
66
67