SHARE
TWEET

Sparse back system.img

a guest Apr 19th, 2016 253 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Script originally from : https://github.com/baohaojun/system-config/blob/9493e1d78cd5bf7fbfc9a9bf16880c18f1bb2471/bin/sparse-unsparse.xml
  3. set -e
  4. if test $# = 0; then
  5.     set -- -p system -o ~/tmp/system.img.$$
  6.     echo "$@"
  7. fi
  8.  
  9. ## start code-generator "^\\s *#\\s *"
  10. # generate-getopt p:part o:out x:xml
  11. ## end code-generator
  12. ## start generated code
  13. TEMP=$(getopt -o p:o:x: --long "part:,out:,xml:"  -n $(basename $0) -- "$@")
  14. part=
  15. out=
  16. xml=
  17. eval set -- "$TEMP"
  18. while true; do
  19.     case "$1" in
  20.         -p|--part)
  21.             part=$2
  22.             shift 2
  23.             ;;
  24.         -o|--out)
  25.             out=$2
  26.             shift 2
  27.             ;;
  28.         -x|--xml)
  29.             xml=$2
  30.             shift 2
  31.             ;;
  32.         --)
  33.             shift
  34.             break
  35.             ;;
  36.         *)
  37.             die "internal error"
  38.             ;;
  39.     esac
  40. done
  41.  
  42. ## end generated code
  43.  
  44. if test -z "$part"; then
  45.     part=system
  46. fi
  47.  
  48. if test -z "$xml"; then
  49.     xml=rawprogram_unsparse.xml
  50. fi
  51.  
  52. if test -z "$out"; then
  53.     out=~${part}.img
  54. fi
  55.  
  56. function die() {
  57.     echo Error: "$@"
  58.     exit -1
  59. }
  60.  
  61. if test ! "$part"; then
  62.     die "part not set, should use -p to set system/userdata/cache etc"
  63. fi
  64. if test -d sparse_images -a ! -e userdata_1.img; then
  65.     cd sparse_images
  66. fi
  67. xmlstarlet sel -t -m //program -v @filename -o " " -v @start_sector -n $xml | grep ${part} |
  68. {
  69.     while read img start; do
  70.         if test $img = ${part}_1.img; then
  71.             the_start=$start
  72.         fi
  73.         start=$((start - the_start)) || true
  74.         dd if=$img of=${out} seek=$start
  75.     done
  76.     size="$(stat -c %s ${out})"
  77.     dd if=/dev/zero of=${out} seek=$(((1000000+size)/512)) count=1
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top