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 list of partition 66 types, one per line. Types recognised include ext, ext2, ext3, ext4, fat and 67 swap. 68 EOF 69 exit 0 70 fi 71 72 # Obtain details of the selected device. 73 74 check_device 75 76 # Read partition types, one per line. 77 78 PARTNUM=1 79 80 while read TYPE ; do 81 DEVICE="${DEV}${PARTNUM}" 82 format "$DEVICE" "$TYPE" 83 PARTNUM=$(($PARTNUM + 1)) 84 done