#!/bin/bash set -Eeuo pipefail if [[ -d "/secrets" ]]; then /usr/local/bin/devbox-template fi # Add some /dev devices [ -e /dev/loop-control ] || mknod /dev/loop-control c 10 237 for i in {0..7}; do [ -e "/dev/loop$i" ] || mknod "/dev/loop$i" b 7 $i done # Podman's overlay storage driver cannot live on virtiofs, so those graphroots # get a loop-mounted ext4 instead. Runs as root and hands the result to owner, # who is the user that will run podman on it. function overlay_fs() { local storage="$1" img="$2" owner="$3" local size="${DEVBOX_STORAGE_SIZE:-40G}" fstype loop mkdir -p "$storage" # df has to run after the mkdir, it fails on a path that does not exist, and # it pads its columns with runs of spaces, so the type has to come from awk # rather than `cut -d' '`. fstype="$(df -PT "$storage" | tail -1 | awk '{print $2}')" case "$fstype" in virtiofs | 9p | fuse* | nfs* | cifs | overlay) ;; # ext2/3/4, xfs, btrfs, f2fs and tmpfs can all host an overlayfs natively. *) return 0 ;; esac if mountpoint -q "$storage"; then return 0 fi # Never truncate or format over an image that already holds a filesystem, # that is how a restart used to wipe every image and container. [ -e "$img" ] || truncate -s "$size" "$img" blkid "$img" >/dev/null 2>&1 || mkfs.ext4 -qF -O dir_index,extent,has_journal "$img" loop="$(losetup -f --show "$img")" if ! mount -o noatime "$loop" "$storage"; then losetup -d "$loop" exit 1 fi # Nested containers need shared propagation, or podman's mounts are invisible # in the namespaces it creates. Failing here means the outer container was # started without it, so say so instead of carrying on. mount --make-rshared "$storage" chown -R "$owner" "$storage" } overlay_fs "/var/lib/containers/storage" "/var/tmp/containers.img" "root:root" overlay_fs "/home/dev/.local/share/containers/storage" "/home/dev/.local/share/containers/img" "dev:dev" su dev # if [[ -z "${PASEO_PASSWORD:-}" ]]; then # echo "PASEO_PASSWORD is required" >&2 # exit 1 # fi # echo "[devbox] starting Paseo daemon on ${PASEO_LISTEN} (web UI: ${PASEO_WEB_UI_ENABLED})" # exec paseo daemon run exec /bin/bash