blob: 1bc2b83bd62063dc36707f5edca4fc9893f41b58 [file] [log] [blame]
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -08001#!/bin/bash
2#
3# To call this script, make sure mksquashfs is somewhere in PATH
4
5function usage() {
6cat<<EOT
7Usage:
Thierry Strudelb89e81d2015-07-09 16:31:39 -07008${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT]
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -08009EOT
10}
11
12echo "in mksquashfsimage.sh PATH=$PATH"
13
14if [ $# -lt 2 ]; then
15 usage
16 exit 1
17fi
18
19SRC_DIR=$1
20if [ ! -d $SRC_DIR ]; then
21 echo "Can not find directory $SRC_DIR!"
22 exit 2
23fi
24OUTPUT_FILE=$2
25shift; shift
26
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -070027SPARSE=false
28if [[ "$1" == "-s" ]]; then
29 SPARSE=true
30 shift;
31fi
32
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080033MOUNT_POINT=
34if [[ "$1" == "-m" ]]; then
35 MOUNT_POINT=$2
36 shift; shift
37fi
38
Thierry Strudelb89e81d2015-07-09 16:31:39 -070039PRODUCT_OUT=
40if [[ "$1" == "-d" ]]; then
41 PRODUCT_OUT=$2
42 shift; shift
43fi
44
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080045FILE_CONTEXTS=
46if [[ "$1" == "-c" ]]; then
47 FILE_CONTEXTS=$2
48 shift; shift
49fi
50
51BLOCK_SIZE=131072
52if [[ "$1" == "-b" ]]; then
53 BLOCK_SIZE=$2
54 shift; shift
55fi
56
Simon Wilsonb4cf7b32015-06-17 12:36:53 -070057COMPRESSOR="lz4"
58COMPRESSOR_OPT="-Xhc"
59if [[ "$1" == "-z" ]]; then
60 COMPRESSOR=$2
61 COMPRESSOR_OPT=
62 shift; shift
63fi
64
65if [[ "$1" == "-zo" ]]; then
66 COMPRESSOR_OPT=$2
67 shift; shift
68fi
69
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080070OPT=""
71if [ -n "$MOUNT_POINT" ]; then
72 OPT="$OPT -mount-point $MOUNT_POINT"
73fi
Thierry Strudelb89e81d2015-07-09 16:31:39 -070074if [ -n "$PRODUCT_OUT" ]; then
75 OPT="$OPT -product-out $PRODUCT_OUT"
76fi
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080077if [ -n "$FILE_CONTEXTS" ]; then
78 OPT="$OPT -context-file $FILE_CONTEXTS"
79fi
80if [ -n "$BLOCK_SIZE" ]; then
81 OPT="$OPT -b $BLOCK_SIZE"
82fi
83
Simon Wilson12edfca2015-06-24 16:22:44 -070084MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR/ $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -android-fs-config $OPT"
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080085echo $MAKE_SQUASHFS_CMD
86$MAKE_SQUASHFS_CMD
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -070087
Mohamad Ayyashc8f18c82015-03-03 12:33:48 -080088if [ $? -ne 0 ]; then
89 exit 4
90fi
Mohamad Ayyashdf1dea32015-06-24 10:36:40 -070091
92SPARSE_SUFFIX=".sparse"
93if [ "$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
99fi
100