1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/makesd-partition Fri May 24 23:17:38 2019 +0200
1.3 @@ -0,0 +1,79 @@
1.4 +#!/bin/sh
1.5 +
1.6 +# Support partitioning of a device using sfdisk.
1.7 +#
1.8 +# Important tasks:
1.9 +#
1.10 +# Erase bootloader blocks.
1.11 +# Perform partitioning using sfdisk.
1.12 +
1.13 +PROGNAME=`basename "$0"`
1.14 +THISDIR=`dirname "$0"`
1.15 +
1.16 +EXPAND="$THISDIR/makesd-expand-def"
1.17 +PARTSUMMARY="$THISDIR/makesd-partition-summary"
1.18 +PARTTABLE="$THISDIR/makesd-partition-table"
1.19 +SFDISK="/sbin/sfdisk"
1.20 +
1.21 +
1.22 +
1.23 +# Test sfdisk behaviour and obtain useful information.
1.24 +
1.25 +init_sfdisk()
1.26 +{
1.27 + if "$SFDISK" -uS -s "$1" > /dev/null 2>&1 ; then
1.28 + SFDISK_OPTIONS="-uS -L"
1.29 + else
1.30 + SFDISK_OPTIONS=
1.31 + fi
1.32 +}
1.33 +
1.34 +
1.35 +
1.36 +# Obtain details of the selected device.
1.37 +
1.38 +if [ ! "$DEV" ] ; then
1.39 + cat 1>&2 <<EOF
1.40 +No device specified. Use the DEV environment variable to indicate a device.
1.41 +EOF
1.42 + exit 1
1.43 +fi
1.44 +
1.45 +if [ ! -e "$DEV" ] ; then
1.46 + cat 1>&2 <<EOF
1.47 +Device not found: $DEV
1.48 +EOF
1.49 + exit 1
1.50 +fi
1.51 +
1.52 +# Test for the cylinder alignment option.
1.53 +
1.54 +if [ "$1" = '--align' ] ; then
1.55 + ALIGN_CYLINDER="$1"
1.56 + shift 1
1.57 +else
1.58 + ALIGN_CYLINDER=
1.59 +fi
1.60 +
1.61 +DEF="$1"
1.62 +
1.63 +if [ ! "$DEF" ] ; then
1.64 + cat 1>&2 <<EOF
1.65 +No definition specified.
1.66 +EOF
1.67 + exit 1
1.68 +fi
1.69 +
1.70 +# Initialise sfdisk usage.
1.71 +
1.72 +init_sfdisk "$DEV"
1.73 +
1.74 +# Expand the definition to partitioning options.
1.75 +# Use the options to generate a partition summary.
1.76 +# Convert the summary into a table.
1.77 +# Present the table to sfdisk.
1.78 +
1.79 + "$EXPAND" "$DEF" \
1.80 +| xargs "$PARTSUMMARY" \
1.81 +| "$PARTTABLE" $ALIGN_CYLINDER \
1.82 +| "$SFDISK" $SFDISK_OPTIONS "$DEV"