diff --git a/Dockerfile b/Dockerfile index 57d528d..1d91ee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,9 @@ ENV PATH /system/bin # Copy libc, linker and few utilities. COPY /system/$SYSTEM_TYPE /system +# Copy entrypoint script. +COPY /entrypoint.sh /entrypoint.sh + # Extract bootstrap archive and create symlinks. ADD https://github.com/termux/termux-packages/releases/download/bootstrap-$BOOTSTRAP_VERSION/bootstrap-$BOOTSTRAP_ARCH.zip /bootstrap.zip RUN busybox mkdir -p /data/data/com.termux/files && \ @@ -84,4 +87,5 @@ WORKDIR /data/data/com.termux/files/home SHELL ["/data/data/com.termux/files/usr/bin/sh", "-c"] USER 1000:1000 +ENTRYPOINT ["/entrypoint.sh"] CMD ["/data/data/com.termux/files/usr/bin/login"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..86bc5b6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/system/bin/sh + +if [ "$(id -u)" = "0" ] && [ -z "$(/system/bin/busybox pidof dnsmasq)" ]; then + /system/bin/sh -T /dev/ptmx -c "/system/bin/dnsmasq -u root -g root --pid-file /dnsmasq.pid" >/dev/null 2>&1 + sleep 1 + if [ -z "$(/system/bin/busybox pidof dnsmasq)" ]; then + echo "[!] Failed to start dnsmasq, host name resolution may fail." >&2 + fi +else + echo "[!] Container is running as non-root, unable to start dnsmasq. DNS will be unavailable." >&2 +fi + +if [ $# -ge 1 ]; then + exec "$@" +else + if [ "$(id -u)" = "0" ]; then + exec /system/bin/su - system -c "/data/data/com.termux/files/usr/bin/login" + else + exec /data/data/com.termux/files/usr/bin/login + fi +fi