paul@12 | 1 | #!/bin/sh |
paul@12 | 2 | |
paul@13 | 3 | # Prepare a disk for booting a specific hardware device. |
paul@15 | 4 | # |
paul@15 | 5 | # Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> |
paul@15 | 6 | # |
paul@15 | 7 | # This program is free software; you can redistribute it and/or modify it under |
paul@15 | 8 | # the terms of the GNU General Public License as published by the Free Software |
paul@15 | 9 | # Foundation; either version 3 of the License, or (at your option) any later |
paul@15 | 10 | # version. |
paul@15 | 11 | # |
paul@15 | 12 | # This program is distributed in the hope that it will be useful, but WITHOUT |
paul@15 | 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@15 | 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@15 | 15 | # details. |
paul@15 | 16 | # |
paul@15 | 17 | # You should have received a copy of the GNU General Public License along with |
paul@15 | 18 | # this program. If not, see <http://www.gnu.org/licenses/>. |
paul@12 | 19 | |
paul@12 | 20 | PROGNAME=`basename "$0"` |
paul@12 | 21 | THISDIR=`dirname "$0"` |
paul@12 | 22 | |
paul@12 | 23 | COMMON="$THISDIR/makesd-common" |
paul@14 | 24 | DEFS="$THISDIR/makesd-defs" |
paul@12 | 25 | EXPAND="$THISDIR/makesd-expand-def" |
paul@12 | 26 | FORMAT="$THISDIR/makesd-format" |
paul@12 | 27 | PARTSUMMARY="$THISDIR/makesd-partition-summary" |
paul@12 | 28 | PARTITION="$THISDIR/makesd-partition" |
paul@12 | 29 | |
paul@12 | 30 | . "$COMMON" |
paul@12 | 31 | |
paul@12 | 32 | |
paul@12 | 33 | |
paul@13 | 34 | # Emit the help message if requested. |
paul@13 | 35 | |
paul@13 | 36 | if [ "$1" = '--help' ] ; then |
paul@13 | 37 | cat 1>&2 <<EOF |
paul@13 | 38 | Usage: $PROGNAME [ --align ] <definition name> |
paul@14 | 39 | $PROGNAME -a | --all | --defs |
paul@13 | 40 | |
paul@13 | 41 | Partition, format, populate and initialise a device for use with a particular |
paul@13 | 42 | kind of hardware. The given definition name is used to search the database of |
paul@13 | 43 | supported hardware devices and to configure the different preparation |
paul@13 | 44 | activities. |
paul@13 | 45 | |
paul@14 | 46 | If the -a, --all or --defs options are specified, all hardware definitions are |
paul@14 | 47 | emitted and no further actions are taken. |
paul@14 | 48 | |
paul@13 | 49 | $(align_cylinder_description) |
paul@13 | 50 | EOF |
paul@13 | 51 | exit 0 |
paul@13 | 52 | fi |
paul@13 | 53 | |
paul@14 | 54 | # Test for the definition output options. |
paul@14 | 55 | |
paul@14 | 56 | if [ "$1" = '-a' ] || [ "$1" = '--all' ] || [ "$1" = '--defs' ] ; then |
paul@14 | 57 | grep '^[[:alpha:]]' "$DEFS" | cut -f1 | sort |
paul@14 | 58 | exit 0 |
paul@14 | 59 | fi |
paul@14 | 60 | |
paul@12 | 61 | # Obtain details of the selected device. |
paul@12 | 62 | |
paul@12 | 63 | check_device |
paul@12 | 64 | |
paul@12 | 65 | SUMMARY="`basename "$DEV"`.summary" |
paul@12 | 66 | |
paul@12 | 67 | # Test for the cylinder alignment option. |
paul@12 | 68 | |
paul@12 | 69 | if test_align_cylinder $* ; then shift 1 ; fi |
paul@12 | 70 | |
paul@12 | 71 | # Obtain the definition name. |
paul@12 | 72 | |
paul@12 | 73 | DEF="$1" |
paul@12 | 74 | |
paul@12 | 75 | if [ ! "$DEF" ] ; then |
paul@12 | 76 | cat 1>&2 <<EOF |
paul@12 | 77 | No definition specified. |
paul@12 | 78 | EOF |
paul@12 | 79 | exit 1 |
paul@12 | 80 | fi |
paul@12 | 81 | |
paul@12 | 82 | shift 1 |
paul@12 | 83 | |
paul@12 | 84 | # Expand the definition to partitioning options. |
paul@12 | 85 | |
paul@12 | 86 | if ! ARGS=`"$EXPAND" "$DEF"` ; then |
paul@12 | 87 | cat 1>&2 <<EOF |
paul@12 | 88 | Device definition not found: $DEF |
paul@12 | 89 | EOF |
paul@12 | 90 | exit 1 |
paul@12 | 91 | fi |
paul@12 | 92 | |
paul@12 | 93 | # Use the options to generate a partition summary. |
paul@12 | 94 | |
paul@12 | 95 | "$PARTSUMMARY" $ARGS \ |
paul@12 | 96 | > "$SUMMARY" |
paul@12 | 97 | |
paul@12 | 98 | # Partition the given device. |
paul@12 | 99 | |
paul@12 | 100 | "$PARTITION" $ALIGN_CYLINDER < "$SUMMARY" |
paul@12 | 101 | |
paul@12 | 102 | # Format the given device. |
paul@12 | 103 | |
paul@12 | 104 | "$FORMAT" < "$SUMMARY" |