1
0
forked from wrenn/wrenn

WIP: Add socat injection to rootfs build scripts

Inject a statically-linked socat binary into rootfs images. envd's
port forwarder requires socat to bridge localhost-listening services
(e.g. Jupyter kernel) to the guest TAP interface.

Both scripts follow the same 3-step resolution: check rootfs, check
host, build from source (http://www.dest-unreach.org/socat/ v1.8.1.1).
Static linkage is verified before injection.

This is an intermediate state — needs further work for the full code
interpreter feature.
This commit is contained in:
2026-03-26 02:11:54 +06:00
parent 8cdf91d895
commit 602ee470d9
2 changed files with 76 additions and 5 deletions

View File

@ -96,10 +96,45 @@ sudo mkdir -p "${MOUNT_DIR}/sbin"
sudo cp "${TINI_BIN}" "${MOUNT_DIR}/sbin/tini"
sudo chmod 755 "${MOUNT_DIR}/sbin/tini"
echo "==> Installing socat..."
SOCAT_BIN=""
# 1. Already in the rootfs?
for p in "${MOUNT_DIR}/usr/bin/socat" "${MOUNT_DIR}/usr/local/bin/socat"; do
if [ -f "$p" ]; then SOCAT_BIN="$p"; break; fi
done
# 2. Available on the host?
if [ -z "${SOCAT_BIN}" ]; then
for p in /usr/bin/socat /usr/local/bin/socat; do
if [ -f "$p" ]; then SOCAT_BIN="$p"; break; fi
done
fi
# 3. Build from source.
if [ -z "${SOCAT_BIN}" ]; then
SOCAT_VERSION="1.8.1.1"
SOCAT_URL="http://www.dest-unreach.org/socat/download/socat-${SOCAT_VERSION}.tar.gz"
SOCAT_BUILD_DIR="/tmp/socat-build"
echo " Building socat ${SOCAT_VERSION} from source..."
rm -rf "${SOCAT_BUILD_DIR}"
mkdir -p "${SOCAT_BUILD_DIR}"
curl -fsSL "${SOCAT_URL}" | tar xz -C "${SOCAT_BUILD_DIR}" --strip-components=1
(cd "${SOCAT_BUILD_DIR}" && LDFLAGS="-static" ./configure --quiet && make -j"$(nproc)" -s)
SOCAT_BIN="${SOCAT_BUILD_DIR}/socat"
if [ ! -f "${SOCAT_BIN}" ]; then
echo "ERROR: socat build failed"
exit 1
fi
if ! file "${SOCAT_BIN}" | grep -q "statically linked"; then
echo "ERROR: socat is not statically linked!"
exit 1
fi
fi
sudo cp "${SOCAT_BIN}" "${MOUNT_DIR}/usr/local/bin/socat"
sudo chmod 755 "${MOUNT_DIR}/usr/local/bin/socat"
# Step 4: Verify.
echo ""
echo "==> Installed files:"
ls -la "${MOUNT_DIR}/usr/local/bin/envd" "${MOUNT_DIR}/usr/local/bin/wrenn-init" "${MOUNT_DIR}/sbin/tini"
ls -la "${MOUNT_DIR}/usr/local/bin/envd" "${MOUNT_DIR}/usr/local/bin/wrenn-init" "${MOUNT_DIR}/sbin/tini" "${MOUNT_DIR}/usr/local/bin/socat"
echo ""
echo "==> Done. Rootfs updated: ${ROOTFS}"