From e90c443bc75b5070b3fcf633252312fa7a89fe98 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Wed, 3 Jan 2024 17:26:33 +0000 Subject: [PATCH 1/9] Support arbitrary registries and sideloading mods --- docker-mods.v3 | 99 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 8db8b36..8e6635e 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -4,7 +4,7 @@ # Use /command/with-contenv shebang because /usr/bin/with-contenv is created in this script # Version 3 -# 2022-09-25 +# 2022-09-25 - Initial Release MOD_SCRIPT_VER="3" # Define custom folder paths @@ -189,6 +189,11 @@ curl_check() { fi } +write_debug() { + local MSG=$@ + if [[ ${DOCKER_MODS_DEBUG,,} = "true" ]]; then echo "[mod-init] (DEBUG) $MSG"; fi +} + # Use different filtering depending on URL get_blob_sha() { MULTIDIGEST=$(curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ @@ -227,6 +232,20 @@ get_blob_sha() { fi } +get_auth_url() { + # Call to get manifests and extract www-authenticate header + local auth_header=$(curl -sLI ${CURL_NOISE_LEVEL} "${1}/${2}" | grep -i www-authenticate | tr -d '\r') + if [[ -n "${auth_header}" ]]; then + # Extract realm URL from www-authenticate header + local realm_url=$(echo "$auth_header" | grep -oP 'realm="\K[^"]+') + local service=$(echo "$auth_header" | grep -oP 'service="\K[^"]+') + local scope=$(echo "$auth_header" | grep -oP 'scope="\K[^"]+') + echo "$realm_url?service=$service&scope=$scope" + else + exit 1 + fi +} + # Main run logic run_mods() { echo "[mod-init] Attempting to run Docker Modification Logic" @@ -244,24 +263,15 @@ run_mods() { [[ ${DOCKER_MODS_FORCE_REGISTRY,,} = "true" ]] && REGISTRY="ghcr.io" || REGISTRY="lscr.io" DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" ;; - lscr.io/* ) - REGISTRY="lscr.io" - DOCKER_MOD="${DOCKER_MOD#lscr.io/*}" - ;; - ghcr.io/* ) - REGISTRY="ghcr.io" - DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" - ;; - quay.io/* ) - REGISTRY="quay.io" - DOCKER_MOD="${DOCKER_MOD#quay.io/*}" - ;; - docker.io/* ) - REGISTRY="registry-1.docker.io" - DOCKER_MOD="${DOCKER_MOD#docker.io/*}" - ;; * ) - REGISTRY="registry-1.docker.io" + if [[ $DOCKER_MOD == */* ]]; then + REGISTRY="registry-1.docker.io" + MOD="${DOCKER_MOD%/*}" + fi + if [[ $MOD == */* ]]; then + REGISTRY="${MOD%%/*}" + DOCKER_MOD="${DOCKER_MOD#"$REGISTRY"/*}" + fi ;; esac ENDPOINT="${DOCKER_MOD%%:*}" @@ -275,12 +285,15 @@ run_mods() { MANIFEST_URL="https://${REGISTRY}/v2/${ENDPOINT}/manifests" BLOB_URL="https://${REGISTRY}/v2/${ENDPOINT}/blobs/" MOD_UA="Mozilla/5.0 (Linux $(uname -m)) linuxserver.io ${REGISTRY}/${ENDPOINT}:${TAG}" + write_debug "Registry='${REGISTRY}', Repository='${USERNAME}', Image='${ENDPOINT}', Tag='${TAG}'" case "${REGISTRY}" in "lscr.io") AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "ghcr.io") AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "quay.io") AUTH_URL="https://quay.io/v2/auth?service=quay.io&scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "registry-1.docker.io") AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull";; + *) get_auth_url "${MANIFEST_URL}" "${TAG}" esac + if [[ -z "${AUTH_URL}" ]]; then echo "[mod-init] Could not fetch auth URL from registry, skipping mod";fi # Kill off modification logic if any of the usernames are banned for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then @@ -304,6 +317,7 @@ run_mods() { # If we're using lscr try and get the manifest from ghcr, if it fails re-request a token from Docker Hub if [[ "${REGISTRY}" == "lscr.io" ]]; then if [[ -n $(curl --user-agent "${MOD_UA}" -sLH "Authorization: Bearer ${TOKEN}" "${MANIFEST_URL}/${TAG}" | jq -r '.errors' >/dev/null 2>&1) ]]; then + write_debug "Couldn't fetch manifest from ghcr.io, trying docker.io" AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" TOKEN="$( curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ @@ -314,9 +328,7 @@ run_mods() { )" fi fi - if [[ ${DOCKER_MODS_DEBUG,,} = "true" ]]; then - echo "[mod-init] Using ${AUTH_URL} as auth endpoint" - fi + write_debug "Using ${AUTH_URL} as auth endpoint" # Determine first and only layer of image SHALAYER=$(get_blob_sha "${TOKEN}" "${MANIFEST_URL}" "${TAG}") if [[ -z "${SHALAYER}" ]]; then @@ -363,17 +375,54 @@ run_mods() { done } +run_mods_local() { + echo "[mod-init] Attempting to run Local Docker Modification Logic" + for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do + # Check mod file exists + if [[ -n "$(/bin/ls -A "/mods/${DOCKER_MOD}.tar" 2>/dev/null)" ]]; then + # Caculate mod bits + FILENAME="${DOCKER_MOD}.local" + SHALAYER=$(sha256sum "/mods/${DOCKER_MOD}.tar" | cut -d " " -f 1) + # 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" + else + echo "[mod-init] Installing ${DOCKER_MOD}" + mkdir -p "/tmp/mod/${DOCKER_MOD}" + tar xf "/mods/${DOCKER_MOD}.tar" -C /tmp/mod --strip-components=1 + tar xf "/tmp/mod/layer.tar" -C "/tmp/mod/${DOCKER_MOD}" + if [[ -d "/tmp/mod/${DOCKER_MOD}/etc/s6-overlay" ]]; then + if [[ -d "/tmp/mod/${DOCKER_MOD}/etc/cont-init.d" ]]; then + rm -rf "/tmp/mod/${DOCKER_MOD}/etc/cont-init.d" + fi + if [[ -d "/tmp/mod/${DOCKER_MOD}/etc/services.d" ]]; then + rm -rf "/tmp/mod/${DOCKER_MOD}/etc/services.d" + fi + fi + shopt -s dotglob + cp -R "/tmp/mod/${DOCKER_MOD}"/* / + shopt -u dotglob + rm -rf "/tmp/mod/${DOCKER_MOD}" + echo "${SHALAYER}" >"/${FILENAME}.local" + echo "[mod-init] ${DOCKER_MOD} applied to container" + fi + else + echo "[mod-init] ${DOCKER_MOD}.tar not found in /mods, skipping" + fi + done +} + run_branding() { # intentional tabs in the heredoc cat <<-EOF >/etc/s6-overlay/s6-rc.d/init-adduser/branding ─────────────────────────────────────── - ██╗ ███████╗██╗ ██████╗ + ██╗ ███████╗██╗ ██████╗ ██║ ██╔════╝██║██╔═══██╗ ██║ ███████╗██║██║ ██║ ██║ ╚════██║██║██║ ██║ ███████╗███████║██║╚██████╔╝ - ╚══════╝╚══════╝╚═╝ ╚═════╝ + ╚══════╝╚══════╝╚═╝ ╚═════╝ Brought to you by linuxserver.io ─────────────────────────────────────── @@ -396,7 +445,9 @@ if [[ -d "${SCRIPTS_DIR}" ]] || [[ -d "${SERVICES_DIR}" ]]; then fi # Run mod logic -if [[ -n "${DOCKER_MODS+x}" ]]; then +if [[ -n "${DOCKER_MODS+x}" ]] && [[ "${DOCKER_MODS_SIDELOAD,,}" = "true" ]]; then + run_mods_local +elif [[ -n "${DOCKER_MODS+x}" ]]; then curl_check run_mods fi From 5ea39f43d0646b91d7348282b7d16686faf8aa7a Mon Sep 17 00:00:00 2001 From: TheSpad Date: Wed, 3 Jan 2024 17:46:06 +0000 Subject: [PATCH 2/9] Support images in the root of local registries --- docker-mods.v3 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 8e6635e..265f34f 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -264,13 +264,17 @@ run_mods() { DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" ;; * ) - if [[ $DOCKER_MOD == */* ]]; then - REGISTRY="registry-1.docker.io" - MOD="${DOCKER_MOD%/*}" - fi + # Default assumption is docker.io + REGISTRY="registry-1.docker.io" + MOD="${DOCKER_MOD%/*}" + # If mod still has a / after stripping off the image name it's not docker.io if [[ $MOD == */* ]]; then REGISTRY="${MOD%%/*}" DOCKER_MOD="${DOCKER_MOD#"$REGISTRY"/*}" + # If "repo" name has . in it, then assume it's actually a registry with no repo + elif [[ ${DOCKER_MOD%%/*} =~ \. ]]; then + REGISTRY="${DOCKER_MOD%%/*}" + MOD="${DOCKER_MOD##*/}" fi ;; esac From c2e6856ec2a9b06358832cb1eb63d2331451e264 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Wed, 3 Jan 2024 17:46:13 +0000 Subject: [PATCH 3/9] Update changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9ec1aad..f28ea38 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ These files are used by Linuxserver build processes to handle mods in our images. Not for end-user consumption. +* **03.01.24:** - Support arbitrary mod registries. * **14.09.23:** - Fix lsiown edge cases. * **08.09.23:** - Change lsiown to skip files that are already owned by the user. * **25.05.23:** - Add lscr.io support for mods. From b6cf5a35696718551b73b7da7373b65152f91b50 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Wed, 3 Jan 2024 17:54:55 +0000 Subject: [PATCH 4/9] Shellcheck --- docker-mods.v3 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 265f34f..22025eb 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -190,7 +190,7 @@ curl_check() { } write_debug() { - local MSG=$@ + local MSG=$* if [[ ${DOCKER_MODS_DEBUG,,} = "true" ]]; then echo "[mod-init] (DEBUG) $MSG"; fi } @@ -233,13 +233,17 @@ get_blob_sha() { } get_auth_url() { + local auth_header + local realm_url + local service + local scope # Call to get manifests and extract www-authenticate header - local auth_header=$(curl -sLI ${CURL_NOISE_LEVEL} "${1}/${2}" | grep -i www-authenticate | tr -d '\r') + auth_header=$(curl -sLI ${CURL_NOISE_LEVEL} "${1}/${2}" | grep -i www-authenticate | tr -d '\r') if [[ -n "${auth_header}" ]]; then # Extract realm URL from www-authenticate header - local realm_url=$(echo "$auth_header" | grep -oP 'realm="\K[^"]+') - local service=$(echo "$auth_header" | grep -oP 'service="\K[^"]+') - local scope=$(echo "$auth_header" | grep -oP 'scope="\K[^"]+') + realm_url=$(echo "$auth_header" | grep -oP 'realm="\K[^"]+') + service=$(echo "$auth_header" | grep -oP 'service="\K[^"]+') + scope=$(echo "$auth_header" | grep -oP 'scope="\K[^"]+') echo "$realm_url?service=$service&scope=$scope" else exit 1 From ed33ad778c4a478e1a8d0afb40b29a0d1391d0bf Mon Sep 17 00:00:00 2001 From: TheSpad Date: Wed, 3 Jan 2024 17:56:41 +0000 Subject: [PATCH 5/9] Add debug output to auth url fetch --- docker-mods.v3 | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-mods.v3 b/docker-mods.v3 index 22025eb..1329bed 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -239,6 +239,7 @@ get_auth_url() { local scope # Call to get manifests and extract www-authenticate header auth_header=$(curl -sLI ${CURL_NOISE_LEVEL} "${1}/${2}" | grep -i www-authenticate | tr -d '\r') + write_debug "${auth_header}" if [[ -n "${auth_header}" ]]; then # Extract realm URL from www-authenticate header realm_url=$(echo "$auth_header" | grep -oP 'realm="\K[^"]+') From a2960729784bf0aad82998d9a54a21e4f765da9c Mon Sep 17 00:00:00 2001 From: TheSpad Date: Thu, 4 Jan 2024 20:17:39 +0000 Subject: [PATCH 6/9] Improve logging, support multiarch mods --- docker-mods.v3 | 96 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 1329bed..08aa214 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -13,7 +13,6 @@ SERVICES_DIR="/custom-services.d" if [[ ${DOCKER_MODS_DEBUG,,} = "true" ]]; then CURL_NOISE_LEVEL="-v" - echo "[mod-init] Running in debug mode" else CURL_NOISE_LEVEL="--silent" fi @@ -141,7 +140,7 @@ create_lsiown_alias() { # Create our with-contenv alias with umask support create_with_contenv_alias() { if [[ ! -f /command/with-contenv ]]; then - echo "[mod-init] /command/with-contenv not found, skipping alias creation" + echo "/command/with-contenv not found, skipping alias creation" return fi rm -rf /usr/bin/with-contenv @@ -162,7 +161,7 @@ create_with_contenv_alias() { # Check for curl curl_check() { if [[ ! -f /usr/bin/curl ]] || [[ ! -f /usr/bin/jq ]]; then - echo "[mod-init] Curl/JQ was not found on this system for Docker mods installing" + write_mod_info "[mod-init] Curl/JQ was not found on this system for Docker mods installing" if [[ -f /usr/bin/apt ]]; then # Ubuntu export DEBIAN_FRONTEND="noninteractive" @@ -189,7 +188,17 @@ curl_check() { fi } -write_debug() { +write_mod_info() { + local MSG=$* + echo "[mod-init] $MSG" +} + +write_mod_error() { + local MSG=$* + echo "[mod-init] (ERROR) $MSG" +} + +write_mod_debug() { local MSG=$* if [[ ${DOCKER_MODS_DEBUG,,} = "true" ]]; then echo "[mod-init] (DEBUG) $MSG"; fi } @@ -199,17 +208,15 @@ get_blob_sha() { MULTIDIGEST=$(curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ ${CURL_NOISE_LEVEL} \ --location \ - --request GET \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ --header "Accept: application/vnd.oci.image.index.v1+json" \ --header "Authorization: Bearer ${1}" \ --user-agent "${MOD_UA}" \ - "${2}/${3}" | jq -r 'first(.manifests[].digest)?') + "${2}/${3}" | jq -r ".manifests[]? | select(.platform.architecture == \"${4}\").digest?") if [[ -z "${MULTIDIGEST}" ]]; then if DIGEST=$(curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ ${CURL_NOISE_LEVEL} \ --location \ - --request GET \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ --header "Accept: application/vnd.oci.image.manifest.v1+json" \ --header "Authorization: Bearer ${1}" \ @@ -221,7 +228,6 @@ get_blob_sha() { if DIGEST=$(curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ ${CURL_NOISE_LEVEL} \ --location \ - --request GET \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ --header "Accept: application/vnd.oci.image.manifest.v1+json" \ --header "Authorization: Bearer ${1}" \ @@ -239,7 +245,7 @@ get_auth_url() { local scope # Call to get manifests and extract www-authenticate header auth_header=$(curl -sLI ${CURL_NOISE_LEVEL} "${1}/${2}" | grep -i www-authenticate | tr -d '\r') - write_debug "${auth_header}" + write_mod_debug "${auth_header}" if [[ -n "${auth_header}" ]]; then # Extract realm URL from www-authenticate header realm_url=$(echo "$auth_header" | grep -oP 'realm="\K[^"]+') @@ -251,9 +257,34 @@ get_auth_url() { fi } +get_arch(){ + local arch + + if [[ -f /sbin/apk ]]; then + arch=$(apk --print-arch) + elif [[ -f /usr/bin/dpkg ]]; then + arch=$(dpkg --print-architecture) + else + arch=$(uname -m) + fi + + case "${arch}" in + x86_64 ) + arch="amd64" + ;; + aarch64 ) + arch="arm64" + ;; + esac + + echo "${arch}" +} + # Main run logic run_mods() { - echo "[mod-init] Attempting to run Docker Modification Logic" + write_mod_info "Attempting to run Docker Modification Logic" + write_mod_debug "Running in debug mode" + write_mod_debug "Mod script version ${MOD_SCRIPT_VER}" for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do # Support alternative endpoints case "${DOCKER_MOD}" in @@ -294,76 +325,75 @@ run_mods() { MANIFEST_URL="https://${REGISTRY}/v2/${ENDPOINT}/manifests" BLOB_URL="https://${REGISTRY}/v2/${ENDPOINT}/blobs/" MOD_UA="Mozilla/5.0 (Linux $(uname -m)) linuxserver.io ${REGISTRY}/${ENDPOINT}:${TAG}" - write_debug "Registry='${REGISTRY}', Repository='${USERNAME}', Image='${ENDPOINT}', Tag='${TAG}'" + write_mod_debug "Registry='${REGISTRY}', Repository='${USERNAME}', Image='${ENDPOINT}', Tag='${TAG}'" case "${REGISTRY}" in "lscr.io") AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "ghcr.io") AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "quay.io") AUTH_URL="https://quay.io/v2/auth?service=quay.io&scope=repository%3A${USERNAME}%2F${REPO}%3Apull";; "registry-1.docker.io") AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull";; - *) get_auth_url "${MANIFEST_URL}" "${TAG}" + *) AUTH_URL=$(get_auth_url "${MANIFEST_URL}" "${TAG}") esac - if [[ -z "${AUTH_URL}" ]]; then echo "[mod-init] Could not fetch auth URL from registry, skipping mod";fi + if [[ -z "${AUTH_URL}" ]]; then write_mod_error "Could not fetch auth URL from registry, skipping mod";fi # Kill off modification logic if any of the usernames are banned for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then if [[ -z ${RUN_BANNED_MODS+x} ]]; then - echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic" + write_mod_info "${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic" return else - echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied" + write_mod_info "You have chosen to run banned mods ${DOCKER_MOD} will be applied" fi fi done - echo "[mod-init] Adding ${DOCKER_MOD} to container" + write_mod_info "Adding ${DOCKER_MOD} to container" # Get registry token for api operations TOKEN="$( curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ ${CURL_NOISE_LEVEL} \ - --request GET \ "${AUTH_URL}" | jq -r '.token' )" # If we're using lscr try and get the manifest from ghcr, if it fails re-request a token from Docker Hub if [[ "${REGISTRY}" == "lscr.io" ]]; then if [[ -n $(curl --user-agent "${MOD_UA}" -sLH "Authorization: Bearer ${TOKEN}" "${MANIFEST_URL}/${TAG}" | jq -r '.errors' >/dev/null 2>&1) ]]; then - write_debug "Couldn't fetch manifest from ghcr.io, trying docker.io" + write_mod_debug "Couldn't fetch manifest from ghcr.io, trying docker.io" AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" TOKEN="$( curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ ${CURL_NOISE_LEVEL} \ - --request GET \ "${AUTH_URL}" | jq -r '.token' )" fi fi - write_debug "Using ${AUTH_URL} as auth endpoint" + write_mod_debug "Using ${AUTH_URL} as auth endpoint" + ARCH=$(get_arch) + write_mod_debug "Arch detected as ${ARCH}" # Determine first and only layer of image - SHALAYER=$(get_blob_sha "${TOKEN}" "${MANIFEST_URL}" "${TAG}") + SHALAYER=$(get_blob_sha "${TOKEN}" "${MANIFEST_URL}" "${TAG}" "${ARCH:=-amd64}") if [[ -z "${SHALAYER}" ]]; then - echo "[mod-init] ${DOCKER_MOD} could not be found on ${REGISTRY}" + write_mod_error "${DOCKER_MOD} digest could not be fetched from ${REGISTRY}" continue fi # 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" + write_mod_info "${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" else - echo "[mod-init] Downloading ${DOCKER_MOD} from ${REGISTRY}" + write_mod_info "Downloading ${DOCKER_MOD} from ${REGISTRY}" # Download and extract layer to / curl -f --retry 10 --retry-max-time 60 --retry-all-errors \ ${CURL_NOISE_LEVEL} \ --location \ - --request GET \ --header "Authorization: Bearer ${TOKEN}" \ --user-agent "${MOD_UA}" \ "${BLOB_URL}${SHALAYER}" -o \ /modtarball.tar.xz mkdir -p /tmp/mod if ! tar -tzf /modtarball.tar.xz >/dev/null 2>&1; then - echo "[mod-init] Invalid tarball, could not download ${DOCKER_MOD} from ${REGISTRY}" + write_mod_error "Invalid tarball, could not download ${DOCKER_MOD} from ${REGISTRY}" continue fi - echo "[mod-init] Installing ${DOCKER_MOD}" + write_mod_info "Installing ${DOCKER_MOD}" tar xzf /modtarball.tar.xz -C /tmp/mod if [[ -d /tmp/mod/etc/s6-overlay ]]; then if [[ -d /tmp/mod/etc/cont-init.d ]]; then @@ -379,13 +409,13 @@ run_mods() { rm -rf /tmp/mod rm -rf /modtarball.tar.xz echo "${SHALAYER}" >"/${FILENAME}" - echo "[mod-init] ${DOCKER_MOD} applied to container" + write_mod_info "${DOCKER_MOD} applied to container" fi done } run_mods_local() { - echo "[mod-init] Attempting to run Local Docker Modification Logic" + write_mod_info "Attempting to run Local Docker Modification Logic" for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do # Check mod file exists if [[ -n "$(/bin/ls -A "/mods/${DOCKER_MOD}.tar" 2>/dev/null)" ]]; then @@ -394,9 +424,9 @@ run_mods_local() { SHALAYER=$(sha256sum "/mods/${DOCKER_MOD}.tar" | cut -d " " -f 1) # 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" + write_mod_info "${DOCKER_MOD} at ${SHALAYER} has been previously applied, skipping" else - echo "[mod-init] Installing ${DOCKER_MOD}" + write_mod_info "Installing ${DOCKER_MOD}" mkdir -p "/tmp/mod/${DOCKER_MOD}" tar xf "/mods/${DOCKER_MOD}.tar" -C /tmp/mod --strip-components=1 tar xf "/tmp/mod/layer.tar" -C "/tmp/mod/${DOCKER_MOD}" @@ -413,10 +443,10 @@ run_mods_local() { shopt -u dotglob rm -rf "/tmp/mod/${DOCKER_MOD}" echo "${SHALAYER}" >"/${FILENAME}.local" - echo "[mod-init] ${DOCKER_MOD} applied to container" + write_mod_info "${DOCKER_MOD} applied to container" fi else - echo "[mod-init] ${DOCKER_MOD}.tar not found in /mods, skipping" + write_mod_error "${DOCKER_MOD}.tar not found in /mods, skipping" fi done } From b77535929df32a64dd38a3ef3f239c868b6ae749 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 5 Jan 2024 21:32:15 +0000 Subject: [PATCH 7/9] Be more confident --- docker-mods.v3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 08aa214..5867b5d 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -282,7 +282,7 @@ get_arch(){ # Main run logic run_mods() { - write_mod_info "Attempting to run Docker Modification Logic" + write_mod_info "Running Docker Modification Logic" write_mod_debug "Running in debug mode" write_mod_debug "Mod script version ${MOD_SCRIPT_VER}" for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do @@ -415,7 +415,7 @@ run_mods() { } run_mods_local() { - write_mod_info "Attempting to run Local Docker Modification Logic" + write_mod_info "Running Local Docker Modification Logic" for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do # Check mod file exists if [[ -n "$(/bin/ls -A "/mods/${DOCKER_MOD}.tar" 2>/dev/null)" ]]; then From 460c7ea4aeee291df3deb0a629cbb90c567f0cdb Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 5 Jan 2024 22:18:54 +0000 Subject: [PATCH 8/9] Update changelog --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f28ea38..a25d5a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ These files are used by Linuxserver build processes to handle mods in our images. Not for end-user consumption. -* **03.01.24:** - Support arbitrary mod registries. +* **03.01.24:** - Support arbitrary mod registries and multiarch mods. * **14.09.23:** - Fix lsiown edge cases. * **08.09.23:** - Change lsiown to skip files that are already owned by the user. * **25.05.23:** - Add lscr.io support for mods. From 5ad9c41a026187ebcc7907e27af3d5d4f8af60da Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 5 Jan 2024 22:20:51 +0000 Subject: [PATCH 9/9] Don't output version twice --- docker-mods.v3 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docker-mods.v3 b/docker-mods.v3 index 5867b5d..a0b81a8 100755 --- a/docker-mods.v3 +++ b/docker-mods.v3 @@ -161,7 +161,7 @@ create_with_contenv_alias() { # Check for curl curl_check() { if [[ ! -f /usr/bin/curl ]] || [[ ! -f /usr/bin/jq ]]; then - write_mod_info "[mod-init] Curl/JQ was not found on this system for Docker mods installing" + write_mod_info "Curl/JQ was not found on this system for Docker mods installing" if [[ -f /usr/bin/apt ]]; then # Ubuntu export DEBIAN_FRONTEND="noninteractive" @@ -474,10 +474,6 @@ create_with_contenv_alias # Main script loop -if [[ ${S6_VERBOSITY} -ge 2 ]]; then - echo "[mod-init] Version ${MOD_SCRIPT_VER}" -fi - if [[ -d "${SCRIPTS_DIR}" ]] || [[ -d "${SERVICES_DIR}" ]]; then tamper_check process_custom_services