diff --git a/Dockerfile b/Dockerfile index bd1a6ce..bd05946 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,28 +17,40 @@ LABEL maintainer="aptalca" ENV PYTHON_EGG_CACHE="/config/plugins/.python-eggs" \ TMPDIR=/run/deluged-temp +# copy release version script +COPY root/version.sh /app + # install software RUN \ echo "**** install build packages ****" && \ apk add --no-cache --upgrade --virtual=build-dependencies \ build-base \ - python3-dev && \ + python3-dev \ + musl-dev \ + git \ + py3-cairo \ + py3-gobject3 \ + py3-zope-interface && \ echo "**** install packages ****" && \ apk add --no-cache --upgrade \ boost1.84-python3 \ geoip \ - python3 \ p7zip && \ - if [ -z ${DELUGE_VERSION+x} ]; then \ - DELUGE_VERSION=$(curl -sL https://pypi.python.org/pypi/deluge/json |jq -r '. | .info.version');\ - fi && \ python3 -m venv /lsiopy && \ pip install -U --no-cache-dir \ pip \ setuptools \ wheel && \ + mkdir /app/deluge-src && \ + git clone https://github.com/deluge-torrent/deluge.git /app/deluge-src/ && \ + cd /app/deluge-src && \ + sh /app/version.sh > /app/deluge-src/RELEASE-VERSION && \ + sed -i '/libtorrent/d' /app/deluge-src/requirements*.txt && \ + sed -i "s|VERSION_FILE = os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION')|VERSION_FILE = '/app/deluge-src/RELEASE-VERSION'|" /app/deluge-src/version.py && \ + sed -i '/version = call_git_describe(prefix, suffix)/s/version = call_git_describe(prefix, suffix)/version = release_version/' /app/deluge-src/version.py && \ + pip install -r /app/deluge-src/requirements-dev.txt && \ + python3 /app/deluge-src/setup.py develop && \ pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.20/ \ - deluge[all]==${DELUGE_VERSION} \ pygeoip && \ echo "**** grab GeoIP database ****" && \ curl -L --retry 10 --retry-max-time 60 --retry-all-errors \ @@ -49,12 +61,12 @@ RUN \ apk del --purge \ build-dependencies && \ rm -rf \ - $HOME/.cache \ + $HOME/.cache \ /tmp/* - COPY --from=libtorrent /libtorrent-build/usr/lib/libtorrent-rasterbar.* /usr/lib/ +COPY --from=libtorrent /libtorrent-build/usr/lib/libtorrent-rasterbar.* /usr/lib/ - COPY --from=libtorrent /libtorrent-build/usr/lib/python3.12 /lsiopy/lib/python3.12 +COPY --from=libtorrent /libtorrent-build/usr/lib/python3.12 /lsiopy/lib/python3.12 # add local files COPY root/ / diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 1d84f5d..3238bfb 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -17,28 +17,40 @@ LABEL maintainer="aptalca" ENV PYTHON_EGG_CACHE="/config/plugins/.python-eggs" \ TMPDIR=/run/deluged-temp +# copy release version script +COPY root/version.sh /app + # install software RUN \ echo "**** install build packages ****" && \ apk add --no-cache --upgrade --virtual=build-dependencies \ build-base \ - python3-dev && \ + python3-dev \ + musl-dev \ + git \ + py3-cairo \ + py3-gobject3 \ + py3-zope-interface && \ echo "**** install packages ****" && \ apk add --no-cache --upgrade \ boost1.84-python3 \ geoip \ - python3 \ p7zip && \ - if [ -z ${DELUGE_VERSION+x} ]; then \ - DELUGE_VERSION=$(curl -sL https://pypi.python.org/pypi/deluge/json |jq -r '. | .info.version');\ - fi && \ python3 -m venv /lsiopy && \ pip install -U --no-cache-dir \ pip \ setuptools \ wheel && \ + mkdir /app/deluge-src && \ + git clone https://github.com/deluge-torrent/deluge.git /app/deluge-src/ && \ + cd /app/deluge-src && \ + sh /app/version.sh > /app/deluge-src/RELEASE-VERSION && \ + sed -i '/libtorrent/d' /app/deluge-src/requirements*.txt && \ + sed -i "s|VERSION_FILE = os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION')|VERSION_FILE = '/app/deluge-src/RELEASE-VERSION'|" /app/deluge-src/version.py && \ + sed -i '/version = call_git_describe(prefix, suffix)/s/version = call_git_describe(prefix, suffix)/version = release_version/' /app/deluge-src/version.py && \ + pip install -r /app/deluge-src/requirements-dev.txt && \ + python3 /app/deluge-src/setup.py develop && \ pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.20/ \ - deluge[all]==${DELUGE_VERSION} \ pygeoip && \ echo "**** grab GeoIP database ****" && \ curl -L --retry 10 --retry-max-time 60 --retry-all-errors \ @@ -49,12 +61,12 @@ RUN \ apk del --purge \ build-dependencies && \ rm -rf \ - $HOME/.cache \ + $HOME/.cache \ /tmp/* - COPY --from=libtorrent /libtorrent-build/usr/lib/libtorrent-rasterbar.* /usr/lib/ +COPY --from=libtorrent /libtorrent-build/usr/lib/libtorrent-rasterbar.* /usr/lib/ - COPY --from=libtorrent /libtorrent-build/usr/lib/python3.12 /lsiopy/lib/python3.12 +COPY --from=libtorrent /libtorrent-build/usr/lib/python3.12 /lsiopy/lib/python3.12 # add local files COPY root/ / diff --git a/root/etc/s6-overlay/s6-rc.d/svc-deluged/run b/root/etc/s6-overlay/s6-rc.d/svc-deluged/run index 2ec50c9..9fe296f 100755 --- a/root/etc/s6-overlay/s6-rc.d/svc-deluged/run +++ b/root/etc/s6-overlay/s6-rc.d/svc-deluged/run @@ -3,6 +3,30 @@ DELUGE_LOGLEVEL=${DELUGE_LOGLEVEL:-info} +# downlad latest GeoIP.dat after aged a week +geoip_dat_path="/usr/share/GeoIP/GeoIP.dat" +echo "[info] Checking GeoIP.dat ($geoip_dat_path)..." + +if [ -e "$geoip_dat_path" ]; then + current_time=$(date +%s) + # file's modification and creation times in seconds since epoch + modification_time=$(stat -c %Y "$geoip_dat_path") + creation_time=$(stat -c %W "$geoip_dat_path") + week_seconds=$((7 * 24 * 60 * 60)) + + if (((current_time - modification_time) > week_seconds)) || (((current_time - creation_time) > week_seconds)); then + echo "[info] Found outdated GeoIP.dat...updating (timeout 30s)" + curl -s -L --retry 3 --retry-max-time 30 --retry-all-errors \ + "https://mailfud.org/geoip-legacy/GeoIP.dat.gz" | + gunzip >$geoip_dat_path + fi +else + echo "[info] No GeoIP.dat found...updating (timeout 30s)" + curl -s -L --retry 3 --retry-max-time 30 --retry-all-errors \ + "https://mailfud.org/geoip-legacy/GeoIP.dat.gz" | + gunzip >$geoip_dat_path +fi + if [[ -f /config/core.conf ]]; then DELUGED_PORT=$(grep '"daemon_port"' /config/core.conf | tr -cd "[:digit:]") fi diff --git a/root/etc/s6-overlay/s6-rc.d/version.sh b/root/etc/s6-overlay/s6-rc.d/version.sh new file mode 100644 index 0000000..76872d9 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/version.sh @@ -0,0 +1,35 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +prefix="deluge-" +suffix=".dev0" +cmd="git describe --tags --match ${prefix}[0-9]*" + +if output=$(eval "$cmd" 2>/dev/null); then + version="${output#"$prefix"}" + version="${version%"$suffix"}" + # Check if there is a dash in the version string + if [[ "$version" == *"-"* ]]; then + # Determine the segment type + segment=".dev" + if [[ "$version" != *"dev"* ]]; then + segment=".post" + fi + + # Process the version string to format it correctly + version=$(echo "$version" | awk -F'-' -v seg="$segment" ' + { + # Remove the last group after the final dot + split($1, parts, ".") + n = length(parts) + if (n > 1) { + $1 = parts[1] "." parts[2] "." parts[3] seg substr($2,1,3) + } + print $1 + }') + fi + + echo "$version" +else + echo "None" +fi