1#!/bin/sh 2# $1: device name. 3 4 5APPS_INSTALL_FOLDER=`nvram get apps_install_folder` 6APPS_DEV=`nvram get apps_dev` 7APPS_MOUNTED_PATH=`nvram get apps_mounted_path` 8APPS_PATH=/opt 9 10 11if [ -z "$APPS_DEV" ]; then 12 echo "Wrong" 13 APPS_DEV=$1 14fi 15 16if [ -z "$APPS_DEV" ] || [ ! -b "/dev/$APPS_DEV" ];then 17 echo "Usage: app_move_to_pool.sh <device name>" 18 nvram set apps_state_error=1 19 exit 1 20fi 21 22APPS_MOUNTED_PATH=`mount |grep "/dev/$APPS_DEV on " |awk '{print $3}'` 23if [ -z "$APPS_MOUNTED_PATH" ]; then 24 echo "$1 had not mounted yet!" 25 nvram set apps_state_error=2 26 exit 1 27fi 28 29APPS_INSTALL_PATH=$APPS_MOUNTED_PATH/$APPS_INSTALL_FOLDER 30if [ ! -d "$APPS_INSTALL_PATH" ]; then 31 echo "No the base directory!" 32 nvram set apps_state_error=4 33 exit 1 34fi 35 36APPS_MOUNTED_TYPE=`mount |grep "/dev/$APPS_DEV on " |awk '{print $5}'` 37if [ -z "$APPS_MOUNTED_TYPE" ]; then 38 echo "$1 had not mounted yet!" 39 nvram set apps_state_error=2 40 exit 1 41fi 42 43objs=`ls -a $APPS_PATH/` 44for obj in $objs; do 45 if [ "$obj" == "." ] || [ "$obj" == ".." ]; then 46 continue 47 fi 48 49 target=`echo $obj |awk '{FS="-"; printf $1}'` 50 if [ "$target" == "ipkg" ]; then 51 continue 52 fi 53 54 if [ "$obj" != "bin" ] && [ "$obj" != "lib" ] && [ ! -e "$APPS_INSTALL_PATH/$obj" ]; then 55 if [ "$APPS_MOUNTED_TYPE" != "vfat" ] && [ "$APPS_MOUNTED_TYPE" != "tfat" ]; then 56 cp -rf $APPS_PATH/$obj $APPS_INSTALL_PATH 57 if [ "$?" != "0" ]; then 58 nvram set apps_state_error=10 59 exit 1 60 fi 61 elif [ ! -L "$APPS_PATH/$obj" ]; then 62 cp -rf $APPS_PATH/$obj $APPS_INSTALL_PATH 63 if [ "$?" != "0" ]; then 64 nvram set apps_state_error=10 65 exit 1 66 fi 67 fi 68 fi 69done 70 71objs=`ls -a $APPS_PATH/bin/` 72for obj in $objs; do 73 if [ "$obj" == "." ] || [ "$obj" == ".." ]; then 74 continue 75 fi 76 77 if [ ! -e "$APPS_INSTALL_PATH/bin/$obj" ]; then 78 if [ "$APPS_MOUNTED_TYPE" != "vfat" ] && [ "$APPS_MOUNTED_TYPE" != "tfat" ]; then 79 cp -rf $APPS_PATH/bin/$obj $APPS_INSTALL_PATH/bin 80 if [ "$?" != "0" ]; then 81 nvram set apps_state_error=10 82 exit 1 83 fi 84 elif [ ! -L "$APPS_PATH/bin/$obj" ]; then 85 cp -rf $APPS_PATH/bin/$obj $APPS_INSTALL_PATH/bin 86 if [ "$?" != "0" ]; then 87 nvram set apps_state_error=10 88 exit 1 89 fi 90 fi 91 fi 92done 93 94objs=`ls -a $APPS_PATH/lib/` 95for obj in $objs; do 96 if [ "$obj" == "." ] || [ "$obj" == ".." ]; then 97 continue 98 fi 99 100 if [ ! -e "$APPS_INSTALL_PATH/lib/$obj" ]; then 101 if [ "$APPS_MOUNTED_TYPE" != "vfat" ] && [ "$APPS_MOUNTED_TYPE" != "tfat" ]; then 102 cp -rf $APPS_PATH/lib/$obj $APPS_INSTALL_PATH/lib 103 if [ "$?" != "0" ]; then 104 nvram set apps_state_error=10 105 exit 1 106 fi 107 elif [ ! -L "$APPS_PATH/lib/$obj" ]; then 108 cp -rf $APPS_PATH/lib/$obj $APPS_INSTALL_PATH/lib 109 if [ "$?" != "0" ]; then 110 nvram set apps_state_error=10 111 exit 1 112 fi 113 fi 114 fi 115done 116