Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 22nd, 2012  |  syntax: None  |  size: 2.54 KB  |  views: 244  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. MTD_PARTS="5 6 8 9"
  4. VOL_NUMS="0 1 2 3"
  5. VOL_NAMES="system data cache efs"
  6. TEMP_MNT="/tmp/mnt"
  7. BACKUP_PATH="/sdcard/samdroid"
  8.  
  9. # Prepare the environment
  10. export LD_LIBRARY_PATH=/tmp/tools
  11. export PATH=/tmp/tools:/bin
  12. if [ ! -e /lib ]; then
  13.         mkdir /lib;
  14. fi
  15.  
  16. if [ -e /lib/ld-uClibc.so.0 ]; then
  17.         rm /lib/ld-uClibc.so.0
  18. fi
  19. ln -s /tmp/tools/ld-uClibc.so.0 /lib/ld-uClibc.so.0
  20.  
  21. # Unmount all UBI volumes
  22. for vol in `cat /proc/mounts | cut -f 1 -d " " | grep ubi`; do
  23.         umount $vol
  24.         if [ $? -ne 0 ]; then
  25.                 echo Failed to unmount $vol, busy?
  26.                 exit 1
  27.         fi
  28.         echo Unmounted $vol.
  29. done
  30.  
  31. # Detach all UBI devices
  32. for dev in `ls -1 /dev/ubi* | grep -v "_" | cut -c 9-`; do
  33.         ubidetach /dev/ubi_ctrl -d $dev
  34.         if [ $? -ne 0 ]; then
  35.                 echo Failed to detach device $dev, check kernel output.
  36.                 exit 1
  37.         fi
  38.         echo Detached UBI device $dev.
  39. done
  40.  
  41. # Make a test mount point
  42. if [ ! -e $TEMP_MNT ]; then
  43.         mkdir $TEMP_MNT
  44. fi
  45. if [ $? -ne 0 ]; then
  46.         echo Failed to create temporary mount point $TEMP_MNT.
  47.         exit 1
  48. fi
  49.  
  50. # Rebuild UBI volumes
  51. for part in $MTD_PARTS; do
  52.         NAME=`echo ${VOL_NAMES} | cut -f 1 -d " "`
  53.         VOL_NAMES=`echo ${VOL_NAMES} | cut -f 2- -d " "`
  54.         NUM=`echo ${VOL_NUMS} | cut -f 1 -d " "`
  55.         VOL_NUMS=`echo ${VOL_NUMS} | cut -f 2- -d " "`
  56.  
  57.         # Erase it
  58.         flash_erase /dev/mtd/mtd$part 0 0
  59.         if [ $? -ne 0 ]; then
  60.                 echo Failed to erase MTD partition $part, check kernel output.
  61.                 exit 1
  62.         fi
  63.         echo Erased MTD partition $part.
  64.  
  65.         # Attach it
  66.         ubiattach /dev/ubi_ctrl -m $part -d $NUM
  67.         if [ $? -ne 0 ]; then
  68.                 echo Failed to attach MTD partition $part on UBI device $NUM, check kernel output.
  69.                 exit 1
  70.         fi
  71.         echo Attached MTD partition $part as UBI device $NUM.
  72.  
  73.         # Make a volume on it
  74.         ubimkvol /dev/ubi$NUM -m -N $NAME
  75.         if [ $? -ne 0 ]; then
  76.                 echo Failed to create UBI volume $NAME on device $NUM, check kernel output.
  77.                 exit 1
  78.         fi
  79.         echo Created UBI volume $NAME on device $NUM.
  80.  
  81.         # Mount
  82.         mount -t ubifs /dev/ubi${NUM}_0 $TEMP_MNT
  83.         if [ $? -ne 0 ]; then
  84.                 echo Failed to mount UBI volume $NAME, check kernel output.
  85.                 exit 1
  86.         fi
  87.         echo Mounted UBI volume $NAME successfully.
  88.  
  89.         # Restore if possible
  90.         if [ -e ${BACKUP_PATH}/${NAME}_restore.tar ]; then
  91.                 tar -xpf ${BACKUP_PATH}/${NAME}_restore.tar -C $TEMP_MNT
  92.                 if [ $? -ne 0 ]; then
  93.                         echo Failed to restore UBI volume $NAME contents from ${BACKUP_PATH}/${NAME}_restore.tar.
  94.                         exit 1
  95.                 fi
  96.                 echo Restored UBI volume $NAME contents from ${BACKUP_PATH}/${NAME}_restore.tar.
  97.         fi
  98.  
  99.         # Sync
  100.         sync
  101.  
  102.         # Unmount
  103.         umount $TEMP_MNT
  104.         echo Unmounted UBI volume $NAME.
  105. done
clone this paste RAW Paste Data