env = dict(
SCRIPT="/work/prepare",
+ CHROOT_SCRIPT="/work/prepare",
SRCDIR=str(Path.cwd()),
CHROOT_SRCDIR="/work/src",
BUILDROOT=str(state.root),
WITH_TESTS=one_zero(state.config.with_tests),
WITH_NETWORK=one_zero(state.config.with_network),
SCRIPT="/work/build-script",
+ CHROOT_SCRIPT="/work/build-script",
SRCDIR=str(Path.cwd()),
CHROOT_SRCDIR="/work/src",
DESTDIR=str(state.install_dir),
env = dict(
SCRIPT="/work/postinst",
+ CHROOT_SCRIPT="/work/postinst",
SRCDIR=str(Path.cwd()),
CHROOT_SRCDIR="/work/src",
OUTPUTDIR=str(state.staging),
env = dict(
SCRIPT="/work/finalize",
+ CHROOT_SCRIPT="/work/finalize",
SRCDIR=str(Path.cwd()),
CHROOT_SRCDIR="/work/src",
OUTPUTDIR=str(state.staging),
Scripts executed by mkosi receive the following environment variables:
-* `$SCRIPT` contains the path to the running script relative to the
- image root directory. The primary usecase for this variable is in
+* `$CHROOT_SCRIPT` contains the path to the running script relative to
+ the image root directory. The primary usecase for this variable is in
combination with the `mkosi-chroot` script. See the description of
`mkosi-chroot` below for more information.
* `mkosi-chroot`: This script will chroot into the image and execute the
given command. On top of chrooting into the image, it will also mount
various files and directories (`$SRCDIR`, `$DESTDIR`, `$BUILDDIR`,
- `$OUTPUTDIR`, `$SCRIPT`) into the image and modify the corresponding
- environment variables to point to the locations inside the image. It
- will also mount APIVFS filesystems (`/proc`, `/dev`, ...) to make sure
- scripts and tools executed inside the chroot work properly. It also
- propagates `/etc/resolv.conf` from the host into the chroot if
- requested so that DNS resolution works inside the chroot. After the
- mkosi-chroot command exits, various mount points are cleaned up.
+ `$OUTPUTDIR`, `$CHROOT_SCRIPT`) into the image and modify the
+ corresponding environment variables to point to the locations inside
+ the image. It will also mount APIVFS filesystems (`/proc`, `/dev`,
+ ...) to make sure scripts and tools executed inside the chroot work
+ properly. It also propagates `/etc/resolv.conf` from the host into the
+ chroot if requested so that DNS resolution works inside the chroot.
+ After the mkosi-chroot command exits, various mount points are cleaned
+ up.
To execute the entire script inside the image, put the following
snippet at the start of the script:
```sh
if [ "$container" != "mkosi" ]; then
- exec mkosi-chroot "$SCRIPT" "$@"
+ exec mkosi-chroot "$CHROOT_SCRIPT" "$@"
fi
```
#!/bin/sh
if [ "$container" != "mkosi" ]; then
- exec mkosi-chroot "$SCRIPT" "$@"
+ exec mkosi-chroot "$CHROOT_SCRIPT" "$@"
fi
cd $SRCDIR