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