Browse Source

Adapt free space checks to new partitions

And don't count as needed space that will be freed from the replaced
files. This will allow to flash the zip over an existing installation
when space is tight.

Also:
awk      -->  tr | cut  because recovery might not provide awk
grep -v  -->  tail -1   in du because it might spit out 3 lines
Alessandro Astone 4 years ago
parent
commit
2b244a1ead
1 changed files with 60 additions and 17 deletions
  1. 60 17
      build/meta/com/google/android/update-binary

+ 60 - 17
build/meta/com/google/android/update-binary

@@ -32,6 +32,12 @@ cleanup() {
   umount -l /system_ext || true
   umount -l /system_ext || true
 }
 }
 
 
+error_no_space() {
+  ui_print "Not enough space for GApps! Aborting"
+  cleanup
+  exit 1
+}
+
 get_block_for_mount_point() {
 get_block_for_mount_point() {
   grep -v "^#" /etc/recovery.fstab | grep " $1 " | tail -n1 | tr -s ' ' | cut -d' ' -f1
   grep -v "^#" /etc/recovery.fstab | grep " $1 " | tail -n1 | tr -s ' ' | cut -d' ' -f1
 }
 }
@@ -63,6 +69,36 @@ find_block() {
   fi
   fi
 }
 }
 
 
+compute_apps_size() {
+  NEEDED_STORAGE_SYSTEM=$(expr $(du -cs `find -maxdepth 1 -mindepth 1 ! -name product ! -name system_ext` | tail -n1 | cut -f1) + $STORAGE_BUFFER)
+  NEEDED_STORAGE_PRODUCT=$(expr $(du -s ./product | cut -f1) + $STORAGE_BUFFER)
+  NEEDED_STORAGE_SYSTEM_EXT=$(expr $(du -s ./system_ext | cut -f1) + $STORAGE_BUFFER)
+
+  RECLAIMABLE_STORAGE_SYSTEM=$(find . ! -path "./product/*" ! -path "./system_ext/*" -type f | sed "s|^./|$SYSTEM_OUT/|" | xargs ls -d 2>/dev/null | xargs du -cs PLACEHOLDER 2>/dev/null | tail -n1 |  cut -f1)
+  NEEDED_STORAGE_SYSTEM=$(expr $NEEDED_STORAGE_SYSTEM - $RECLAIMABLE_STORAGE_SYSTEM)
+
+  RECLAIMABLE_STORAGE_PRODUCT=$(find ./product -type f | sed "s|^./|$SYSTEM_OUT/|" | xargs ls -d 2>/dev/null | xargs du -cs PLACEHOLDER 2>/dev/null | tail -n1 |  cut -f1)
+  NEEDED_STORAGE_PRODUCT=$(expr $NEEDED_STORAGE_PRODUCT - $RECLAIMABLE_STORAGE_PRODUCT)
+
+  RECLAIMABLE_STORAGE_SYSTEM_EXT=$(find ./system_ext -type f | sed "s|^./|$SYSTEM_OUT/|" | xargs ls -d 2>/dev/null | xargs du -cs PLACEHOLDER 2>/dev/null | tail -n1 |  cut -f1)
+  NEEDED_STORAGE_SYSTEM_EXT=$(expr $NEEDED_STORAGE_SYSTEM_EXT - $RECLAIMABLE_STORAGE_SYSTEM_EXT)
+
+  if [ -z "$PRODUCT_BLOCK" ]; then
+    NEEDED_STORAGE_SYSTEM=$(expr $NEEDED_STORAGE_SYSTEM + $NEEDED_STORAGE_PRODUCT - $STORAGE_BUFFER)
+  fi
+  if [ -z "$SYSTEM_EXT_BLOCK" ]; then
+    NEEDED_STORAGE_SYSTEM=$(expr $NEEDED_STORAGE_SYSTEM + $NEEDED_STORAGE_SYSTEM_EXT - $STORAGE_BUFFER)
+  fi
+}
+
+remove_big_optional_apps() {
+  ui_print "Low resource device detected, removing large extras"
+  rm -rf product/app/MarkupGoogle
+  rm -rf product/priv-app/AndroidMigratePrebuilt
+  rm -rf product/priv-app/SetupWizardPrebuilt
+  rm -rf product/priv-app/Velvet
+}
+
 ui_print "**********************"
 ui_print "**********************"
 ui_print "MindTheGapps installer"
 ui_print "MindTheGapps installer"
 ui_print "**********************"
 ui_print "**********************"
