Codebase list debootstick / 3afd352
More robust code: avoid using space as field separator. Etienne Dublé 3 years ago
1 changed file(s) with 28 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
260260 dump_partition_info()
261261 {
262262 disk_device="$1"
263 echo "$PARTITIONS" | tr ';' ' ' | while read part_id subtype mountpoint size
263 echo "$PARTITIONS" | while IFS=";" read part_id subtype mountpoint size
264264 do
265265 device="$(get_part_device $disk_device $part_id)"
266 echo "part $device $subtype $mountpoint $size"
266 echo "part;$device;$subtype;$mountpoint;$size"
267267 done
268268 }
269269
271271 {
272272 if [ "$LVM_VOLUMES" != "" ]
273273 then
274 echo "$LVM_VOLUMES" | tr ';' ' ' | while read label subtype mountpoint size
274 echo "$LVM_VOLUMES" | while IFS=";" read label subtype mountpoint size
275275 do
276 echo "lvm /dev/$VG/$label $subtype $mountpoint $size"
276 echo "lvm;/dev/$VG/$label;$subtype;$mountpoint;$size"
277277 done
278278 fi
279279 }
286286
287287 lvm_partition_size_mb()
288288 {
289 dump_partition_info "$1" | while read vol_type device subtype mountpoint size
289 dump_partition_info "$1" | while IFS=";" read vol_type device subtype mountpoint size
290290 do
291291 if [ "$subtype" = "lvm" ]
292292 then
298298
299299 lvm_sum_size_mb()
300300 {
301 dump_lvm_info | while read vol_type device subtype mountpoint size
301 dump_lvm_info | while IFS=";" read vol_type device subtype mountpoint size
302302 do
303303 device_size_mb "$device"
304304 done | sum_lines
323323 nice_factor="$1"
324324 disk_size_mb="$2"
325325
326 while read voltype device subtype mountpoint size
326 while IFS=";" read voltype device subtype mountpoint size
327327 do
328328 current_size_mb=$(device_size_mb $device)
329329 case "$size" in
333333 size_mb=$((percent_requested*nice_factor*disk_size_mb/NICE_FACTOR_SCALE/100))
334334 if [ $current_size_mb -ge $size_mb ]
335335 then # percentage too low regarding current size, convert to 'auto'
336 echo $voltype auto $device $subtype $mountpoint $current_size_mb
336 echo "$voltype;auto;$device;$subtype;$mountpoint;$current_size_mb"
337337 else # convert to fixed size, to ease later processing
338 echo $voltype fixed $device $subtype $mountpoint $size_mb
338 echo "$voltype;fixed;$device;$subtype;$mountpoint;$size_mb"
339339 fi
340340 ;;
341341 *[MG])
344344 size_mb=$((size_requested_mb*nice_factor/NICE_FACTOR_SCALE))
345345 if [ $size_mb -le $current_size_mb ]
346346 then # fixed size too low regarding current size (because of nice factor), convert to 'auto'
347 echo $voltype auto $device $subtype $mountpoint $current_size_mb
347 echo "$voltype;auto;$device;$subtype;$mountpoint;$current_size_mb"
348348 else
349 echo $voltype fixed $device $subtype $mountpoint $size_mb
349 echo "$voltype;fixed;$device;$subtype;$mountpoint;$size_mb"
350350 fi
351351 ;;
352352 max)
353 echo $voltype max $device $subtype $mountpoint $current_size_mb
353 echo "$voltype;max;$device;$subtype;$mountpoint;$current_size_mb"
354354 ;;
355355 auto)
356 echo $voltype auto $device $subtype $mountpoint $current_size_mb
356 echo "$voltype;auto;$device;$subtype;$mountpoint;$current_size_mb"
357357 ;;
358358 *)
359359 echo "unknown size! '$size'" >&2
361361 ;;
362362 esac
363363 done
364 }
365
366 last_field()
367 {
368 awk 'BEGIN {FS = ";"}; {print $NF}'
364369 }
365370
366371 compute_applied_sizes()
377382 do
378383 volume_analysis_step1="$(echo "$volumes_info" | analysis_step1 $nice_factor $disk_size_mb)"
379384
380 static_size_mb=$(echo "$volume_analysis_step1" | grep -v " fixed " | awk '{print $NF}' | sum_lines)
385 static_size_mb=$(echo "$volume_analysis_step1" | grep -v ";fixed;" | last_field | sum_lines)
381386 space_size_mb=$((total_size_mb-static_size_mb))
382 sum_fixed_mb=$(echo "$volume_analysis_step1" | grep " fixed " | awk '{print $NF}' | sum_lines)
387 sum_fixed_mb=$(echo "$volume_analysis_step1" | grep ";fixed;" | last_field | sum_lines)
383388
384389 if [ $sum_fixed_mb -gt $space_size_mb ]
385390 then
407412 fi
408413 done
409414
410 echo "$volume_analysis_step1" | while read voltype sizetype args
411 do
412 set -- $args
415 echo "$volume_analysis_step1" | \
416 while IFS=";" read voltype sizetype device subtype mountpoint current_size_mb
417 do
413418 case $sizetype in
414419 "fixed")
415 echo $voltype $1 $2 $3 $4
420 echo "$voltype;$device;$subtype;$mountpoint;$current_size_mb"
416421 ;;
417422 "auto")
418 echo $voltype $1 $2 $3 keep
423 echo "$voltype;$device;$subtype;$mountpoint;keep"
419424 ;;
420425 "max")
421 echo $voltype $1 $2 $3 max
426 echo "$voltype;$device;$subtype;$mountpoint;max"
422427 ;;
423428 esac
424429 done
649654 format_info="$4"
650655
651656 # we process lines with "applied_size=max" last (sort key)
652 echo "$format_info" | sort -k 5,5 | \
653 while read voltype voldevice subtype mountpoint applied_size
657 echo "$format_info" | sort -t ";" -k 5,5 | \
658 while IFS=";" read voltype voldevice subtype mountpoint applied_size
654659 do
655660 dev_name=$(device_name $voltype $voldevice)
656661 origin_voldevice=$(get_origin_voldevice $voldevice $voltype $origin_device)