diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cdd7c19 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.sh diff --git a/config-default.sh b/config-default.sh new file mode 100644 index 0000000..82c58f0 --- /dev/null +++ b/config-default.sh @@ -0,0 +1,5 @@ +# Where should the home directories used in containers be persisted +HOMEDIR_STORAGE=$HOME/.local/share/dobu/homedir +# Whether btrfs subvolumes should be used for homes instead of +# normal subdirectories +HOMEDIR_IS_BTRFS=false diff --git a/dobu-run.sh b/dobu-run.sh index 0329494..7905a51 100755 --- a/dobu-run.sh +++ b/dobu-run.sh @@ -9,9 +9,11 @@ assert_prerequisites image_name="$(path_to_image_name "apps/$1")" # image_name is of the form dobu/xxxx, while for containers we want dobu-xxx container_name="${image_name/\//-}" +home_path="$HOMEDIR_STORAGE/$1" log "Image name: $image_name" log "Container name: $container_name" +log "Home directory path: $home_path" assert_image_exists "$image_name" @@ -28,6 +30,17 @@ fi # Make sure we have Sommelier running first ensure_sommelier +# Prepare $HOME for the container +if [ ! -d "$home_path" ]; then + if [ "$HOMEDIR_IS_BTRFS" == "true" ]; then + log "Creating $home_path as a btrfs subvolume" + btrfs subvol create "$home_path" + else + log "Creating $home_path" + mkdir -p "$home_path" + fi +fi + # The fun part: start the container! # Don't detach like we did with Sommelier, though podman run --rm --userns=keep-id:uid=1100,gid=1100 \ @@ -48,6 +61,8 @@ podman run --rm --userns=keep-id:uid=1100,gid=1100 \ `# Pass through PulseAudio` \ -v "$host_pulse":/xdg_runtime/pulse/native \ -e PULSE_SERVER=unix:/xdg_runtime/pulse/native \ + `# $HOME` \ + -v "$home_path":/home/user \ `# Miscellaneous` \ -e XDG_SESSION_TYPE=wayland \ -e TZ="$(date +%Z)" \ diff --git a/functions.sh b/functions.sh index 90fd390..9ecbc8d 100644 --- a/functions.sh +++ b/functions.sh @@ -6,6 +6,9 @@ script_path="$(dirname "$(realpath "$0")")" DOBU_TMP=/tmp/dobu +. "$script_path/config-default.sh" +[ -f "$script_path/config.sh" ] && . "$script_path/config.sh" + assert_prerequisites() { command -v podman >/dev/null 2>&1 || die "Podman is required" [ -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ] || die "Dobu must be run under a compliant Wayland compositor"