Home | History | Annotate | Download | only in ext4_utils
      1 #!/bin/bash -x
      2 #
      3 # To call this script, make sure make_ext4fs is somewhere in PATH
      4 
      5 function usage() {
      6 cat<<EOT
      7 Usage:
      8 mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [FILE_CONTEXTS]
      9 EOT
     10 }
     11 
     12 echo "in mkuserimg.sh PATH=$PATH"
     13 
     14 ENABLE_SPARSE_IMAGE=
     15 if [ "$1" = "-s" ]; then
     16   ENABLE_SPARSE_IMAGE="-s"
     17   shift
     18 fi
     19 
     20 if [ $# -ne 5 -a $# -ne 6 ]; then
     21   usage
     22   exit 1
     23 fi
     24 
     25 SRC_DIR=$1
     26 if [ ! -d $SRC_DIR ]; then
     27   echo "Can not find directory $SRC_DIR!"
     28   exit 2
     29 fi
     30 
     31 OUTPUT_FILE=$2
     32 EXT_VARIANT=$3
     33 MOUNT_POINT=$4
     34 SIZE=$5
     35 FC=$6
     36 
     37 case $EXT_VARIANT in
     38   ext4) ;;
     39   *) echo "Only ext4 is supported!"; exit 3 ;;
     40 esac
     41 
     42 if [ -z $MOUNT_POINT ]; then
     43   echo "Mount point is required"
     44   exit 2
     45 fi
     46 
     47 if [ -z $SIZE ]; then
     48   echo "Need size of filesystem"
     49   exit 2
     50 fi
     51 
     52 if [ -n "$FC" ]; then
     53     FCOPT="-S $FC"
     54 fi
     55 
     56 MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE $FCOPT -l $SIZE -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR"
     57 echo $MAKE_EXT4FS_CMD
     58 $MAKE_EXT4FS_CMD
     59 if [ $? -ne 0 ]; then
     60   exit 4
     61 fi
     62