diff --git a/Dockerfile b/Dockerfile index d5a1b642c423d60360d81a19aaf7e8d1374d1cd9..3d5c8b8e31ed3c4dcc9e38a826d26201ae6ea601 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM alpine:3.9 as rootfs-stage -MAINTAINER sparkyballs,thelamer # environment ENV REL=xenial @@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ARG BUILD_DATE ARG VERSION LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" -LABEL MAINTAINER="sparkyballs,TheLamer" +LABEL MAINTAINER="TheLamer" # set version for s6 overlay ARG OVERLAY_VERSION="v1.22.0.0" diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index c103b768065815b0103ec6e0f336695c371c6590..8bcdea23e24b3cae3292770543fcd1013f2cec6f 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -1,5 +1,4 @@ FROM alpine:3.9 as rootfs-stage -MAINTAINER sparkyballs,thelamer # environment ENV REL=xenial @@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ARG BUILD_DATE ARG VERSION LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" -LABEL MAINTAINER="sparkyballs,TheLamer" +LABEL MAINTAINER="TheLamer" # set version for s6 overlay ARG OVERLAY_VERSION="v1.22.0.0" diff --git a/Dockerfile.armhf b/Dockerfile.armhf index ed0168d9b8c29d52cb9da82b5bf4e9cf72e7efca..cb526f317447d489a4b172d7de26098f9f7c6388 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -1,5 +1,4 @@ FROM alpine:3.9 as rootfs-stage -MAINTAINER sparkyballs,thelamer # environment ENV REL=xenial @@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ARG BUILD_DATE ARG VERSION LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" -LABEL MAINTAINER="sparkyballs,TheLamer" +LABEL MAINTAINER="TheLamer" # set version for s6 overlay ARG OVERLAY_VERSION="v1.22.0.0" diff --git a/root/docker-mods b/root/docker-mods index c90e5a47b9f6431b3583ed406c0983ae2fe7bd85..4059a0b81559fd07629f236ab19857d5064ed2b1 100755 --- a/root/docker-mods +++ b/root/docker-mods @@ -20,15 +20,66 @@ if [ ! -f /usr/bin/curl ]; then fi fi +## Functions + +# Use different filtering depending on URL +get_blob_sha () { + if [[ $1 == "ghcr" ]]; then + curl \ + --silent \ + --location \ + --request GET \ + --header "Authorization: Bearer $2" \ + $3 |\ + grep -A4 'layers' |\ + grep -m1 'digest' |\ + awk -F'"' '{print $4}' + else + curl \ + --silent \ + --location \ + --request GET \ + --header "Authorization: Bearer $2" \ + $3 |\ + grep -m1 "blobSum" |\ + awk -F'"' '{print $4}' + fi +} + # Main run logic echo "[mod-init] Attempting to run Docker Modification Logic" IFS='|' DOCKER_MODS=(${DOCKER_MODS}) for DOCKER_MOD in "${DOCKER_MODS[@]}"; do - FILENAME=$(echo ${DOCKER_MOD} | sed 's/[:\/]/./g') - ENDPOINT=$(echo ${DOCKER_MOD} | awk -F: '{print $1}') - USERNAME=$(echo ${ENDPOINT} | awk -F/ '{print $1}') - TAG=$(echo ${DOCKER_MOD} | awk -F: '{print $2}') + # Support alternative endpoints + if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then + DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" + ENDPOINT="${DOCKER_MOD%%:*}" + USERNAME="${DOCKER_MOD%%/*}" + REPO="${ENDPOINT#*/}" + TAG="${DOCKER_MOD#*:}" + if [[ ${TAG} == "${DOCKER_MOD}" ]]; then + TAG="latest" + fi + FILENAME="${USERNAME}.${REPO}.${TAG}" + AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull" + MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}" + BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/" + MODE="ghcr" + else + ENDPOINT="${DOCKER_MOD%%:*}" + USERNAME="${DOCKER_MOD%%/*}" + REPO="${ENDPOINT#*/}" + TAG="${DOCKER_MOD#*:}" + if [[ ${TAG} == "${DOCKER_MOD}" ]]; then + TAG="latest" + fi + FILENAME="${USERNAME}.${REPO}.${TAG}" + AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" + MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}" + BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/" + MODE="dockerhub" + fi # Kill off modification logic if any of the usernames are banned BLACKLIST=$(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt) IFS=$'\n' @@ -49,20 +100,11 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do "$(curl \ --silent \ --header 'GET' \ - "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" \ + "${AUTH_URL}" \ | awk -F'"' '{print $4}' \ )" # Determine first and only layer of image - SHALAYER=\ -"$(curl \ - --silent \ - --location \ - --request GET \ - --header "Authorization: Bearer ${TOKEN}" \ - https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG} \ - |grep -m1 "blobSum" \ - | awk -F'"' '{print $4}' \ - )" + SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}") # Check if we have allready applied this layer if [ -f "/${FILENAME}" ] && [ "${SHALAYER}" == "$(cat /${FILENAME})" ]; then echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" @@ -73,7 +115,7 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do --location \ --request GET \ --header "Authorization: Bearer ${TOKEN}" \ - "https://registry-1.docker.io/v2/${ENDPOINT}/blobs/${SHALAYER}" \ + "${BLOB_URL}${SHALAYER}" \ | tar xz -C / echo ${SHALAYER} > "/${FILENAME}" fi