scripts/populate: add -m option, to merge source and dest
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Mar 24 22:36:51 2010 +0100 (2010-03-24)
changeset 1860ed94d8e12b63
parent 1859 f4e17e0e2574
child 1861 a5c020c3d31d
scripts/populate: add -m option, to merge source and dest

Merge the source rootfs into the (pre-existing) destination rootfs,
and populate the result accordingly.
scripts/populate.in
     1.1 --- a/scripts/populate.in	Tue Mar 23 19:27:41 2010 +0100
     1.2 +++ b/scripts/populate.in	Wed Mar 24 22:36:51 2010 +0100
     1.3 @@ -61,6 +61,18 @@
     1.4  
     1.5      -f  force execution: if destination directory already exists, it will be
     1.6          removed first; if a specified library (above) was not found, continue.
     1.7 +        Note: if using -m and the destination directory already exists, it
     1.8 +        is *not* removed, see below.
     1.9 +
    1.10 +    -m  Merge the source root directory with the destination root directory.
    1.11 +        If the latter does not exist, it is created, and -m is ignored.
    1.12 +        If the destination droot directory exists, then the content of the
    1.13 +        source root directory is copied in there, and the result is populated
    1.14 +        as usual.
    1.15 +        It can be usefull if constructing a rootfs incrementally from many
    1.16 +        smaller source root directories, or if your destination root directory
    1.17 +        is an NFS export that your target mounts as / (and you don't want to
    1.18 +        re-run exportfs -av everytime). USE WITH CARE!
    1.19  
    1.20      -v  Be verbose. By default, populate is absolutely silent.
    1.21  
    1.22 @@ -71,10 +83,11 @@
    1.23  CT_ROOT_DST_DIR=
    1.24  CT_LIB_LIST=
    1.25  CT_LIB_FILE=
    1.26 -CT_FORCE=no
    1.27 +CT_MERGE=
    1.28 +CT_FORCE=
    1.29  CT_PRINTF=:
    1.30  OPTIND=1
    1.31 -while getopts ":s:d:r:l:L:fvh" CT_OPT; do
    1.32 +while getopts ":s:d:r:l:L:fmvh" CT_OPT; do
    1.33      case "${CT_OPT}" in
    1.34          s)  CT_ROOT_SRC_DIR="${OPTARG}";;
    1.35          d)  CT_ROOT_DST_DIR="${OPTARG}";;
    1.36 @@ -82,6 +95,7 @@
    1.37          l)  CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
    1.38          L)  CT_LIB_FILE="${OPTARG}";;
    1.39          f)  CT_FORCE=y;;
    1.40 +        m)  CT_MERGE=y;;
    1.41          v)  CT_PRINTF=printf;;
    1.42          h)  doHelp
    1.43              exit 0
    1.44 @@ -108,9 +122,16 @@
    1.45      echo "$myname: '${CT_SYSROOT_DIR}': no such file or directory"
    1.46      exit 1
    1.47  fi
    1.48 -if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then
    1.49 -    echo "$myname: '${CT_ROOT_DST_DIR}': already exists"
    1.50 -    exit 1
    1.51 +# If the dest dir does not exist, all is well
    1.52 +# If merging, we accept an existing dest directory
    1.53 +# If forcing and not merging, we remove an exiting dest directory
    1.54 +# If not forcing and not merging, we do not accept an exiting dest directory
    1.55 +if [ -d "${CT_ROOT_DST_DIR}" ]; then
    1.56 +    case "${CT_FORCE}:${CT_MERGE}" in
    1.57 +        *:y)    ;;
    1.58 +        y:)     rm -rf "${CT_ROOT_DST_DIR}";;
    1.59 +        :)      echo "$myname: '${CT_ROOT_DST_DIR}': already exists" && exit 1 ;;
    1.60 +    esac
    1.61  fi
    1.62  src_inode=$(stat -c '%i' "${CT_ROOT_SRC_DIR}/.")
    1.63  dst_inode=$(stat -c '%i' "${CT_ROOT_DST_DIR}/." 2>/dev/null || true)
    1.64 @@ -125,10 +146,7 @@
    1.65      exit 1
    1.66  fi
    1.67  
    1.68 -# Get rid of potentially older destination directory
    1.69 -rm -rf "${CT_ROOT_DST_DIR}"
    1.70 -
    1.71 -# Create the working copy
    1.72 +# Create the working copy, no issue if already existing
    1.73  mkdir -p "${CT_ROOT_DST_DIR}"
    1.74  
    1.75  # Make all path absolute