From 1fed68526cb76aaab3c70982b2c57aacb43df9e1 Mon Sep 17 00:00:00 2001 From: Orwill Towne Date: Fri, 22 Nov 2019 22:42:25 +0800 Subject: [PATCH 1/4] Add podman support to setup.sh --- setup.sh | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/setup.sh b/setup.sh index f2ccf4c2..686d3248 100755 --- a/setup.sh +++ b/setup.sh @@ -1,12 +1,32 @@ -#! /bin/sh +#!/usr/bin/env bash ## # Wrapper for various setup scripts included in the docker-mailserver # -INFO=$(docker ps \ +CRI= + +_check_root() { + if [[ $EUID -ne 0 ]]; then + echo "Curently docker-mailserver doesn't support podman's rootless mode, please run this script as root user." + exit 1 + fi +} +if [ -z "${CRI}" ]; then + if [ ! -z "$(command -v docker)" ]; then + CRI=docker + else if [ ! -z "$(command -v podman)" ]; then + CRI=podman + _check_root + else do + echo "No Supported Container Runtime Interface Detected." + exit 1 + fi +fi + +INFO=$(${CRI} ps \ --no-trunc \ - --format="{{.Image}}\t{{.Names}}\t{{.Command}}" | \ + --format="{{.Image}} {{.Names}} {{.Command}}" | \ grep "supervisord -c /etc/supervisor/supervisord.conf") IMAGE_NAME=$(echo $INFO | awk '{print $1}') @@ -15,7 +35,7 @@ DEFAULT_CONFIG_PATH="$(pwd)/config" USE_CONTAINER=false _update_config_path() { - VOLUME=$(docker inspect $CONTAINER_NAME \ + VOLUME=$(${CRI} inspect $CONTAINER_NAME \ --format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \ grep "/tmp/docker-mailserver$" 2>/dev/null) @@ -25,7 +45,11 @@ _update_config_path() { } if [ -z "$IMAGE_NAME" ]; then - IMAGE_NAME=tvial/docker-mailserver:latest + if [ "$CRI" = "docker" ]; then + IMAGE_NAME=tvial/docker-mailserver:latest + else if [ "$CRI" = "podman" ]; then + IMAGE_NAME=docker.io/tvial/docker-mailserver:latest + fi fi _inspect() { @@ -48,7 +72,9 @@ _usage() { OPTIONS: -i IMAGE_NAME The name of the docker-mailserver image, by default - 'tvial/docker-mailserver:latest'. + 'tvial/docker-mailserver:latest' for docker, and + 'docker.io/tvial/docker-mailserver:latest' for podman. + -c CONTAINER_NAME The name of the running container. -p PATH config folder path (default: $(pwd)/config) @@ -91,7 +117,7 @@ SUBCOMMANDS: } _docker_image_exists() { - if docker history -q "$1" >/dev/null 2>&1; then + if ${CRI} history -q "$1" >/dev/null 2>&1; then return 0 else return 1 @@ -105,15 +131,15 @@ fi _docker_image() { if [ "$USE_CONTAINER" = true ]; then # Reuse existing container specified on command line - docker exec ${USE_TTY} "$CONTAINER_NAME" "$@" + ${CRI} exec ${USE_TTY} "$CONTAINER_NAME" "$@" else # Start temporary container with specified image if ! _docker_image_exists "$IMAGE_NAME"; then echo "Image '$IMAGE_NAME' not found. Pulling ..." - docker pull "$IMAGE_NAME" + ${CRI} pull "$IMAGE_NAME" fi - docker run \ + ${CRI} run \ --rm \ -v "$CONFIG_PATH":/tmp/docker-mailserver \ ${USE_TTY} "$IMAGE_NAME" $@ @@ -122,7 +148,7 @@ _docker_image() { _docker_container() { if [ -n "$CONTAINER_NAME" ]; then - docker exec ${USE_TTY} "$CONTAINER_NAME" "$@" + ${CRI} exec ${USE_TTY} "$CONTAINER_NAME" "$@" else echo "The docker-mailserver is not running!" exit 1 From 49b49f972318722559c4cdcd6a80df382a676197 Mon Sep 17 00:00:00 2001 From: Orwill Towne Date: Fri, 22 Nov 2019 23:10:42 +0800 Subject: [PATCH 2/4] little tweak --- setup.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 686d3248..767b5839 100755 --- a/setup.sh +++ b/setup.sh @@ -12,14 +12,15 @@ _check_root() { exit 1 fi } + if [ -z "${CRI}" ]; then if [ ! -z "$(command -v docker)" ]; then CRI=docker else if [ ! -z "$(command -v podman)" ]; then CRI=podman _check_root - else do - echo "No Supported Container Runtime Interface Detected." + else + echo "No Support Container Runtime Interface Detected." exit 1 fi fi From 317cf80ba81cbf0287e3a2fda2bef9e75d678110 Mon Sep 17 00:00:00 2001 From: Orwill Towne Date: Fri, 22 Nov 2019 23:50:23 +0800 Subject: [PATCH 3/4] fix elif --- setup.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/setup.sh b/setup.sh index 767b5839..e2c05bd0 100755 --- a/setup.sh +++ b/setup.sh @@ -10,13 +10,13 @@ _check_root() { if [[ $EUID -ne 0 ]]; then echo "Curently docker-mailserver doesn't support podman's rootless mode, please run this script as root user." exit 1 - fi + fi } -if [ -z "${CRI}" ]; then +if [ -z "$CRI" ]; then if [ ! -z "$(command -v docker)" ]; then CRI=docker - else if [ ! -z "$(command -v podman)" ]; then + elif [ ! -z "$(command -v podman)" ]; then CRI=podman _check_root else @@ -25,7 +25,7 @@ if [ -z "${CRI}" ]; then fi fi -INFO=$(${CRI} ps \ +INFO=$($CRI ps \ --no-trunc \ --format="{{.Image}} {{.Names}} {{.Command}}" | \ grep "supervisord -c /etc/supervisor/supervisord.conf") @@ -36,7 +36,7 @@ DEFAULT_CONFIG_PATH="$(pwd)/config" USE_CONTAINER=false _update_config_path() { - VOLUME=$(${CRI} inspect $CONTAINER_NAME \ + VOLUME=$($CRI inspect $CONTAINER_NAME \ --format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \ grep "/tmp/docker-mailserver$" 2>/dev/null) @@ -46,11 +46,11 @@ _update_config_path() { } if [ -z "$IMAGE_NAME" ]; then - if [ "$CRI" = "docker" ]; then - IMAGE_NAME=tvial/docker-mailserver:latest - else if [ "$CRI" = "podman" ]; then - IMAGE_NAME=docker.io/tvial/docker-mailserver:latest - fi + if [ "$CRI" = "docker" ]; then + IMAGE_NAME=tvial/docker-mailserver:latest + elif [ "$CRI" = "podman" ]; then + IMAGE_NAME=docker.io/tvial/docker-mailserver:latest + fi fi _inspect() { From a3f571365ff238c3c2ff2995abff264b7e6061f5 Mon Sep 17 00:00:00 2001 From: Orwill Towne Date: Tue, 26 Nov 2019 06:31:42 +0800 Subject: [PATCH 4/4] Change interpreter --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index e2c05bd0..6d41e406 100755 --- a/setup.sh +++ b/setup.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh ## # Wrapper for various setup scripts included in the docker-mailserver