update-binary 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. ABDEVICE=`getprop ro.build.system_root_image`
  25. ui_print "Mounting system partition"
  26. if [ "$ABDEVICE" == "true" ]; then
  27. SYSTEM="/system/system"
  28. # TODO: Actually handle A/B ota devices
  29. ui_print "A/B OTA device detected! This is unsupported. Aborting"
  30. exit 1
  31. else
  32. SYSTEM="/system"
  33. if mount $SYSTEM; then
  34. ui_print "$SYSTEM mounted"
  35. else
  36. ui_print "Could not mount $SYSTEM! Aborting"
  37. exit 1
  38. fi
  39. fi
  40. if [ -f $SYSTEM/bin/toybox ]; then
  41. UTILS=$SYSTEM/bin/toybox
  42. LD_PATH=$SYSTEM/lib
  43. else
  44. ui_print "Could not find $SYSTEM/bin/toybox! Aborting"
  45. exit 1
  46. fi
  47. DIRS="addon.d app priv-app framework etc lib"
  48. if [ -d $SYSTEM/lib64 ]; then
  49. DIRS="$DIRS lib64"
  50. LD_PATH=$SYSTEM/lib64
  51. fi
  52. LOWMEM=1572864
  53. MEM=`cat /proc/meminfo | head -1 | sed 's/[^0-9]*//g'`
  54. ui_print "Extracting files"
  55. cd /tmp
  56. unzip -o "$ZIP"
  57. exec_util "rm -rf META-INF"
  58. cd system
  59. #if [ "$MEM" -lt "$LOWMEM" ]; then
  60. # ui_print "Low RAM device detected, removing Google SuW"
  61. exec_util "rm -rf priv-app/SetupWizard"
  62. #fi
  63. ui_print "Generating addon.d file"
  64. cat addon.d/addond_head > addon.d/30-gapps.sh
  65. for f in `exec_util "find . -type f"`; do
  66. line=$(echo "$f" | sed 's/\.\///')
  67. echo "$line" >> addon.d/30-gapps.sh
  68. done
  69. cat addon.d/addond_tail >> addon.d/30-gapps.sh
  70. ui_print "Preparing files for copying"
  71. for dirs in $DIRS; do
  72. set_perm 0755 $dir
  73. for d in `exec_util "find ./$dir -type d"`; do
  74. set_perm 0755 $d
  75. set_owner root root $d
  76. done
  77. for f in `exec_util "find ./$dir -type f"`; do
  78. type=$(echo "$f" | sed 's/.*\.//')
  79. if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then
  80. set_perm 0755 $f
  81. else
  82. set_perm 0644 $f
  83. fi
  84. set_owner root root $f
  85. set_con system_file $f
  86. done
  87. done
  88. ui_print "Copying files"
  89. exec_util "cp --preserve=a -r ./* $SYSTEM/"
  90. ui_print "Cleaning up files"
  91. cd ../
  92. exec_util "rm -rf system/"
  93. ui_print "Unmounting system partition"
  94. umount $SYSTEM
  95. ui_print "Done!"
  96. exit 0