cookutils rev 539 slitaz-tank

libmodular.sh: Add _mksquash function.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Sep 23 11:12:02 2012 +0000 (2012-09-23)
parents 62860c25523f
children 699d4f06e3dc
files lib/libmodular.sh
line diff
     1.1 --- a/lib/libmodular.sh	Sun Sep 23 10:29:05 2012 +0000
     1.2 +++ b/lib/libmodular.sh	Sun Sep 23 11:12:02 2012 +0000
     1.3 @@ -9,6 +9,10 @@
     1.4  CDNAME="slitaz"
     1.5  SGNFILE=$ROOTCD/${CDNAME}/livecd.sgn
     1.6  KEY_FILES="init liblinuxlive linuxrc"
     1.7 +EXT="xz"
     1.8 +COMPRESSION="xz -Xbcj x86"
     1.9 +MKOPTION="-b 512k"
    1.10 +#NCPU="-processors 3"
    1.11  
    1.12  error () { echo -e "\033[1;31;40m!!! \033[1;37;40m$@\033[1;0m"; }
    1.13  warn ()  { echo -e "\033[1;33;40m*** \033[1;37;40m$@\033[1;0m"; }
    1.14 @@ -140,3 +144,45 @@
    1.15  	find ${MODULES_DIR} -type f -name ".wh.*" -exec rm {} \;
    1.16  	find ${MODULES_DIR} -type d -name ".wh.*" -exec rm -rf {} \;
    1.17  }
    1.18 +
    1.19 +# _mksquash dirname
    1.20 +_mksquash () {
    1.21 +    if [ ! -d "$1" ]; then
    1.22 +        error "Error: '$1' is not a directory"
    1.23 +        return 1
    1.24 +    fi
    1.25 +
    1.26 +    if [ ! -d "$2" ]; then
    1.27 +        error "Error: '$2' is not a directory"
    1.28 +        return 1
    1.29 +    fi
    1.30 +
    1.31 +    if [ ! -d "${1}${3}" ]; then
    1.32 +        error "Error: '${1}${3}' is not a directory"
    1.33 +        return 1
    1.34 +    fi
    1.35 +
    1.36 +    time_dir="${3}"
    1.37 +    sqimg="${2}/$(basename ${1}).${EXT}"
    1.38 +    info "====> Generating SquashFS image for '${1}'"
    1.39 +    if [ -e "${sqimg}" ]; then
    1.40 +        dirhaschanged=$(find ${1}${time_dir} -newer ${sqimg})
    1.41 +        if [ "${dirhaschanged}" != "" ]; then
    1.42 +            info "SquashFS image '${sqimg}' is not up to date, rebuilding..."
    1.43 +            rm "${sqimg}"
    1.44 +        else
    1.45 +            info "SquashFS image '${sqimg}' is up to date, skipping."
    1.46 +            return
    1.47 +        fi
    1.48 +    fi
    1.49 +
    1.50 +    info "Creating SquashFS image. This may take some time..."
    1.51 +    start=$(date +%s)
    1.52 +    if [ "${QUIET}" = "y" ]; then
    1.53 +        mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION} >/dev/null
    1.54 +    else
    1.55 +        mksquashfs "${1}" "${sqimg}" ${NCPU} -noappend ${MKOPTION} -comp ${COMPRESSION}
    1.56 +    fi
    1.57 +    minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
    1.58 +    info "Image creation done in $minutes minutes."
    1.59 +}