1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/makesd-partition-summary Fri May 24 20:24:34 2019 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +#!/bin/sh
1.5 +
1.6 +# Emit a partition summary for a device employing parameters such as the start,
1.7 +# size, and type.
1.8 +
1.9 +PROGNAME=`basename "$0"`
1.10 +THISDIR=`dirname "$0"`
1.11 +
1.12 +
1.13 +
1.14 +# Emit any partition details as a complete record.
1.15 +
1.16 +emit_partition()
1.17 +{
1.18 + echo "${START:--}\t${SIZE:--}\t${TYPE:--}"
1.19 +}
1.20 +
1.21 +# Reset the current partition details.
1.22 +
1.23 +reset_partition()
1.24 +{
1.25 + START=
1.26 + SIZE=
1.27 + TYPE=
1.28 +}
1.29 +
1.30 +# Emit the current partition details and proceed to the next partition.
1.31 +
1.32 +next_partition()
1.33 +{
1.34 + if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then
1.35 + emit_partition
1.36 + reset_partition
1.37 + fi
1.38 +}
1.39 +
1.40 +
1.41 +
1.42 +# Emit the help message if requested.
1.43 +
1.44 +if [ "$1" = '--help' ] ; then
1.45 + cat 1>&2 <<EOF
1.46 +Usage: $PROGNAME ( -f <type> | -p <start> | -s <size> )...
1.47 +
1.48 +Produce partition descriptions, indicating partition type, start position and
1.49 +size for each partition. Each new occurrence of an active option starts a new
1.50 +partition description.
1.51 +
1.52 +Each line of the produced description is tab-separated with '-' indicating an
1.53 +empty field.
1.54 +EOF
1.55 + exit 0
1.56 +fi
1.57 +
1.58 +# Process the arguments, building a partition description.
1.59 +
1.60 +reset_partition
1.61 +
1.62 +while [ "$1" ] ; do
1.63 + case "$1" in
1.64 + -f )
1.65 + if [ "$TYPE" ] ; then next_partition ; fi
1.66 + TYPE="$2"
1.67 + shift 2
1.68 + ;;
1.69 + -p )
1.70 + if [ "$START" ] ; then next_partition ; fi
1.71 + START="$2"
1.72 + shift 2
1.73 + ;;
1.74 + -s )
1.75 + if [ "$SIZE" ] ; then next_partition ; fi
1.76 + SIZE="$2"
1.77 + shift 2
1.78 + ;;
1.79 + * )
1.80 + shift 1
1.81 + ;;
1.82 + esac
1.83 +done
1.84 +
1.85 +# Terminate any unfinished partition.
1.86 +
1.87 +next_partition