diff --git a/Dockerfile b/Dockerfile index 9dd98ce..eba83cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,47 @@ -FROM ghcr.io/hassio-addons/debian-base:7.2.0 +# syntax=docker/dockerfile:1 + +FROM ghcr.io/linuxserver/baseimage-ubuntu:noble + +# set version label +ARG BUILD_DATE +ARG VERSION +ARG FOLDINGATHOME_RELEASE +LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" +LABEL maintainer="aptalca" + +#Add needed nvidia environment variables for container toolkit +ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" + +# global environment settings +ENV DEBIAN_FRONTEND="noninteractive" + RUN \ - echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - curl \ - ca-certificates \ - gnupg && \ - curl -sSL https://download.foldingathome.org/releases/public/fah-client/debian-10-64bit/release/fah-client_8.4.9_amd64.deb -o /fahclient.deb && \ - echo "Installing fahclient..." && \ - dpkg -i /fahclient.deb && \ - apt-get install -f -y && \ - echo "Verifying installation..." && \ - ls -l /usr/bin/fahclient || echo "fahclient not found" && \ - rm /fahclient.deb && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* -COPY rootfs / + echo "**** install runtime packages ****" && \ + apt-get update && \ + apt-get install -y \ + bzip2 \ + intel-opencl-icd \ + libexpat1 && \ + ln -s libOpenCL.so.1 /usr/lib/x86_64-linux-gnu/libOpenCL.so && \ + echo "**** install foldingathome ****" && \ + download_url="https://download.foldingathome.org/releases/public/fah-client/"$(curl -s https://download.foldingathome.org/releases/public/fah-client/meta.json | jq -r '.[] | select((.package | contains("debian")) and (.package | contains("release"))) | .package' | grep -v "arm64" | grep "tar.bz2") && \ + curl -o \ + /tmp/fah.tar.bz2 -L \ + ${download_url} && \ + tar xf /tmp/fah.tar.bz2 -C /app --strip-components=1 && \ + printf "Linuxserver.io version: ${VERSION}\nBuild-date: ${BUILD_DATE}" > /build_version && \ + echo "**** cleanup ****" && \ + apt-get clean && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* \ + /var/log/* + +# add local files +COPY root/ / + +# ports and volumes EXPOSE 7396 -CMD ["/usr/bin/fahclient", "--config", "/config/config.xml", "${CLI_ARGS}"] \ No newline at end of file + +VOLUME /config \ No newline at end of file diff --git a/root/etc/OpenCL/vendors/nvidia.icd b/root/etc/OpenCL/vendors/nvidia.icd new file mode 100644 index 0000000..9712af9 --- /dev/null +++ b/root/etc/OpenCL/vendors/nvidia.icd @@ -0,0 +1 @@ +libnvidia-opencl.so.1 diff --git a/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-foldingathome-video b/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-foldingathome-video new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/dependencies.d/init-config b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/dependencies.d/init-config new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/run b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/run new file mode 100755 index 0000000..ca1fb3c --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/run @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +# permissions on config root and folders +lsiown -R abc:abc \ + /config diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/type b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/type @@ -0,0 +1 @@ +oneshot diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/up b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/up new file mode 100644 index 0000000..c136ca7 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-config/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-foldingathome-config/run diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/dependencies.d/init-foldingathome-config b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/dependencies.d/init-foldingathome-config new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/run b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/run new file mode 100755 index 0000000..436acf6 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/run @@ -0,0 +1,36 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +FILES=$(find /dev/dri /dev/dvb -type c -print 2>/dev/null) + +for i in $FILES +do + VIDEO_GID=$(stat -c '%g' "${i}") + VIDEO_UID=$(stat -c '%u' "${i}") + # check if user matches device + if id -u abc | grep -qw "${VIDEO_UID}"; then + echo "**** permissions for ${i} are good ****" + else + # check if group matches and that device has group rw + if id -G abc | grep -qw "${VIDEO_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then + echo "**** permissions for ${i} are good ****" + # check if device needs to be added to video group + elif ! id -G abc | grep -qw "${VIDEO_GID}"; then + # check if video group needs to be created + VIDEO_NAME=$(getent group "${VIDEO_GID}" | awk -F: '{print $1}') + if [ -z "${VIDEO_NAME}" ]; then + VIDEO_NAME="video$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)" + groupadd "${VIDEO_NAME}" + groupmod -g "${VIDEO_GID}" "${VIDEO_NAME}" + echo "**** creating video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" + fi + echo "**** adding ${i} to video group ${VIDEO_NAME} with id ${VIDEO_GID} ****" + usermod -a -G "${VIDEO_NAME}" abc + fi + # check if device has group rw + if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then + echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****" + chmod g+rw "${i}" + fi + fi +done diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/type b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/type @@ -0,0 +1 @@ +oneshot diff --git a/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/up b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/up new file mode 100644 index 0000000..a488a77 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-foldingathome-video/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-foldingathome-video/run diff --git a/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/dependencies.d/init-services b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/dependencies.d/init-services new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/notification-fd b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/notification-fd new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/notification-fd @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/run b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/run new file mode 100755 index 0000000..5fa5280 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/run @@ -0,0 +1,27 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +if [[ -n "${ACCOUNT_TOKEN}" ]] && [[ -n "${MACHINE_NAME}" ]]; then + TOKEN_AND_NAME="--account-token ${ACCOUNT_TOKEN} --machine-name ${MACHINE_NAME}" +else + echo ' +*************************************************************************** +*************************************************************************** +**** **** +**** **** +**** On first run, both the ACCOUNT_TOKEN and the MACHINE_NAME **** +**** env vars are required. Please set them and recreate the container **** +**** unless the instance was previously added to online account. **** +**** **** +**** **** +*************************************************************************** +*************************************************************************** +' +fi + + +exec \ + s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 7396" \ + cd /config s6-setuidgid abc /app/fah-client \ + --http-addresses 0.0.0.0:7396 --allow 0/0 ${TOKEN_AND_NAME} \ + ${CLI_ARGS} diff --git a/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/type b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-foldingathome/type @@ -0,0 +1 @@ +longrun diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-foldingathome-config b/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-foldingathome-config new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-foldingathome-video b/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-foldingathome-video new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-foldingathome b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-foldingathome new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/cont-init.d/00-config b/rootfs/etc/s6-overlay/cont-init.d/00-config deleted file mode 100755 index ee6a6f1..0000000 --- a/rootfs/etc/s6-overlay/cont-init.d/00-config +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/with-contenv bash -CONFIG_PATH=/config -mkdir -p "$CONFIG_PATH" -if [ ! -f "$CONFIG_PATH/config.xml" ]; then - cat > "$CONFIG_PATH/config.xml" << EOC - - - - - - - - - - -EOC - echo "Config created at $CONFIG_PATH/config.xml" -fi -if [ -n "$CLI_ARGS" ]; then - export CLI_ARGS -fi \ No newline at end of file