OSDN Git Service

am b4cf7b30: Add switches for compressor
[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 [-m MOUNT_POINT] [-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 MOUNT_POINT=
28 if [[ "$1" == "-m" ]]; then
29     MOUNT_POINT=$2
30     shift; shift
31 fi
32
33 FILE_CONTEXTS=
34 if [[ "$1" == "-c" ]]; then
35     FILE_CONTEXTS=$2
36     shift; shift
37 fi
38
39 BLOCK_SIZE=131072
40 if [[ "$1" == "-b" ]]; then
41     BLOCK_SIZE=$2
42     shift; shift
43 fi
44
45 COMPRESSOR="lz4"
46 COMPRESSOR_OPT="-Xhc"
47 if [[ "$1" == "-z" ]]; then
48     COMPRESSOR=$2
49     COMPRESSOR_OPT=
50     shift; shift
51 fi
52
53 if [[ "$1" == "-zo" ]]; then
54     COMPRESSOR_OPT=$2
55     shift; shift
56 fi
57
58 OPT=""
59 if [ -n "$MOUNT_POINT" ]; then
60   OPT="$OPT -mount-point $MOUNT_POINT"
61 fi
62 if [ -n "$FILE_CONTEXTS" ]; then
63   OPT="$OPT -context-file $FILE_CONTEXTS"
64 fi
65 if [ -n "$BLOCK_SIZE" ]; then
66   OPT="$OPT -b $BLOCK_SIZE"
67 fi
68
69 MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -android-fs-config $OPT"
70 echo $MAKE_SQUASHFS_CMD
71 $MAKE_SQUASHFS_CMD
72 if [ $? -ne 0 ]; then
73     exit 4
74 fi