Skip to content
Snippets Groups Projects
Unverified Commit e721db9a authored by aptalca's avatar aptalca Committed by GitHub
Browse files

Merge pull request #57 from linuxserver/xenial-mod

update mod logic
parents 03e08980 4e84b60f
No related branches found
No related tags found
No related merge requests found
FROM alpine:3.9 as rootfs-stage FROM alpine:3.9 as rootfs-stage
MAINTAINER sparkyballs,thelamer
# environment # environment
ENV REL=xenial ENV REL=xenial
...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ /
ARG BUILD_DATE ARG BUILD_DATE
ARG VERSION ARG VERSION
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL MAINTAINER="sparkyballs,TheLamer" LABEL MAINTAINER="TheLamer"
# set version for s6 overlay # set version for s6 overlay
ARG OVERLAY_VERSION="v1.22.0.0" ARG OVERLAY_VERSION="v1.22.0.0"
......
FROM alpine:3.9 as rootfs-stage FROM alpine:3.9 as rootfs-stage
MAINTAINER sparkyballs,thelamer
# environment # environment
ENV REL=xenial ENV REL=xenial
...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ /
ARG BUILD_DATE ARG BUILD_DATE
ARG VERSION ARG VERSION
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL MAINTAINER="sparkyballs,TheLamer" LABEL MAINTAINER="TheLamer"
# set version for s6 overlay # set version for s6 overlay
ARG OVERLAY_VERSION="v1.22.0.0" ARG OVERLAY_VERSION="v1.22.0.0"
......
FROM alpine:3.9 as rootfs-stage FROM alpine:3.9 as rootfs-stage
MAINTAINER sparkyballs,thelamer
# environment # environment
ENV REL=xenial ENV REL=xenial
...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ / ...@@ -28,7 +27,7 @@ COPY --from=rootfs-stage /root-out/ /
ARG BUILD_DATE ARG BUILD_DATE
ARG VERSION ARG VERSION
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL MAINTAINER="sparkyballs,TheLamer" LABEL MAINTAINER="TheLamer"
# set version for s6 overlay # set version for s6 overlay
ARG OVERLAY_VERSION="v1.22.0.0" ARG OVERLAY_VERSION="v1.22.0.0"
......
...@@ -20,15 +20,66 @@ if [ ! -f /usr/bin/curl ]; then ...@@ -20,15 +20,66 @@ if [ ! -f /usr/bin/curl ]; then
fi fi
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 # Main run logic
echo "[mod-init] Attempting to run Docker Modification Logic" echo "[mod-init] Attempting to run Docker Modification Logic"
IFS='|' IFS='|'
DOCKER_MODS=(${DOCKER_MODS}) DOCKER_MODS=(${DOCKER_MODS})
for DOCKER_MOD in "${DOCKER_MODS[@]}"; do for DOCKER_MOD in "${DOCKER_MODS[@]}"; do
FILENAME=$(echo ${DOCKER_MOD} | sed 's/[:\/]/./g') # Support alternative endpoints
ENDPOINT=$(echo ${DOCKER_MOD} | awk -F: '{print $1}') if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then
USERNAME=$(echo ${ENDPOINT} | awk -F/ '{print $1}') DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}"
TAG=$(echo ${DOCKER_MOD} | awk -F: '{print $2}') 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 # Kill off modification logic if any of the usernames are banned
BLACKLIST=$(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt) BLACKLIST=$(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt)
IFS=$'\n' IFS=$'\n'
...@@ -49,20 +100,11 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do ...@@ -49,20 +100,11 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do
"$(curl \ "$(curl \
--silent \ --silent \
--header 'GET' \ --header 'GET' \
"https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" \ "${AUTH_URL}" \
| awk -F'"' '{print $4}' \ | awk -F'"' '{print $4}' \
)" )"
# Determine first and only layer of image # Determine first and only layer of image
SHALAYER=\ SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}")
"$(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}' \
)"
# Check if we have allready applied this layer # Check if we have allready applied this layer
if [ -f "/${FILENAME}" ] && [ "${SHALAYER}" == "$(cat /${FILENAME})" ]; then if [ -f "/${FILENAME}" ] && [ "${SHALAYER}" == "$(cat /${FILENAME})" ]; then
echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping"
...@@ -73,7 +115,7 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do ...@@ -73,7 +115,7 @@ for DOCKER_MOD in "${DOCKER_MODS[@]}"; do
--location \ --location \
--request GET \ --request GET \
--header "Authorization: Bearer ${TOKEN}" \ --header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/${ENDPOINT}/blobs/${SHALAYER}" \ "${BLOB_URL}${SHALAYER}" \
| tar xz -C / | tar xz -C /
echo ${SHALAYER} > "/${FILENAME}" echo ${SHALAYER} > "/${FILENAME}"
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment