paul@8 | 1 | #!/bin/sh |
paul@8 | 2 | |
paul@8 | 3 | # Support formatting of partitions. |
paul@8 | 4 | |
paul@8 | 5 | PROGNAME=`basename "$0"` |
paul@8 | 6 | THISDIR=`dirname "$0"` |
paul@8 | 7 | |
paul@8 | 8 | COMMON="$THISDIR/makesd-common" |
paul@8 | 9 | FSCK="/sbin/fsck" |
paul@8 | 10 | MKFS="/sbin/mkfs" |
paul@8 | 11 | MKSWAP="/sbin/mkswap" |
paul@8 | 12 | |
paul@8 | 13 | . "$COMMON" |
paul@8 | 14 | |
paul@8 | 15 | |
paul@8 | 16 | |
paul@8 | 17 | # format <device> <type> |
paul@8 | 18 | |
paul@8 | 19 | format() |
paul@8 | 20 | { |
paul@10 | 21 | DEVICE=$1 |
paul@8 | 22 | TYPE=$2 |
paul@8 | 23 | |
paul@8 | 24 | if [ ! -e "$DEVICE" ] ; then |
paul@8 | 25 | echo "$DEVICE does not exist and therefore cannot be formatted." 1>&2 |
paul@8 | 26 | return 1 |
paul@8 | 27 | fi |
paul@8 | 28 | |
paul@8 | 29 | case "$DEVICE" in |
paul@8 | 30 | ( fat ) |
paul@8 | 31 | "${MKFS}.vfat" -F 32 -n "boot" "$DEVICE" && "${FSCK}.vfat" -a -y "$DEVICE" |
paul@8 | 32 | ;; |
paul@8 | 33 | ( ext* ) |
paul@8 | 34 | "${MKFS}.$TYPE" "$DEVICE" && "${FSCK}.$TYPE" -y "$DEVICE" |
paul@8 | 35 | ;; |
paul@8 | 36 | ( swap ) |
paul@8 | 37 | "$MKSWAP" "$DEVICE" |
paul@8 | 38 | ;; |
paul@8 | 39 | esac |
paul@8 | 40 | } |
paul@8 | 41 | |
paul@8 | 42 | |
paul@8 | 43 | |
paul@13 | 44 | # Emit the help message if requested. |
paul@13 | 45 | |
paul@13 | 46 | if [ "$1" = '--help' ] ; then |
paul@13 | 47 | cat 1>&2 <<EOF |
paul@13 | 48 | Usage: $PROGNAME |
paul@13 | 49 | |
paul@13 | 50 | The input for this program is supplied via standard input as a partitioning |
paul@13 | 51 | summary with each line providing a collection of tab-separated values. These |
paul@13 | 52 | values appear in the following order: |
paul@13 | 53 | |
paul@13 | 54 | <start> <size> <type> |
paul@13 | 55 | |
paul@13 | 56 | Only the type value is employed by this program. Types recognised include ext, |
paul@13 | 57 | ext2, ext3, ext4, fat and swap. |
paul@13 | 58 | EOF |
paul@13 | 59 | exit 0 |
paul@13 | 60 | fi |
paul@13 | 61 | |
paul@8 | 62 | # Obtain details of the selected device. |
paul@8 | 63 | |
paul@8 | 64 | check_device |
paul@8 | 65 | |
paul@8 | 66 | PARTNUM=1 |
paul@8 | 67 | |
paul@8 | 68 | while read_fields ; do |
paul@10 | 69 | DEVICE="${DEV}${PARTNUM}" |
paul@10 | 70 | format "$DEVICE" "$TYPE" |
paul@8 | 71 | PARTNUM=$(($PARTNUM + 1)) |
paul@8 | 72 | done |