Advertisement
Guest User

loadpreinstalls.sh

a guest
Jun 27th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.74 KB | None | 0 0
  1. #!/system/bin/sh
  2. export PATH=/system/bin:$PATH
  3. PRELOAD_APP_DIR=/system/preinstall/app
  4. PRELOAD_HASH_DIR=/system/preinstall/md5
  5. DATA_HASH_DIR=/data/preinstall_md5
  6. PRELOAD_DONE_PROP=preinstall.done
  7. PRELOAD_LOG_FILE=$DATA_HASH_DIR/log.txt
  8.  
  9. mkdir $DATA_HASH_DIR
  10.  
  11. unzip_needed=1
  12. for file in `ls $PRELOAD_APP_DIR`; do
  13.     if [ $file = "bell_gameloft_resources.zip" ]; then
  14.        if [ -d "/data/gameloft" ]; then
  15.           if [ -f "/data/gameloft/done.txt" ]; then
  16.               unzip_needed=0
  17.           else
  18.               echo "Gameloft resources corrupted. Script will try again"
  19.               echo "Gameloft resources corrupted. Script will try again" >> $PRELOAD_LOG_FILE
  20.               rm -R /data/gameloft
  21.               unzip_needed=1
  22.           fi  
  23.        fi
  24.    
  25.        if [ $unzip_needed -eq 0 ]; then
  26.             echo "Gameloft resources already installed. Exiting"
  27.             echo "Gameloft resources already installed. Exiting" >> $PRELOAD_LOG_FILE
  28.        else
  29.             echo "$file: Found on ${PRELOAD_APP_DIR}/"
  30.             echo "$file: Found on ${PRELOAD_APP_DIR}/" >> $PRELOAD_LOG_FILE
  31.             now=`date`
  32.             echo "Unzipping gameloft resources started: $now"
  33.             echo "Unzipping gameloft resources started: $now" >> $PRELOAD_LOG_FILE
  34.             busybox unzip $PRELOAD_APP_DIR/$file -d /data
  35.             ret=$?
  36.             if [ $ret -ne 0 ]; then
  37.                echo "Install of gameloft apks failed: $ret"
  38.                echo "Install of gameloft apks failed: $ret" >> $PRELOAD_LOG_FILE
  39.             else
  40.                echo "Install of gameloft apks done!"
  41.                echo "Install of gameloft apks done!" >> $PRELOAD_LOG_FILE
  42.                echo "done" > /data/gameloft/done.txt
  43.             fi
  44.             now=`date`
  45.             echo "Unzipping gameloft ended: $now "
  46.             echo "Unzipping gameloft ended: $now " >> $PRELOAD_LOG_FILE
  47.        fi
  48.     else
  49.        echo "$file: comparing $PRELOAD_HASH_DIR/$file.md5 and $DATA_HASH_DIR/$file.md5"
  50.        echo "$file: comparing $PRELOAD_HASH_DIR/$file.md5 and $DATA_HASH_DIR/$file.md5" >> $PRELOAD_LOG_FILE
  51.        newMD5=`cat $PRELOAD_HASH_DIR/$file.md5`
  52.        oldMD5=`cat $DATA_HASH_DIR/$file.md5`
  53.        if [ "$newMD5" != "$oldMD5" ]; then
  54.            isInstalled=`pm path $file`
  55.            # app not installed, but md5 exists = user uninstalled app, do nothing
  56.            if [ -z "$isInstalled" -a -e "$DATA_HASH_DIR/$file.md5" ]; then
  57.                echo "$file: user has uninstalled, dont reinstall. copying $file.md5 to $DATA_HASH_DIR"
  58.                echo "$file: user has uninstalled, dont reinstall. copying $file.md5 to $DATA_HASH_DIR" >> $PRELOAD_LOG_FILE
  59.                cp $PRELOAD_HASH_DIR/$file.md5 $DATA_HASH_DIR
  60.            else
  61.                # app is installed, but md5 changed, uninstall first but keep users data
  62.                if [ -n "$isInstalled" ]; then
  63.                    for count in 1 2 3 4 5
  64.                    do
  65.                        pm uninstall -k $file
  66.                        isInstalled=`pm path $file`
  67.                        if [ -n "$isInstalled" ]; then
  68.                            echo "$file: uninstall attempt $count of 5 failed"
  69.                            echo "$file: uninstall attempt $count of 5 failed" >> $PRELOAD_LOG_FILE
  70.                            sleep 5
  71.                        else
  72.                            echo "$file: uninstall successful, user data kept"
  73.                            echo "$file: uninstall successful, user data kept" >> $PRELOAD_LOG_FILE
  74.                            break
  75.                        fi
  76.                    done
  77.                fi
  78.    
  79.                isInstalled=`pm path $file`
  80.                # app should not be installed at this point, either it never was installed, or it changed
  81.                # and we uninstalled the old version above
  82.                if [ -z "$isInstalled" ]; then
  83.                    for count in 1 2 3 4 5
  84.                    do
  85.                        pm install $PRELOAD_APP_DIR/$file
  86.    
  87.                        isInstalled=`pm path $file`
  88.                        if [ -z "$isInstalled" ]; then
  89.                            echo "$file: install attempt $count of 5 failed"
  90.                            echo "$file: install attempt $count of 5 failed" >> $PRELOAD_LOG_FILE
  91.                            sleep 5
  92.                        else
  93.                            echo "$file: install successful, copying $file.md5 to $DATA_HASH_DIR"
  94.                            echo "$file: install successful, copying $file.md5 to $DATA_HASH_DIR" >> $PRELOAD_LOG_FILE
  95.                            cp $PRELOAD_HASH_DIR/$file.md5 $DATA_HASH_DIR
  96.                            break
  97.                        fi
  98.                    done
  99.                else
  100.                    echo "$file: file still installed when it shouldnt be!"
  101.                    echo "$file: file still installed when it shouldnt be!" >> $PRELOAD_LOG_FILE
  102.                fi
  103.            fi
  104.        else
  105.            echo "$file: install skipped, file unchanged"
  106.            echo "$file: install skipped, file unchanged" >> $PRELOAD_LOG_FILE
  107.        fi
  108.    fi
  109. done
  110.  
  111. retries=10
  112. echo "preinstall finished, setting $PRELOAD_DONE_PROP to 1"
  113. echo "preinstall finished, setting $PRELOAD_DONE_PROP to 1" >> $PRELOAD_LOG_FILE
  114. setprop $PRELOAD_DONE_PROP 1
  115. readback=`getprop $PRELOAD_DONE_PROP`
  116. while [ "$readback" != "1" -a $retries -gt 0 ]
  117. do
  118.     echo "  property readback failed! expected 1, got $readback. retries left $retries..."
  119.     echo "  property readback failed! expected 1, got $readback. retries left $retries..." >> $PRELOAD_LOG_FILE
  120.     retries=$(($retries-1))
  121.     sleep 2
  122.     setprop $PRELOAD_DONE_PROP 1
  123.     readback=`getprop $PRELOAD_DONE_PROP`
  124. done
  125.  
  126. echo "preinstall exiting..."
  127. echo "preinstall exiting..." >> $PRELOAD_LOG_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement