Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 2 | # |
3 | # To call this script, make sure make_ext4fs is somewhere in PATH | ||||
4 | |||||
5 | function usage() { | ||||
6 | cat<<EOT | ||||
7 | Usage: | ||||
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 8 | mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE |
Christoffer Dall | b23b2c0 | 2014-12-17 21:35:37 +0100 | [diff] [blame^] | 9 | [-T TIMESTAMP] [-C FS_CONFIG] [-B BLOCK_LIST_FILE] [-L LABEL] [FILE_CONTEXTS] |
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 10 | EOT |
11 | } | ||||
12 | |||||
Ying Wang | c22117c | 2010-11-17 15:42:51 -0800 | [diff] [blame] | 13 | ENABLE_SPARSE_IMAGE= |
14 | if [ "$1" = "-s" ]; then | ||||
15 | ENABLE_SPARSE_IMAGE="-s" | ||||
16 | shift | ||||
17 | fi | ||||
18 | |||||
Doug Zongker | aad1acc | 2014-06-16 09:07:44 -0700 | [diff] [blame] | 19 | if [ $# -lt 5 ]; then |
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 20 | usage |
21 | exit 1 | ||||
22 | fi | ||||
23 | |||||
24 | SRC_DIR=$1 | ||||
25 | if [ ! -d $SRC_DIR ]; then | ||||
26 | echo "Can not find directory $SRC_DIR!" | ||||
27 | exit 2 | ||||
28 | fi | ||||
29 | |||||
30 | OUTPUT_FILE=$2 | ||||
31 | EXT_VARIANT=$3 | ||||
Ying Wang | 8bdbbe2 | 2010-09-27 17:56:55 -0700 | [diff] [blame] | 32 | MOUNT_POINT=$4 |
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 33 | SIZE=$5 |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 34 | shift; shift; shift; shift; shift |
35 | |||||
36 | TIMESTAMP=-1 | ||||
37 | if [[ "$1" == "-T" ]]; then | ||||
38 | TIMESTAMP=$2 | ||||
39 | shift; shift | ||||
40 | fi | ||||
Doug Zongker | aad1acc | 2014-06-16 09:07:44 -0700 | [diff] [blame] | 41 | |
42 | FS_CONFIG= | ||||
43 | if [[ "$1" == "-C" ]]; then | ||||
44 | FS_CONFIG=$2 | ||||
45 | shift; shift | ||||
46 | fi | ||||
47 | |||||
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 48 | BLOCK_LIST= |
49 | if [[ "$1" == "-B" ]]; then | ||||
50 | BLOCK_LIST=$2 | ||||
51 | shift; shift | ||||
52 | fi | ||||
53 | |||||
Christoffer Dall | b23b2c0 | 2014-12-17 21:35:37 +0100 | [diff] [blame^] | 54 | LABEL= |
55 | if [[ "$1" == "-L" ]]; then | ||||
56 | LABEL=$2 | ||||
57 | shift; shift | ||||
58 | fi | ||||
59 | |||||
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 60 | FC=$1 |
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 61 | |
62 | case $EXT_VARIANT in | ||||
63 | ext4) ;; | ||||
64 | *) echo "Only ext4 is supported!"; exit 3 ;; | ||||
65 | esac | ||||
66 | |||||
Ying Wang | 8bdbbe2 | 2010-09-27 17:56:55 -0700 | [diff] [blame] | 67 | if [ -z $MOUNT_POINT ]; then |
68 | echo "Mount point is required" | ||||
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 69 | exit 2 |
70 | fi | ||||
71 | |||||
72 | if [ -z $SIZE ]; then | ||||
Ying Wang | a468c4e | 2012-11-19 10:42:55 -0800 | [diff] [blame] | 73 | echo "Need size of filesystem" |
74 | exit 2 | ||||
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 75 | fi |
76 | |||||
Doug Zongker | aad1acc | 2014-06-16 09:07:44 -0700 | [diff] [blame] | 77 | OPT="" |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 78 | if [ -n "$FC" ]; then |
Doug Zongker | aad1acc | 2014-06-16 09:07:44 -0700 | [diff] [blame] | 79 | OPT="$OPT -S $FC" |
80 | fi | ||||
81 | if [ -n "$FS_CONFIG" ]; then | ||||
82 | OPT="$OPT -C $FS_CONFIG" | ||||
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 83 | fi |
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 84 | if [ -n "$BLOCK_LIST" ]; then |
85 | OPT="$OPT -B $BLOCK_LIST" | ||||
86 | fi | ||||
Christoffer Dall | b23b2c0 | 2014-12-17 21:35:37 +0100 | [diff] [blame^] | 87 | if [ -n "$LABEL" ]; then |
88 | OPT="$OPT -L $LABEL" | ||||
89 | fi | ||||
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 90 | |
Doug Zongker | aad1acc | 2014-06-16 09:07:44 -0700 | [diff] [blame] | 91 | MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE -T $TIMESTAMP $OPT -l $SIZE -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR" |
Ying Wang | c22117c | 2010-11-17 15:42:51 -0800 | [diff] [blame] | 92 | echo $MAKE_EXT4FS_CMD |
93 | $MAKE_EXT4FS_CMD | ||||
Colin Cross | 3c97782 | 2010-08-03 13:49:43 -0700 | [diff] [blame] | 94 | if [ $? -ne 0 ]; then |
95 | exit 4 | ||||
96 | fi |