Skip to content

Commit

Permalink
Add more force overrides with ENROOT_FORCE_OVERRIDE
Browse files Browse the repository at this point in the history
  • Loading branch information
3XX0 committed Jun 30, 2020
1 parent 14d95f3 commit 393ba41
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
3 changes: 3 additions & 0 deletions conf/enroot.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/cmd/bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...]
Expand Down Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion doc/cmd/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ 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

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
Expand Down
2 changes: 2 additions & 0 deletions doc/cmd/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions doc/cmd/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions enroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
;;
--)
Expand All @@ -529,7 +541,7 @@ enroot::remove() {
fi

for name in "$@"; do
runtime::remove "${name}" "${force}"
runtime::remove "${name}"
done
}

Expand All @@ -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"
Expand Down
24 changes: 18 additions & 6 deletions src/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 393ba41

Please sign in to comment.