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