aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore9
-rw-r--r--Makefile32
-rw-r--r--container/Containerfile (renamed from Containerfile)6
-rwxr-xr-xcontainer/init (renamed from dbx-init)8
-rwxr-xr-xdbx33
-rwxr-xr-xdbx-create45
-rwxr-xr-xdbx-enter11
-rwxr-xr-xdbx-proxy17
-rwxr-xr-xdbx-start23
-rwxr-xr-xdbx-stop15
10 files changed, 29 insertions, 170 deletions
diff --git a/.gitignore b/.gitignore
index 0f8e6ab..33d3062 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,2 @@
-.container
-custom/extra-packages
-custom/post-install
-custom/skel/
-ssh/*.config
-ssh/*.known_hosts
-ssh/id_*
+dbx
+src/*.o
diff --git a/Makefile b/Makefile
index 7377817..6f6f205 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,26 @@
-DBX_IMAGE ?= dbx
+CC = cc
+CFLAGS = -Wall -Wextra -O2
+LDFLAGS =
+
+SRCS = $(shell find src -name '*.c')
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
+CONTAINER = $(if $(findstring Darwin,$(shell uname -s)),container,podman)
+IMAGE = dbx-next
.PHONY: all
-all: .container ssh/id_ed25519 ;
+all: dbx ;
+
+dbx: $(OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-.PHONY: install
-install: all
- mkdir -p $(HOME)/.local/bin
- ln -s $(PWD)/dbx $(HOME)/.local/bin/dbx
+%.o: %.c src/dbx.h
+ $(CC) $(CFLAGS) -c -o $@ $<
-.container: Containerfile dbx-init ssh/id_ed25519.pub
- container build --pull --tag $(DBX_IMAGE) .
- touch $@
+.PHONY: container
+container: container/Containerfile container/init
+ $(CONTAINER) build --tag $(IMAGE) container
-ssh/id_% ssh/id_%.pub:
- ssh-keygen -C "$$(id -un)@$$(hostname)" -f ssh/id_$* -N "" -t $*
+.PHONY: clean
+clean:
+ rm -f dbx src/*.o
diff --git a/Containerfile b/container/Containerfile
index 9f250dd..2498b12 100644
--- a/Containerfile
+++ b/container/Containerfile
@@ -19,10 +19,10 @@ RUN rm /etc/apt/apt.conf.d/docker-* && \
RUN update-locale LANG=C.UTF-8 LC_ALL=C.UTF-8
# Configure SSH server
-COPY ssh/id_ed25519.pub /etc/ssh/authorized_keys
RUN echo "StreamLocalBindUnlink yes" >> /etc/ssh/sshd_config && \
- echo "AuthorizedKeysFile /etc/ssh/authorized_keys" >> /etc/ssh/sshd_config
+ echo "AuthorizedKeysFile /etc/ssh/authorized_keys" >> /etc/ssh/sshd_config && \
+ touch /etc/ssh/authorized_keys
# Set up the entrypoint
-COPY dbx-init /sbin/init
+COPY init /sbin/init
ENTRYPOINT ["/sbin/init"]
diff --git a/dbx-init b/container/init
index 3877c92..24b6629 100755
--- a/dbx-init
+++ b/container/init
@@ -1,12 +1,10 @@
-#!/usr/bin/env bash
+#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-set -euo pipefail
-
-if [[ ! -f /run/.dbxenv ]]; then
+if [ ! -f /run/.dbxenv ]; then
echo "ERROR: not in a devbox" >&2
exit 1
fi
-exec tini /usr/sbin/sshd -- -D -e
+exec /usr/bin/tini /usr/sbin/sshd -- -D -e
diff --git a/dbx b/dbx
deleted file mode 100755
index 3402133..0000000
--- a/dbx
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-
-set -euo pipefail
-
-root="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
-
-usage() {
- cat <<EOF
-dbx - containerized development environments
-
-USAGE:
- dbx create creates the devbox
- dbx [enter] enters the devbox
- dbx proxy PORT proxies a devbox port to the host
- dbx start starts the devbox
- dbx stop stops the devbox
-EOF
-}
-
-cmd="${1:-enter}"
-shift || true
-
-case "$#:$cmd" in
- 0:create|0:enter|1:proxy|0:start|0:stop)
- "$root/dbx-$cmd" "$@"
- ;;
- *)
- usage
- exit 1
- ;;
-esac
diff --git a/dbx-create b/dbx-create
deleted file mode 100755
index ee96294..0000000
--- a/dbx-create
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-
-set -euo pipefail
-
-root="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
-machine="${DBX_MACHINE:-dbx}"
-image="${DBX_IMAGE:-dbx}"
-
-if ! container system status &>/dev/null; then
- container system start >/dev/null
-fi
-
-if container machine inspect "$machine" &>/dev/null; then
- echo "already created"
- exit
-fi
-
-container machine create \
- --name="$machine" \
- --no-boot \
- --home-mount=none \
- "$image" \
- >/dev/null
-
-# Perform the initial setup for the devbox
-"$root/dbx-start"
-if [ -f "$root/custom/extra-packages" ]; then
- container machine run --name="$machine" --root \
- apt-get update
- container machine run --name="$machine" --root \
- apt-get install -y $(cat "$root/custom/extra-packages")
-fi
-if [ -d "$root/custom/skel" ]; then
- home="$(container machine run --name="$machine" bash -c 'echo $HOME')"
- scp -F "$root/ssh/$machine.config" -r \
- "$root/custom/skel/." "$machine:$home"
-fi
-if [ -x "$root/custom/post-install" ]; then
- scp -F "$root/ssh/$machine.config" -r \
- "$root/custom/post-install" "$machine:/tmp/post-install"
- container machine run --name="$machine" /tmp/post-install
- container machine run --name="$machine" rm /tmp/post-install
-fi
diff --git a/dbx-enter b/dbx-enter
deleted file mode 100755
index 49078b4..0000000
--- a/dbx-enter
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-
-set -euo pipefail
-
-root="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
-machine="${DBX_MACHINE:-dbx}"
-
-"$root/dbx-start"
-exec ssh "$machine" -F "$root/ssh/$machine.config"
diff --git a/dbx-proxy b/dbx-proxy
deleted file mode 100755
index 67e0456..0000000
--- a/dbx-proxy
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-
-set -euo pipefail
-
-if [[ $# -ne 1 ]]; then
- echo "ERROR: missing port to proxy" >&2
- exit 1
-fi
-
-root="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
-machine="${DBX_MACHINE:-dbx}"
-port="$1"
-
-"$root/dbx-start"
-exec ssh "$machine" -F "$root/ssh/$machine.config" \
- -L "localhost:$port:localhost:$port" -N
diff --git a/dbx-start b/dbx-start
deleted file mode 100755
index 1b602e1..0000000
--- a/dbx-start
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-
-set -euo pipefail
-
-root="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
-machine="${DBX_MACHINE:-dbx}"
-
-if ! container system status &>/dev/null; then
- container system start >/dev/null
-fi
-
-container machine run --name="$machine" true >/dev/null
-
-# The IP address assigned to the machine changes on restarts, so update the SSH
-# configuration with the current value.
-ip="$(container machine inspect "$machine" | jq -r '.[0].ipAddress')"
-cat "$root/ssh/config.in" \
- | sed -e 's|$ROOT|'"$root"'|g' \
- | sed -e 's|$MACHINE|'"$machine"'|g' \
- | sed -e 's|$IP|'"$ip"'|g' \
- >"$root/ssh/$machine.config"
diff --git a/dbx-stop b/dbx-stop
deleted file mode 100755
index dcef4a2..0000000
--- a/dbx-stop
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: GPL-3.0-only
-# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]>
-
-set -euo pipefail
-
-machine="${DBX_MACHINE:-dbx}"
-
-if ! container system status &>/dev/null; then
- exit 0
-fi
-
-container machine stop "$machine" &>/dev/null \
- || true
-container system stop >/dev/null