From b84783b68156505cd9173914c30faf5589920a3b Mon Sep 17 00:00:00 2001 From: TheSpad Date: Tue, 16 May 2023 09:32:55 +0100 Subject: [PATCH 1/2] Add package install --- README.md | 1 + package-install.v1 | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 package-install.v1 diff --git a/README.md b/README.md index a299a60..f26db83 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. +* **16.05.23:** - Add package installer. * **15.05.23:** - Add DOCKER_MODS_DEBUG env. * **19.03.23:** - Add quay.io support for mods. * **25.02.23:** - Inject branding. diff --git a/package-install.v1 b/package-install.v1 new file mode 100755 index 0000000..b9018aa --- /dev/null +++ b/package-install.v1 @@ -0,0 +1,69 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +if [[ -f "/mod-pip-packages-to-install.list" ]]; then + IFS=' ' read -ra PIP_PACKAGES <<< "$(tr '\n' ' ' < /mod-pip-packages-to-install.list)" + if [[ ${#PIP_PACKAGES[@]} -ne 0 ]] && [[ ${PIP_PACKAGES[*]} != "" ]]; then + if [[ -f /usr/bin/apt ]]; then + echo "python3-venv" >> /mod-repo-packages-to-install.list + elif [[ -f /sbin/apk ]]; then + echo "python3" >> /mod-repo-packages-to-install.list + elif [[ -f /usr/sbin/pacman ]]; then + echo "python" >> /mod-repo-packages-to-install.list + elif [[ -f /usr/bin/dnf ]]; then + echo "python3" >> /mod-repo-packages-to-install.list + fi + fi +fi + +if [[ -f "/mod-repo-packages-to-install.list" ]]; then + IFS=' ' read -ra REPO_PACKAGES <<< "$(tr '\n' ' ' < /mod-repo-packages-to-install.list)" + if [[ ${#REPO_PACKAGES[@]} -ne 0 ]] && [[ ${REPO_PACKAGES[*]} != "" ]]; then + echo "[mod-init] **** Installing all mod packages ****" + if [[ -f /usr/bin/apt ]]; then + export DEBIAN_FRONTEND="noninteractive" + apt-get update + apt-get install -y --no-install-recommends \ + "${REPO_PACKAGES[@]}" + elif [[ -f /sbin/apk ]]; then + apk add --no-cache \ + "${REPO_PACKAGES[@]}" + elif [[ -f /usr/sbin/pacman ]]; then + pacman -Sy --noconfirm \ + "${REPO_PACKAGES[@]}" + elif [[ -f /usr/bin/dnf ]]; then + dnf install -y --setopt=install_weak_deps=False --best \ + "${REPO_PACKAGES[@]}" + fi + fi +fi + +if [[ -f "/mod-pip-packages-to-install.list" ]]; then + IFS=' ' read -ra PIP_PACKAGES <<< "$(tr '\n' ' ' < /mod-pip-packages-to-install.list)" + if [[ ${#PIP_PACKAGES[@]} -ne 0 ]] && [[ ${PIP_PACKAGES[*]} != "" ]]; then + echo "[mod-init] **** Installing all pip packages ****" + if [[ ! -d /lsiopy/bin ]]; then + echo "**** Creating venv ****" + python3 -m venv /lsiopy + fi + python3 -m pip install -U pip wheel setuptools + PIP_ARGS=() + if [[ -f /usr/bin/apt ]]; then + PIP_ARGS+=("-f" "https://wheel-index.linuxserver.io/ubuntu/") + elif [[ -f /sbin/apk ]]; then + ALPINE_VER=$(grep main /etc/apk/repositories | sed 's|.*alpine/v||' | sed 's|/main.*||') + if [[ "${ALPINE_VER}" = "3.14" ]]; then + PIP_ARGS+=("-f" "https://wheel-index.linuxserver.io/alpine/") + else + PIP_ARGS+=("-f" "https://wheel-index.linuxserver.io/alpine-${ALPINE_VER}/") + fi + fi + python3 -m pip install \ + "${PIP_ARGS[@]}" \ + "${PIP_PACKAGES[@]}" + fi +fi + +rm -rf \ + /mod-repo-packages-to-install.list \ + /mod-pip-packages-to-install.list From 8b54e5638eb0d2ca36152107ae00d38e284fcd74 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Tue, 16 May 2023 14:59:55 +0100 Subject: [PATCH 2/2] Differentiate ubuntu & debian for pip options --- package-install.v1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-install.v1 b/package-install.v1 index b9018aa..7dc1e2c 100755 --- a/package-install.v1 +++ b/package-install.v1 @@ -48,7 +48,7 @@ if [[ -f "/mod-pip-packages-to-install.list" ]]; then fi python3 -m pip install -U pip wheel setuptools PIP_ARGS=() - if [[ -f /usr/bin/apt ]]; then + if [[ -f /usr/bin/apt ]] && grep -q 'ID=ubuntu' /etc/os-release; then PIP_ARGS+=("-f" "https://wheel-index.linuxserver.io/ubuntu/") elif [[ -f /sbin/apk ]]; then ALPINE_VER=$(grep main /etc/apk/repositories | sed 's|.*alpine/v||' | sed 's|/main.*||')