# HG changeset patch # User Paul Boddie # Date 1558739979 -7200 # Node ID 173422bb874144b5a88bbdeec8fa4953deadac95 # Parent 4135f638972c09ec8e20ef9955c8eea790901a52 Added an initial version of a filesystem formatting script. diff -r 4135f638972c -r 173422bb8741 makesd-format --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/makesd-format Sat May 25 01:19:39 2019 +0200 @@ -0,0 +1,54 @@ +#!/bin/sh + +# Support formatting of partitions. + +PROGNAME=`basename "$0"` +THISDIR=`dirname "$0"` + +COMMON="$THISDIR/makesd-common" +FSCK="/sbin/fsck" +MKFS="/sbin/mkfs" +MKSWAP="/sbin/mkswap" + +. "$COMMON" + + + +# format + +format() +{ + PARTNUM=$1 + TYPE=$2 + DEVICE="${DEV}${PARTNUM}" + + if [ ! -e "$DEVICE" ] ; then + echo "$DEVICE does not exist and therefore cannot be formatted." 1>&2 + return 1 + fi + + case "$DEVICE" in + ( fat ) + "${MKFS}.vfat" -F 32 -n "boot" "$DEVICE" && "${FSCK}.vfat" -a -y "$DEVICE" + ;; + ( ext* ) + "${MKFS}.$TYPE" "$DEVICE" && "${FSCK}.$TYPE" -y "$DEVICE" + ;; + ( swap ) + "$MKSWAP" "$DEVICE" + ;; + esac +} + + + +# Obtain details of the selected device. + +check_device + +PARTNUM=1 + +while read_fields ; do + format "$PARTNUM" "$TYPE" + PARTNUM=$(($PARTNUM + 1)) +done