From a0d0db91923a4dad91f4419511a48fdceee08e5a Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Mon, 23 Dec 2024 07:35:38 +0100 Subject: [PATCH] Docker: adjust module options to match changes --- tools/json/config.software.json | 25 +++---- tools/modules/software/install_docker.sh | 41 ----------- tools/modules/software/install_swag.sh | 4 +- tools/modules/software/module_bazarr.sh | 4 +- tools/modules/software/module_deluge.sh | 4 +- tools/modules/software/module_docker.sh | 93 ++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 61 deletions(-) delete mode 100644 tools/modules/software/install_docker.sh create mode 100644 tools/modules/software/module_docker.sh diff --git a/tools/json/config.software.json b/tools/json/config.software.json index f8272956a..e71cca3cd 100644 --- a/tools/json/config.software.json +++ b/tools/json/config.software.json @@ -878,48 +878,47 @@ "sub": [ { "id": "CON001", - "description": "Install Docker Minimal", + "description": "Docker Minimal Install", "about": "This operation will install Docker Minimal.", "command": [ - "install_docker" + "module_docker install minimal" ], "status": "Stable", "author": "@schwar3kat", - "condition": "! pkg_installed docker-ce" + "condition": "! module_docker status docker-ce" }, { "id": "CON002", - "description": "Install Docker Engine", + "description": "Docker Engine Install", "about": "This operation will install Docker Engine.", "command": [ - "install_docker engine" + "module_docker install engine" ], "status": "Stable", "author": "@schwar3kat", - "condition": "! pkg_installed docker-compose-plugin" + "condition": "! module_docker status docker-compose-plugin" }, { "id": "CON003", - "description": "Remove Docker", + "description": "Docker Remove", "about": "This operation will purge Docker.", "command": [ - "pkg_remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras" + "module_docker remove" ], "status": "Stable", "author": "@schwar3kat", - "condition": "pkg_installed docker-ce" + "condition": "module_docker status docker-ce" }, { "id": "CON004", - "description": "Purge all Docker images, containers, and volumes", + "description": "Docker Purge all images, containers, and volumes", "about": "This operation will delete all Docker images, containers, and volumes.", "command": [ - "rm -rf /var/lib/docker", - "rm -rf /var/lib/containerd" + "module_docker purge" ], "status": "Stable", "author": "@schwar3kat", - "condition": "! pkg_installed docker-ce && [ -d /var/lib/docker ]" + "condition": "! module_docker status docker-ce && [ -d /var/lib/docker ]" }, { "id": "CON005", diff --git a/tools/modules/software/install_docker.sh b/tools/modules/software/install_docker.sh deleted file mode 100644 index 7d00bb87d..000000000 --- a/tools/modules/software/install_docker.sh +++ /dev/null @@ -1,41 +0,0 @@ - -module_options+=( - ["install_docker,author"]="@schwar3kat" - ["install_docker,ref_link"]="" - ["install_docker,feature"]="install_docker" - ["install_docker,desc"]="Install docker from a repo using apt" - ["install_docker,example"]="install_docker engine" - ["install_docker,status"]="Active" -) -# -# Install Docker from repo using apt -# Setup sources list and GPG key then install the app. If you want a full desktop then $1=desktop -# -install_docker() { - # Check if repo for distribution exists. - URL="https://download.docker.com/linux/${DISTRO,,}/dists/$DISTROID" - if wget --spider "${URL}" 2> /dev/null; then - # Add Docker's official GPG key: - wget -qO - https://download.docker.com/linux/${DISTRO,,}/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker.gpg > /dev/null - if [[ $? -eq 0 ]]; then - # Add the repository to Apt sources: - cat <<- EOF > "/etc/apt/sources.list.d/docker.list" - deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO,,} $DISTROID stable - EOF - pkg_update - # Install docker - if [ "$1" = "engine" ]; then - pkg_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - else - pkg_install docker-ce docker-ce-cli containerd.io - fi - groupadd docker 2>/dev/null || true - usermod -aG docker $SUDO_USER - systemctl enable docker.service > /dev/null 2>&1 - systemctl enable containerd.service > /dev/null 2>&1 - fi - else - $DIALOG --msgbox "ERROR ! ${DISTRO} $DISTROID distribution not found in repository!" 7 70 - fi -} - diff --git a/tools/modules/software/install_swag.sh b/tools/modules/software/install_swag.sh index e2cfff10d..2655e7406 100644 --- a/tools/modules/software/install_swag.sh +++ b/tools/modules/software/install_swag.sh @@ -32,9 +32,7 @@ function module_swag() { # adjust hostname hostnamectl set-hostname $(echo ${SWAG_URL} | sed -E 's/^\s*.*:\/\///g') # install docker - pkg_installed docker-ce || install_docker - # add additional bridge where containers see each other - docker network create lsio 2> /dev/null + pkg_installed docker-ce || module_docker install [[ -d "$SWAG_BASE" ]] || mkdir -p "$SWAG_BASE" || { echo "Couldn't create storage directory: $SWAG_BASE"; exit 1; } diff --git a/tools/modules/software/module_bazarr.sh b/tools/modules/software/module_bazarr.sh index 7cfaffc56..972b8ac49 100644 --- a/tools/modules/software/module_bazarr.sh +++ b/tools/modules/software/module_bazarr.sh @@ -8,7 +8,7 @@ module_options+=( ["module_bazarr,doc_link"]="https://wiki.bazarr.media/" ["module_bazarr,group"]="Downloaders" ["module_bazarr,port"]="6767" - ["module_bazarr,arch"]="x86-64,arm64" + ["module_bazarr,arch"]="x86-64 arm64" ) # # Module Bazarr @@ -29,7 +29,7 @@ function module_bazarr () { case "$1" in "${commands[0]}") - pkg_installed docker-ce || install_docker + pkg_installed docker-ce || module_docker install [[ -d "$BAZARR_BASE" ]] || mkdir -p "$BAZARR_BASE" || { echo "Couldn't create storage directory: $BAZARR_BASE"; exit 1; } docker run -d \ --name=bazarr \ diff --git a/tools/modules/software/module_deluge.sh b/tools/modules/software/module_deluge.sh index 19df6c89a..52084826d 100644 --- a/tools/modules/software/module_deluge.sh +++ b/tools/modules/software/module_deluge.sh @@ -8,7 +8,7 @@ module_options+=( ["module_deluge,doc_link"]="https://deluge-torrent.org/userguide/" ["module_deluge,group"]="Downloaders" ["module_deluge,port"]="8112 6181 58846" - ["module_deluge,arch"]="x86-64,arm64" + ["module_deluge,arch"]="x86-64 arm64" ) # # Module deluge @@ -29,7 +29,7 @@ function module_deluge () { case "$1" in "${commands[0]}") - pkg_installed docker-ce || install_docker + pkg_installed docker-ce || module_docker install [[ -d "$DELUGE_BASE" ]] || mkdir -p "$DELUGE_BASE" || { echo "Couldn't create storage directory: $DELUGE_BASE"; exit 1; } docker run -d \ --name=deluge \ diff --git a/tools/modules/software/module_docker.sh b/tools/modules/software/module_docker.sh new file mode 100644 index 000000000..c23090b44 --- /dev/null +++ b/tools/modules/software/module_docker.sh @@ -0,0 +1,93 @@ +module_options+=( + ["module_docker,author"]="@schwar3kat" + ["module_docker,maintainer"]="@igorpecovnik" + ["module_docker,feature"]="install_docker" + ["module_docker,example"]="install remove purge status help" + ["module_docker,desc"]="Install docker from a repo using apt" + ["module_docker,status"]="Active" + ["module_docker,doc_link"]="https://wiki.bazarr.media/" + ["module_docker,group"]="Containers" + ["module_docker,port"]="" + ["module_docker,arch"]="x86-64 arm64 armhf" +) +# +# Install Docker from repo using apt +# Setup sources list and GPG key then install the app. If you want a full desktop then $1=desktop +# +function module_docker() { + + local title="bazarr" + local condition=$(which "$title" 2>/dev/null) + + local commands + IFS=' ' read -r -a commands <<< "${module_options["module_docker,example"]}" + + case "$1" in + "${commands[0]}") + # Check if repo for distribution exists. + URL="https://download.docker.com/linux/${DISTRO,,}/dists/$DISTROID" + if wget --spider "${URL}" 2> /dev/null; then + # Add Docker's official GPG key: + wget -qO - https://download.docker.com/linux/${DISTRO,,}/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker.gpg > /dev/null + if [[ $? -eq 0 ]]; then + # Add the repository to Apt sources: + cat <<- EOF > "/etc/apt/sources.list.d/docker.list" + deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO,,} $DISTROID stable + EOF + pkg_update + # Install docker + if [ "$2" = "engine" ]; then + pkg_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + else + pkg_install docker-ce docker-ce-cli containerd.io + fi + + groupadd docker 2>/dev/null || true + usermod -aG docker $SUDO_USER + systemctl enable docker.service > /dev/null 2>&1 + systemctl enable containerd.service > /dev/null 2>&1 + docker network create lsio 2> /dev/null + fi + else + $DIALOG --msgbox "ERROR ! ${DISTRO} $DISTROID distribution not found in repository!" 7 70 + fi + ;; + "${commands[1]}") + pkg_remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras + ;; + "${commands[2]}") + rm -rf /var/lib/docker + rm -rf /var/lib/containerd + ;; + "${commands[3]}") + if [ "$2" = "docker-ce" ]; then + if pkg_installed docker-ce; then + return 0 + else + return 1 + fi + fi + if [ "$2" = "docker-compose-plugin" ]; then + if pkg_installed docker-compose-plugin; then + return 0 + else + return 1 + fi + fi + ;; + "${commands[4]}") + echo -e "\nUsage: ${module_options["module_docker,feature"]} " + echo -e "Commands: ${module_options["module_docker,example"]}" + echo "Available commands:" + echo -e "\tinstall\t- Install $title." + echo -e "\tstatus\t- Installation status $title." + echo -e "\tremove\t- Remove $title." + echo -e "\tremove\t- Purge $title." + echo + ;; + *) + ${module_options["module_docker,feature"]} ${commands[4]} + ;; + esac +} +