1 #!/bin/sh 2 3 # Support formatting of partitions. 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 FSCK="/sbin/fsck" 25 MKFS="/sbin/mkfs" 26 MKSWAP="/sbin/mkswap" 27 28 . "$COMMON" 29 30 31 32 # format <device> <type> 33 34 format() 35 { 36 DEVICE=$1 37 TYPE=$2 38 39 if [ ! -e "$DEVICE" ] ; then 40 echo "$DEVICE does not exist and therefore cannot be formatted." 1>&2 41 return 1 42 fi 43 44 case "$DEVICE" in 45 ( fat ) 46 "${MKFS}.vfat" -F 32 -n "boot" "$DEVICE" && "${FSCK}.vfat" -a -y "$DEVICE" 47 ;; 48 ( ext* ) 49 "${MKFS}.$TYPE" "$DEVICE" && "${FSCK}.$TYPE" -y "$DEVICE" 50 ;; 51 ( swap ) 52 "$MKSWAP" "$DEVICE" 53 ;; 54 esac 55 } 56 57 58 59 # Emit the help message if requested. 60 61 if [ "$1" = '--help' ] ; then 62 cat 1>&2 <<EOF 63 Usage: $PROGNAME 64 65 The input for this program is supplied via standard input as a partitioning 66 summary with each line providing a collection of tab-separated values. These 67 values appear in the following order: 68 69 <start> <size> <type> 70 71 Only the type value is employed by this program. Types recognised include ext, 72 ext2, ext3, ext4, fat and swap. 73 EOF 74 exit 0 75 fi 76 77 # Obtain details of the selected device. 78 79 check_device 80 81 PARTNUM=1 82 83 while read_fields ; do 84 DEVICE="${DEV}${PARTNUM}" 85 format "$DEVICE" "$TYPE" 86 PARTNUM=$(($PARTNUM + 1)) 87 done