update-binary 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/sbin/sh
  2. OUTFD="/proc/self/fd/$2"
  3. ZIP=$3
  4. exec_util() {
  5. LD_LIBRARY_PATH=$LD_PATH $UTILS $1
  6. }
  7. set_con() {
  8. exec_util "chcon -h u:object_r:"$1":s0 $2"
  9. exec_util "chcon u:object_r:"$1":s0 $2"
  10. }
  11. set_perm() {
  12. exec_util "chmod $1 $2"
  13. }
  14. set_owner() {
  15. exec_util "chown $1:$2 $3"
  16. }
  17. ui_print() {
  18. echo "ui_print $1" > "$OUTFD";
  19. echo "ui_print" > "$OUTFD";
  20. }
  21. ui_print "**********************"
  22. ui_print "MindTheGapps installer"
  23. ui_print "**********************"
  24. SYSTEMASROOT=`getprop ro.build.system_root_image`
  25. ui_print "Mounting system partition"
  26. # Ensure system is unmounted so mounting succeeds
  27. umount /system || true
  28. if [ "$SYSTEMASROOT" == "true" ]; then
  29. CURRENTSLOT=`getprop ro.boot.slot_suffix`
  30. if [ ! -z "$CURRENTSLOT" ]; then
  31. if [ "$CURRENTSLOT" == "_a" ]; then
  32. TARGETSYSTEM=/dev/block/bootdevice/by-name/system_b
  33. else
  34. TARGETSYSTEM=/dev/block/bootdevice/by-name/system_a
  35. fi
  36. else
  37. TARGETSYSTEM=/dev/block/bootdevice/by-name/system
  38. fi
  39. mkdir -p /system_root
  40. if mount -o rw $TARGETSYSTEM /system_root && mount /system_root/system /system; then
  41. ui_print "/system mounted"
  42. else
  43. ui_print "Could not mount /system! Aborting"
  44. exit 1
  45. fi
  46. else
  47. if mount /system; then
  48. ui_print "/system mounted"
  49. else
  50. ui_print "Could not mount /system! Aborting"
  51. exit 1
  52. fi
  53. fi
  54. if [ -f /system/bin/toybox ]; then
  55. UTILS=/system/bin/toybox
  56. LD_PATH=/system/lib
  57. else
  58. ui_print "Could not find /system/bin/toybox! Aborting"
  59. exit 1
  60. fi
  61. DIRS="addon.d app priv-app framework etc lib"
  62. if [ -d /system/lib64 ]; then
  63. DIRS="$DIRS lib64"
  64. LD_PATH=/system/lib64
  65. fi
  66. LOWMEM=1572864
  67. MEM=`cat /proc/meminfo | head -1 | sed 's/[^0-9]*//g'`
  68. ui_print "Extracting files"
  69. cd /tmp
  70. unzip -o "$ZIP"
  71. exec_util "rm -rf META-INF"
  72. cd system
  73. if [ "$MEM" -lt "$LOWMEM" ]; then
  74. ui_print "Low RAM device detected, removing large extras"
  75. exec_util "rm -rf priv-app/SetupWizard"
  76. exec_util "rm -rf priv-app/Velvet"
  77. fi
  78. ui_print "Generating addon.d file"
  79. cat addon.d/addond_head > addon.d/30-gapps.sh
  80. for f in `exec_util "find . -type f"`; do
  81. line=$(echo "$f" | sed 's/\.\///')
  82. echo "$line" >> addon.d/30-gapps.sh
  83. done
  84. cat addon.d/addond_tail >> addon.d/30-gapps.sh
  85. rm addon.d/addond_head addon.d/addond_tail
  86. ui_print "Preparing files for copying"
  87. for dirs in $DIRS; do
  88. set_perm 0755 $dir
  89. for d in `exec_util "find ./$dir -type d"`; do
  90. set_perm 0755 $d
  91. set_owner root root $d
  92. done
  93. for f in `exec_util "find ./$dir -type f"`; do
  94. type=$(echo "$f" | sed 's/.*\.//')
  95. if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then
  96. set_perm 0755 $f
  97. else
  98. set_perm 0644 $f
  99. fi
  100. set_owner root root $f
  101. set_con system_file $f
  102. done
  103. done
  104. ui_print "Copying files"
  105. exec_util "cp --preserve=a -r ./* /system/"
  106. exec_util "rm -rf /system/priv-app/Provision/"
  107. ui_print "Cleaning up files"
  108. cd ../
  109. exec_util "rm -rf system/"
  110. ui_print "Unmounting system partition"
  111. if umount -l /system; then
  112. if [ "$SYSTEMASROOT" == "true" ]; then
  113. umount -l /system_root
  114. fi
  115. fi
  116. ui_print "Done!"
  117. exit 0