Mohamad Ayyash | f0d5f8c | 2015-03-03 12:33:48 -0800 | [diff] [blame] | 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] |
| 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 | OPT="" |
| 46 | if [ -n "$MOUNT_POINT" ]; then |
| 47 | OPT="$OPT -mount-point $MOUNT_POINT" |
| 48 | fi |
| 49 | if [ -n "$FILE_CONTEXTS" ]; then |
| 50 | OPT="$OPT -context-file $FILE_CONTEXTS" |
| 51 | fi |
| 52 | if [ -n "$BLOCK_SIZE" ]; then |
| 53 | OPT="$OPT -b $BLOCK_SIZE" |
| 54 | fi |
| 55 | |
| 56 | MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR $OUTPUT_FILE -no-progress -comp lz4 -Xhc -no-exports -noappend -no-recovery -android-fs-config $OPT" |
| 57 | echo $MAKE_SQUASHFS_CMD |
| 58 | $MAKE_SQUASHFS_CMD |
| 59 | if [ $? -ne 0 ]; then |
| 60 | exit 4 |
| 61 | fi |