remakesd

makesd-partition-summary

9:63c473a6c9b3
2019-05-25 Paul Boddie Changed the partition tool to accept a partitioning summary.
     1 #!/bin/sh     2      3 # Emit a partition summary for a device employing parameters such as the start,     4 # size, and type.     5      6 PROGNAME=`basename "$0"`     7 THISDIR=`dirname "$0"`     8      9     10     11 # Emit any partition details as a complete record.    12     13 emit_partition()    14 {    15     echo "${START:--}\t${SIZE:--}\t${TYPE:--}"    16 }    17     18 # Reset the current partition details.    19     20 reset_partition()    21 {    22     START=    23     SIZE=    24     TYPE=    25 }    26     27 # Emit the current partition details and proceed to the next partition.    28     29 next_partition()    30 {    31     if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then    32         emit_partition    33         reset_partition    34     fi    35 }    36     37     38     39 # Emit the help message if requested.    40     41 if [ "$1" = '--help' ] ; then    42     cat 1>&2 <<EOF    43 Usage: $PROGNAME ( -f <type> | -p <start> | -s <size> )...    44     45 Produce partition descriptions, indicating partition type, start position and    46 size for each partition. Each new occurrence of an active option starts a new    47 partition description.    48     49 Each line of the produced description is tab-separated with '-' indicating an    50 empty field.    51 EOF    52     exit 0    53 fi    54     55 # Process the arguments, building a partition description.    56     57 reset_partition    58     59 while [ "$1" ] ; do    60     case "$1" in    61         -f )    62             if [ "$TYPE" ] ; then next_partition ; fi    63             TYPE="$2"    64             shift 2    65             ;;    66         -p )    67             if [ "$START" ] ; then next_partition ; fi    68             START="$2"    69             shift 2    70             ;;    71         -s )    72             if [ "$SIZE" ] ; then next_partition ; fi    73             SIZE="$2"    74             shift 2    75             ;;    76         * )    77             shift 1    78             ;;    79     esac    80 done    81     82 # Terminate any unfinished partition.    83     84 next_partition