diff --git a/conf/enroot.conf.in b/conf/enroot.conf.in index eb67d2b..84f36c5 100644 --- a/conf/enroot.conf.in +++ b/conf/enroot.conf.in @@ -57,6 +57,9 @@ # Restrict /dev inside the container to a minimal set of devices. #ENROOT_RESTRICT_DEV no +# Always use --force on command invocations. +#ENROOT_FORCE_OVERRIDE no + # SSL certificates settings: #SSL_CERT_DIR #SSL_CERT_FILE diff --git a/doc/cmd/bundle.md b/doc/cmd/bundle.md index 4e7417f..f894ce3 100644 --- a/doc/cmd/bundle.md +++ b/doc/cmd/bundle.md @@ -10,6 +10,7 @@ Create a self-extracting bundle from a container image. -d, --desc TEXT Provide a description of the bundle -o, --output BUNDLE Name of the output bundle file (defaults to "IMAGE.run") -t, --target DIR Target directory used by --keep (defaults to "$PWD/BUNDLE") + -f, --force Overwrite an existing bundle ``` ``` Usage: bundle.run [options] [--] [COMMAND] [ARG...] @@ -47,6 +48,7 @@ If `--keep` is not provided at launch, `$ENROOT_TEMP_PATH` will be used for extr | ------ | ------ | ------ | | `ENROOT_BUNDLE_ALL` | `no` | Include runtime and user-specific configuration inside bundles (same as `--all`) | | `ENROOT_BUNDLE_CHECKSUM` | `no` | Generate an embedded checksum inside bundles (same as `--checksum`) | +| `ENROOT_FORCE_OVERRIDE` | `no` | Overwrite the bundle if it already exists (same as `--force`) | # Example diff --git a/doc/cmd/create.md b/doc/cmd/create.md index 36b4711..f842df4 100644 --- a/doc/cmd/create.md +++ b/doc/cmd/create.md @@ -6,7 +6,8 @@ Usage: enroot create [options] [--] IMAGE Create a container root filesystem from a container image. Options: - -n, --name Name of the container (defaults to "IMAGE") + -n, --name Name of the container (defaults to "IMAGE") + -f, --force Overwrite an existing root filesystem ``` # Description @@ -14,6 +15,12 @@ Create a container root filesystem from a container image. Take a container image and unpack its root filesystem under `$ENROOT_DATA_PATH/`. The resulting root filesystem can be started with the [start](start.md) command or removed with the [remove](remove.md) command. +# Configuration + +| Setting | Default | Description | +| ------ | ------ | ------ | +| `ENROOT_FORCE_OVERRIDE` | `no` | Overwrite the root filesystem if it already exists (same as `--force`) | + # Example ```sh diff --git a/doc/cmd/export.md b/doc/cmd/export.md index ee37b96..79ed680 100644 --- a/doc/cmd/export.md +++ b/doc/cmd/export.md @@ -7,6 +7,7 @@ Create a container image from a container root filesystem. Options: -o, --output Name of the output image file (defaults to "NAME.sqsh") + -f, --force Overwrite an existing container image ``` # Description @@ -20,6 +21,7 @@ The resulting image can be unpacked using the [create](create.md) command. | ------ | ------ | ------ | | `ENROOT_MAX_PROCESSORS` | `$(nproc)` | Maximum number of processors to use for parallel tasks (0 means unlimited) | | `ENROOT_SQUASH_OPTIONS` | `-comp lzo -noD` | Options passed to mksquashfs to produce container images | +| `ENROOT_FORCE_OVERRIDE` | `no` | Overwrite the container image if it already exists (same as `--force`) | # Example diff --git a/doc/cmd/remove.md b/doc/cmd/remove.md index 1182c76..cc92c8a 100644 --- a/doc/cmd/remove.md +++ b/doc/cmd/remove.md @@ -12,6 +12,12 @@ Delete one or multiple container root filesystems. Remove one or multiple containers, deleting their root filesystem from disk. +# Configuration + +| Setting | Default | Description | +| ------ | ------ | ------ | +| `ENROOT_FORCE_OVERRIDE` | `no` | Remove container root filesystems without prompting for confirmation (same as `--force`) | + # Example ```sh diff --git a/enroot.in b/enroot.in index eda5a85..cdfc83d 100644 --- a/enroot.in +++ b/enroot.in @@ -85,6 +85,7 @@ config::export ENROOT_ROOTFS_WRITABLE false config::export ENROOT_REMAP_ROOT false config::export ENROOT_BUNDLE_ALL false config::export ENROOT_BUNDLE_CHECKSUM false +config::export ENROOT_FORCE_OVERRIDE false config::fini @@ -120,6 +121,7 @@ enroot::usage() { -d, --desc TEXT Provide a description of the bundle -o, --output BUNDLE Name of the output bundle file (defaults to "IMAGE.run") -t, --target DIR Target directory used by --keep (defaults to "\$PWD/BUNDLE") + -f, --force Overwrite an existing bundle EOF ;; create) @@ -129,7 +131,8 @@ enroot::usage() { Create a container root filesystem from a container image. Options: - -n, --name Name of the container (defaults to "IMAGE") + -n, --name Name of the container (defaults to "IMAGE") + -f, --force Overwrite an existing root filesystem EOF ;; exec) @@ -150,6 +153,7 @@ enroot::usage() { Options: -o, --output Name of the output image file (defaults to "NAME.sqsh") + -f, --force Overwrite an existing container image EOF ;; import) @@ -279,6 +283,10 @@ enroot::export() { while [ $# -gt 0 ]; do case "$1" in + -f|--force) + export ENROOT_FORCE_OVERRIDE=y + shift + ;; -o|--output) [ -z "${2-}" ] && enroot::usage export filename="$2" @@ -310,6 +318,10 @@ enroot::create() { while [ $# -gt 0 ]; do case "$1" in + -f|--force) + export ENROOT_FORCE_OVERRIDE=y + shift + ;; -n|--name) [ -z "${2-}" ] && enroot::usage create name="$2" @@ -508,12 +520,12 @@ enroot::list() { } enroot::remove() { - local name= force= + local name= while [ $# -gt 0 ]; do case "$1" in -f|--force) - force=y + export ENROOT_FORCE_OVERRIDE=y shift ;; --) @@ -529,7 +541,7 @@ enroot::remove() { fi for name in "$@"; do - runtime::remove "${name}" "${force}" + runtime::remove "${name}" done } @@ -546,6 +558,10 @@ enroot::bundle() { export ENROOT_BUNDLE_CHECKSUM=y shift ;; + -f|--force) + export ENROOT_FORCE_OVERRIDE=y + shift + ;; -o|--output) [ -z "${2-}" ] && enroot::usage bundle filename="$2" diff --git a/src/runtime.sh b/src/runtime.sh index 1f75cdb..6cabe2d 100644 --- a/src/runtime.sh +++ b/src/runtime.sh @@ -407,7 +407,11 @@ runtime::create() { fi rootfs=$(common::realpath "${ENROOT_DATA_PATH}/${rootfs}") if [ -e "${rootfs}" ]; then - common::err "File already exists: ${rootfs}" + if [ -z "${ENROOT_FORCE_OVERRIDE-}" ]; then + common::err "File already exists: ${rootfs}" + else + common::rmall "${rootfs}" + fi fi # Extract the container rootfs from the image. @@ -460,7 +464,11 @@ runtime::export() { fi filename=$(common::realpath "${filename}") if [ -e "${filename}" ]; then - common::err "File already exists: ${filename}" + if [ -z "${ENROOT_FORCE_OVERRIDE-}" ]; then + common::err "File already exists: ${filename}" + else + common::rmall "${filename}" + fi fi # Exclude mountpoints, the bundle directory and the lockfile. @@ -534,7 +542,7 @@ runtime::list() { } runtime::remove() { - local rootfs="$1" force="$2" + local rootfs="$1" # Resolve the container rootfs path. if [ -z "${rootfs}" ]; then @@ -549,10 +557,10 @@ runtime::remove() { fi # Remove the rootfs specified after asking for confirmation. - if [ -z "${force}" ]; then + if [ -z "${ENROOT_FORCE_OVERRIDE-}" ]; then read -r -e -p "Do you really want to delete ${rootfs}? [y/N] " fi - if [ -n "${force}" ] || [ "${REPLY}" = "y" ] || [ "${REPLY}" = "Y" ]; then + if [ -n "${ENROOT_FORCE_OVERRIDE-}" ] || [ "${REPLY}" = "y" ] || [ "${REPLY}" = "Y" ]; then common::rmall "${rootfs}" fi } @@ -581,7 +589,11 @@ runtime::bundle() ( fi filename=$(common::realpath "${filename}") if [ -e "${filename}" ]; then - common::err "File already exists: ${filename}" + if [ -z "${ENROOT_FORCE_OVERRIDE-}" ]; then + common::err "File already exists: ${filename}" + else + common::rmall "${filename}" + fi fi # Generate a target directory if none was specified.