home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / lib / partman / check.d / 03partition_too_small next >
Encoding:
Text File  |  2009-03-10  |  2.3 KB  |  97 lines

  1. #! /bin/sh
  2. # Check that the root filesystem is large enough to hold /rofs.
  3. . /lib/partman/lib/base.sh
  4.  
  5. # Fudge factors
  6. rootfudge=200000000 # 200MB
  7. bootmultfudge=3
  8.  
  9. partitions=
  10. rofssum=0
  11. rootrofssize=
  12. rootsize=
  13.  
  14. parts=$(
  15. for dev in $DEVICES/*; do
  16.     [ -d "$dev" ] || continue
  17.     cd $dev
  18.     open_dialog PARTITIONS
  19.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  20.     [ "$fs" != free ] || continue
  21.     [ -f "$id/method" ] || continue
  22.     [ -f "$id/acting_filesystem" ] || continue
  23.         [ -f "$id/mountpoint" ] || continue
  24.         mountpoint="$(cat "$id/mountpoint")"
  25.     echo "$mountpoint,$size"
  26.     done
  27.     close_dialog
  28. done | sort
  29. )
  30.  
  31. seen=
  32. for part in $parts; do
  33.     mountpoint="${part%,*}"
  34.     size="${part#*,}"
  35.     if [ "$mountpoint" = "/" ]; then
  36.         rofssize="$(du -s --block-size=1 /rofs | cut -f1)"
  37.         rootrofssize="$rofssize"
  38.         rootsize="$size"
  39.     else
  40.         [ -d "/rofs$mountpoint" ] || continue
  41.         rofssize="$(du -s --block-size=1 /rofs$mountpoint | cut -f1)"
  42.         if [ "$mountpoint" = "/boot" ]; then
  43.             rofssize="$(expr $rofssize \* $bootmultfudge)"
  44.         else
  45.             # general fudge factor: add 20% for luck
  46.             rofssize="$(expr $rofssize \* 12 / 10)"
  47.         fi
  48.         if ! longint_le $rofssize $size ; then
  49.             partitions="${partitions:+$partitions, }$mountpoint $rofssize"
  50.         fi
  51.  
  52.         # Make sure that no parent of $mountpoint has been added to
  53.         # $rofssum yet, otherwise we'll produce an invalid size.
  54.         d="$(dirname $mountpoint)"
  55.         found=
  56.         if [ -n "$seen" ]; then
  57.             while :; do
  58.                 if [ "$d" = / ]; then
  59.                     break
  60.                 fi
  61.                 if echo "$seen" | grep -wqs "$d"; then
  62.                     found=1
  63.                     break
  64.                 fi
  65.                 d="$(dirname $d)"
  66.             done
  67.         fi
  68.         if [ -z "$found" ]; then
  69.             rofssum="$(expr $rofssum + $rofssize)"
  70.             seen="$seen $mountpoint"
  71.         fi
  72.     fi
  73. done
  74.  
  75. if [ -n "$rootrofssize" ]; then
  76.     rofs=$(expr $rootrofssize - $rofssum + $rootfudge)
  77.     if ! longint_le $rofs $rootsize ; then
  78.         partitions="/ $rofs${partitions:+, $partitions}"
  79.     fi
  80. fi
  81.  
  82. if [ -n "$partitions" ]; then
  83.     partitions="$(echo "$partitions" | sed -e 's/, /\n/g')"
  84.     db_capb escape
  85.     db_reset ubiquity/partition-too-small
  86.     db_subst ubiquity/partition-too-small PARTITIONS "$(printf %s "$partitions" | debconf-escape -e)"
  87.     db_capb
  88.     db_input critical ubiquity/partition-too-small || true
  89.     db_go || true
  90.     db_get ubiquity/partition-too-small
  91.     if [ "$RET" = true ]; then
  92.         exit 1
  93.     fi
  94. fi
  95.  
  96. exit 0
  97.