update-binary 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if [ "$SYSTEMASROOT" == "true" ]; then
  27. CURRENTSLOT=`getprop ro.boot.slot_suffix`
  28. if [ ! -z "$CURRENTSLOT" ]; then
  29. if [ "$CURRENTSLOT" == "_a" ]; then
  30. TARGETSYSTEM=/dev/block/bootdevice/by-name/system_b
  31. else
  32. TARGETSYSTEM=/dev/block/bootdevice/by-name/system_a
  33. fi
  34. else
  35. TARGETSYSTEM=/dev/block/bootdevice/by-name/system
  36. fi
  37. mkdir -p /system_root
  38. if mount -o rw $TARGETSYSTEM /system_root && mount /system_root/system /system; then
  39. ui_print "/system mounted"
  40. else
  41. ui_print "Could not mount /system! Aborting"
  42. exit 1
  43. fi
  44. else
  45. if mount /system; then
  46. ui_print "/system mounted"
  47. else
  48. ui_print "Could not mount /system! Aborting"
  49. exit 1
  50. fi
  51. fi
  52. if [ -f /system/bin/toybox ]; then
  53. UTILS=/system/bin/toybox
  54. LD_PATH=/system/lib
  55. else
  56. ui_print "Could not find /system/bin/toybox! Aborting"
  57. exit 1
  58. fi
  59. DIRS="addon.d app priv-app framework etc lib"
  60. if [ -d /system/lib64 ]; then
  61. DIRS="$DIRS lib64"
  62. LD_PATH=/system/lib64
  63. fi
  64. LOWMEM=1572864
  65. MEM=`cat /proc/meminfo | head -1 | sed 's/[^0-9]*//g'`
  66. ui_print "Extracting files"
  67. cd /tmp
  68. unzip -o "$ZIP"
  69. exec_util "rm -rf META-INF"
  70. cd system
  71. if [ "$MEM" -lt "$LOWMEM" ]; then
  72. ui_print "Low RAM device detected, removing large extras"
  73. exec_util "rm -rf priv-app/SetupWizard"
  74. exec_util "rm -rf priv-app/Velvet"
  75. fi
  76. ui_print "Generating addon.d file"
  77. cat addon.d/addond_head > addon.d/30-gapps.sh
  78. for f in `exec_util "find . -type f"`; do
  79. line=$(echo "$f" | sed 's/\.\///')
  80. echo "$line" >> addon.d/30-gapps.sh
  81. done
  82. cat addon.d/addond_tail >> addon.d/30-gapps.sh
  83. ui_print "Preparing files for copying"
  84. for dirs in $DIRS; do
  85. set_perm 0755 $dir
  86. for d in `exec_util "find ./$dir -type d"`; do
  87. set_perm 0755 $d
  88. set_owner root root $d
  89. done
  90. for f in `exec_util "find ./$dir -type f"`; do
  91. type=$(echo "$f" | sed 's/.*\.//')
  92. if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then
  93. set_perm 0755 $f
  94. else
  95. set_perm 0644 $f
  96. fi
  97. set_owner root root $f
  98. set_con system_file $f
  99. done
  100. done
  101. ui_print "Copying files"
  102. exec_util "cp --preserve=a -r ./* /system/"
  103. exec_util "rm -rf /system/priv-app/Provision/"
  104. ui_print "Cleaning up files"
  105. cd ../
  106. exec_util "rm -rf system/"
  107. ui_print "Unmounting system partition"
  108. if umount /system; then
  109. if [ "$SYSTEMASROOT" == "true" ]; then
  110. umount /system_root
  111. fi
  112. fi
  113. ui_print "Done!"
  114. exit 0