OSDN Git Service

am 44df7549: Merge "fix bug in mkf2fs tool calculation of f2fs filesystem length"
[android-x86/system-extras.git] / squashfs_utils / mksquashfsimage.sh
1 #!/bin/bash
2 #
3 # To call this script, make sure mksquashfs is somewhere in PATH
4
5 function usage() {
6 cat<<EOT
7 Usage:
8 ${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT]
9 EOT
10 }
11
12 echo "in mksquashfsimage.sh PATH=$PATH"
13
14 if [ $# -lt 2 ]; then
15     usage
16     exit 1
17 fi
18
19 SRC_DIR=$1
20 if [ ! -d $SRC_DIR ]; then
21   echo "Can not find directory $SRC_DIR!"
22   exit 2
23 fi
24 OUTPUT_FILE=$2
25 shift; shift
26
27 SPARSE=false
28 if [[ "$1" == "-s" ]]; then
29     SPARSE=true
30     shift;
31 fi
32
33 MOUNT_POINT=
34 if [[ "$1" == "-m" ]]; then
35     MOUNT_POINT=$2
36     shift; shift
37 fi
38
39 PRODUCT_OUT=
40 if [[ "$1" == "-d" ]]; then
41     PRODUCT_OUT=$2
42     shift; shift
43 fi
44
45 FILE_CONTEXTS=
46 if [[ "$1" == "-c" ]]; then
47     FILE_CONTEXTS=$2
48     shift; shift
49 fi
50
51 BLOCK_SIZE=131072
52 if [[ "$1" == "-b" ]]; then
53     BLOCK_SIZE=$2
54     shift; shift
55 fi
56
57 COMPRESSOR="lz4"
58 COMPRESSOR_OPT="-Xhc"
59 if [[ "$1" == "-z" ]]; then
60     COMPRESSOR=$2
61     COMPRESSOR_OPT=
62     shift; shift
63 fi
64
65 if [[ "$1" == "-zo" ]]; then
66     COMPRESSOR_OPT=$2
67     shift; shift
68 fi
69
70 OPT=""
71 if [ -n "$MOUNT_POINT" ]; then
72   OPT="$OPT -mount-point $MOUNT_POINT"
73 fi
74 if [ -n "$PRODUCT_OUT" ]; then
75   OPT="$OPT -product-out $PRODUCT_OUT"
76 fi
77 if [ -n "$FILE_CONTEXTS" ]; then
78   OPT="$OPT -context-file $FILE_CONTEXTS"
79 fi
80 if [ -n "$BLOCK_SIZE" ]; then
81   OPT="$OPT -b $BLOCK_SIZE"
82 fi
83
84 MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR/ $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -android-fs-config $OPT"
85 echo $MAKE_SQUASHFS_CMD
86 $MAKE_SQUASHFS_CMD
87
88 if [ $? -ne 0 ]; then
89     exit 4
90 fi
91
92 SPARSE_SUFFIX=".sparse"
93 if [ "$SPARSE" = true ]; then
94     img2simg $OUTPUT_FILE $OUTPUT_FILE$SPARSE_SUFFIX
95     if [ $? -ne 0 ]; then
96         exit 4
97     fi
98     mv $OUTPUT_FILE$SPARSE_SUFFIX $OUTPUT_FILE
99 fi
100