blob: 08c75bef2b7677497f6765c60045901722507a13 [file] [log] [blame]
Doug Zongker95266802013-12-05 15:51:28 -08001#!/bin/bash
Colin Cross3c977822010-08-03 13:49:43 -07002#
3# To call this script, make sure make_ext4fs is somewhere in PATH
4
5function usage() {
6cat<<EOT
7Usage:
Ying Wang1ec61e72014-11-18 18:06:56 -08008mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
Patrick Tjin8a764b52016-10-20 10:55:11 -07009 [-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE]
10 [-d BASE_ALLOC_FILE_IN ] [-A BASE_ALLOC_FILE_OUT ] [-L LABEL]
11 [-i INODES ] [FILE_CONTEXTS]
Colin Cross3c977822010-08-03 13:49:43 -070012EOT
13}
14
Ying Wangc22117c2010-11-17 15:42:51 -080015ENABLE_SPARSE_IMAGE=
16if [ "$1" = "-s" ]; then
17 ENABLE_SPARSE_IMAGE="-s"
18 shift
19fi
20
Doug Zongkeraad1acc2014-06-16 09:07:44 -070021if [ $# -lt 5 ]; then
Colin Cross3c977822010-08-03 13:49:43 -070022 usage
23 exit 1
24fi
25
26SRC_DIR=$1
27if [ ! -d $SRC_DIR ]; then
28 echo "Can not find directory $SRC_DIR!"
29 exit 2
30fi
31
32OUTPUT_FILE=$2
33EXT_VARIANT=$3
Ying Wang8bdbbe22010-09-27 17:56:55 -070034MOUNT_POINT=$4
Colin Cross3c977822010-08-03 13:49:43 -070035SIZE=$5
Doug Zongker95266802013-12-05 15:51:28 -080036shift; shift; shift; shift; shift
37
Ying Wang1ec61e72014-11-18 18:06:56 -080038JOURNAL_FLAGS=
39if [ "$1" = "-j" ]; then
40 if [ "$2" = "0" ]; then
41 JOURNAL_FLAGS="-J"
42 else
43 JOURNAL_FLAGS="-j $2"
44 fi
45 shift; shift
46fi
47
Doug Zongker95266802013-12-05 15:51:28 -080048TIMESTAMP=-1
49if [[ "$1" == "-T" ]]; then
50 TIMESTAMP=$2
51 shift; shift
52fi
Doug Zongkeraad1acc2014-06-16 09:07:44 -070053
54FS_CONFIG=
55if [[ "$1" == "-C" ]]; then
56 FS_CONFIG=$2
57 shift; shift
58fi
59
Thierry Strudelb89e81d2015-07-09 16:31:39 -070060PRODUCT_OUT=
61if [[ "$1" == "-D" ]]; then
62 PRODUCT_OUT=$2
63 shift; shift
64fi
65
Doug Zongkerbec598e2014-08-12 11:35:37 -070066BLOCK_LIST=
67if [[ "$1" == "-B" ]]; then
68 BLOCK_LIST=$2
69 shift; shift
70fi
71
Mohamad Ayyash95791982016-02-20 03:46:00 +000072BASE_ALLOC_FILE_IN=
73if [[ "$1" == "-d" ]]; then
74 BASE_ALLOC_FILE_IN=$2
75 shift; shift
76fi
77
78BASE_ALLOC_FILE_OUT=
79if [[ "$1" == "-A" ]]; then
80 BASE_ALLOC_FILE_OUT=$2
81 shift; shift
82fi
83
Christoffer Dallb23b2c02014-12-17 21:35:37 +010084LABEL=
85if [[ "$1" == "-L" ]]; then
86 LABEL=$2
87 shift; shift
88fi
89
Patrick Tjin8a764b52016-10-20 10:55:11 -070090INODES=
91if [[ "$1" == "-i" ]]; then
92 INODES=$2
93 shift; shift
94fi
Doug Zongker95266802013-12-05 15:51:28 -080095FC=$1
Colin Cross3c977822010-08-03 13:49:43 -070096
97case $EXT_VARIANT in
98 ext4) ;;
99 *) echo "Only ext4 is supported!"; exit 3 ;;
100esac
101
Ying Wang8bdbbe22010-09-27 17:56:55 -0700102if [ -z $MOUNT_POINT ]; then
103 echo "Mount point is required"
Colin Cross3c977822010-08-03 13:49:43 -0700104 exit 2
105fi
106
107if [ -z $SIZE ]; then
Ying Wanga468c4e2012-11-19 10:42:55 -0800108 echo "Need size of filesystem"
109 exit 2
Colin Cross3c977822010-08-03 13:49:43 -0700110fi
111
Doug Zongkeraad1acc2014-06-16 09:07:44 -0700112OPT=""
Stephen Smalleyb4eca4b2012-01-13 09:00:56 -0500113if [ -n "$FC" ]; then
Doug Zongkeraad1acc2014-06-16 09:07:44 -0700114 OPT="$OPT -S $FC"
115fi
116if [ -n "$FS_CONFIG" ]; then
117 OPT="$OPT -C $FS_CONFIG"
Stephen Smalleyb4eca4b2012-01-13 09:00:56 -0500118fi
Doug Zongkerbec598e2014-08-12 11:35:37 -0700119if [ -n "$BLOCK_LIST" ]; then
120 OPT="$OPT -B $BLOCK_LIST"
121fi
Mohamad Ayyash95791982016-02-20 03:46:00 +0000122if [ -n "$BASE_ALLOC_FILE_IN" ]; then
123 OPT="$OPT -d $BASE_ALLOC_FILE_IN"
124fi
125if [ -n "$BASE_ALLOC_FILE_OUT" ]; then
126 OPT="$OPT -D $BASE_ALLOC_FILE_OUT"
127fi
Christoffer Dallb23b2c02014-12-17 21:35:37 +0100128if [ -n "$LABEL" ]; then
129 OPT="$OPT -L $LABEL"
130fi
Patrick Tjin8a764b52016-10-20 10:55:11 -0700131if [ -n "$INODES" ]; then
132 OPT="$OPT -i $INODES"
133fi
Stephen Smalleyb4eca4b2012-01-13 09:00:56 -0500134
Thierry Strudelb89e81d2015-07-09 16:31:39 -0700135MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE -T $TIMESTAMP $OPT -l $SIZE $JOURNAL_FLAGS -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR $PRODUCT_OUT"
Ying Wangc22117c2010-11-17 15:42:51 -0800136echo $MAKE_EXT4FS_CMD
137$MAKE_EXT4FS_CMD
Colin Cross3c977822010-08-03 13:49:43 -0700138if [ $? -ne 0 ]; then
139 exit 4
140fi