@@ -136,9 +172,14 @@ if [ -n "$SYSTEM_EXT_BLOCK" ]; then
   fi
   fi
 fi
 fi
 
 
-LOWMEM=1572864
-MEM=`grep MemTotal /proc/meminfo | awk '{ print $2 }'`
-STORAGE=`df $SYSTEM_MNT | grep -v Filesystem | awk '{ print $4 }'`
+# Compute storage requirements
+SYSTEM_STORAGE=`df $SYSTEM_MNT | tail -1 | tr -s ' ' | cut -d ' ' -f4`
+if [ -n "$PRODUCT_BLOCK" ]; then
+  PRODUCT_STORAGE=`df /product | tail -1 | tr -s ' ' | cut -d ' ' -f4`
+fi
+if [ -n "$SYSTEM_EXT_BLOCK" ]; then
+  SYSTEM_EXT_STORAGE=`df /system_ext | tail -1 | tr -s ' ' | cut -d ' ' -f4`
+fi
 STORAGE_BUFFER=10240
 STORAGE_BUFFER=10240
 
 
 ui_print "Extracting files"
 ui_print "Extracting files"
@@ -146,23 +187,25 @@ cd /tmp
 unzip -o "$ZIP"
 unzip -o "$ZIP"
 rm -rf META-INF
 rm -rf META-INF
 cd system
 cd system
+compute_apps_size
 
 
-NEEDED_STORAGE=`expr $(du -s . | awk '{ print $1 }') + $STORAGE_BUFFER`
-
-if [ "$MEM" -lt "$LOWMEM" ] || [ "$STORAGE" -lt "$NEEDED_STORAGE" ]; then
-  ui_print "Low resource device detected, removing large extras"
-  rm -rf product/app/MarkupGoogle
-  rm -rf product/priv-app/AndroidMigratePrebuilt
-  rm -rf product/priv-app/SetupWizardPrebuilt
-  rm -rf product/priv-app/Velvet
-  NEEDED_STORAGE=`expr $(du -s . | awk '{ print $1 }') + $STORAGE_BUFFER`
-  if [ "$STORAGE" -lt "$NEEDED_STORAGE" ]; then
-    ui_print "Not enough space for GApps! Aborting"
-    cd ..
-    rm -rf system
-    exit 1
+if [ "$SYSTEM_STORAGE" -lt "$NEEDED_STORAGE_SYSTEM" ]; then
+  remove_big_optional_apps
+  compute_apps_size
+  if [ "$SYSTEM_STORAGE" -lt "$NEEDED_STORAGE_SYSTEM" ]; then
+    error_no_space
   fi
   fi
 fi
 fi
+if [ -n "$PRODUCT_BLOCK" ] && [ "$PRODUCT_STORAGE" -lt "$NEEDED_STORAGE_PRODUCT" ]; then
+  remove_big_optional_apps
+  compute_apps_size
+  if [ "$PRODUCT_STORAGE" -lt "$NEEDED_STORAGE_PRODUCT" ]; then
+    error_no_space
+  fi
+fi
+if [ -n "$SYSTEM_EXT_BLOCK" ] && [ "$SYSTEM_EXT_STORAGE" -lt "$NEEDED_STORAGE_SYSTEM_EXT" ]; then
+  error_no_space
+fi
 
 
 ui_print "Generating addon.d file"
 ui_print "Generating addon.d file"
 cat addon.d/addond_head > addon.d/30-gapps.sh
 cat addon.d/addond_head > addon.d/30-gapps.sh