OSDN Git Service

0079f6ef7797fd2750b507563574d7117979ec1b
[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 FS_CONFIG ] [-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 FS_CONFIG=
46 if [[ "$1" == "-C" ]]; then
47     FS_CONFIG=$2
48     shift; shift
49 fi
50
51 FILE_CONTEXTS=
52 if [[ "$1" == "-c" ]]; then
53     FILE_CONTEXTS=$2
54     shift; shift
55 fi
56
57 BLOCK_SIZE=131072
58 if [[ "$1" == "-b" ]]; then
59     BLOCK_SIZE=$2
60     shift; shift
61 fi
62
63 COMPRESSOR="lz4"
64 COMPRESSOR_OPT="-Xhc"
65 if [[ "$1" == "-z" ]]; then
66     COMPRESSOR=$2
67     COMPRESSOR_OPT=
68     shift; shift
69 fi
70
71 if [[ "$1" == "-zo" ]]; then
72     COMPRESSOR_OPT=$2
73     shift; shift
74 fi
75
76 OPT=""
77 if [ -n "$MOUNT_POINT" ]; then
78   OPT="$OPT -mount-point $MOUNT_POINT"
79 fi
80 if [ -n "$PRODUCT_OUT" ]; then
81   OPT="$OPT -product-out $PRODUCT_OUT"
82 fi
83 if [ -n "$FS_CONFIG" ]; then
84   OPT="$OPT -fs-config-file $FS_CONFIG"
85 fi
86 if [ -n "$FILE_CONTEXTS" ]; then
87   OPT="$OPT -context-file $FILE_CONTEXTS"
88 fi
89 if [ -n "$BLOCK_SIZE" ]; then
90   OPT="$OPT -b $BLOCK_SIZE"
91 fi
92
93 MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR/ $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -android-fs-config -no-fragments $OPT"
94 echo $MAKE_SQUASHFS_CMD
95 $MAKE_SQUASHFS_CMD
96
97 if [ $? -ne 0 ]; then
98     exit 4
99 fi
100
101 SPARSE_SUFFIX=".sparse"
102 if [ "$SPARSE" = true ]; then
103     img2simg $OUTPUT_FILE $OUTPUT_FILE$SPARSE_SUFFIX
104     if [ $? -ne 0 ]; then
105         exit 4
106     fi
107     mv $OUTPUT_FILE$SPARSE_SUFFIX $OUTPUT_FILE
108 fi
109