chore: bump setup.sh to latest version too
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/23/head
Davide Polonio 2023-05-24 11:40:13 +02:00
parent bb1dca4cff
commit fd63010449
1 changed files with 16 additions and 31 deletions

View File

@ -12,7 +12,7 @@ DESIRED_CONFIG_PATH=
DIR=$(pwd) DIR=$(pwd)
DMS_CONFIG='/tmp/docker-mailserver' DMS_CONFIG='/tmp/docker-mailserver'
IMAGE_NAME= IMAGE_NAME=
DEFAULT_IMAGE_NAME='docker.io/mailserver/docker-mailserver:latest' DEFAULT_IMAGE_NAME='ghcr.io/docker-mailserver/docker-mailserver:latest'
INFO= INFO=
PODMAN_ROOTLESS=false PODMAN_ROOTLESS=false
USE_SELINUX= USE_SELINUX=
@ -71,11 +71,9 @@ function _show_local_usage
function _get_absolute_script_directory function _get_absolute_script_directory
{ {
if dirname "$(readlink -f "${0}")" &>/dev/null if dirname "$(readlink -f "${0}")" &>/dev/null; then
then
DIR=$(dirname "$(readlink -f "${0}")") DIR=$(dirname "$(readlink -f "${0}")")
elif realpath -e -L "${0}" &>/dev/null elif realpath -e -L "${0}" &>/dev/null; then
then
DIR=$(realpath -e -L "${0}") DIR=$(realpath -e -L "${0}")
DIR="${DIR%/setup.sh}" DIR="${DIR%/setup.sh}"
fi fi
@ -83,8 +81,7 @@ function _get_absolute_script_directory
function _set_default_config_path function _set_default_config_path
{ {
if [[ -d "${DIR}/config" ]] if [[ -d "${DIR}/config" ]]; then
then
# legacy path (pre v10.2.0) # legacy path (pre v10.2.0)
DEFAULT_CONFIG_PATH="${DIR}/config" DEFAULT_CONFIG_PATH="${DIR}/config"
else else
@ -94,23 +91,19 @@ function _set_default_config_path
function _handle_config_path function _handle_config_path
{ {
if [[ -z ${DESIRED_CONFIG_PATH} ]] if [[ -z ${DESIRED_CONFIG_PATH} ]]; then
then
# no desired config path # no desired config path
if [[ -n ${CONTAINER_NAME} ]] if [[ -n ${CONTAINER_NAME} ]]; then
then
VOLUME=$(${CRI} inspect "${CONTAINER_NAME}" \ VOLUME=$(${CRI} inspect "${CONTAINER_NAME}" \
--format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \ --format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \
grep "${DMS_CONFIG}$" 2>/dev/null || :) grep "${DMS_CONFIG}$" 2>/dev/null || :)
fi fi
if [[ -n ${VOLUME} ]] if [[ -n ${VOLUME} ]]; then
then
CONFIG_PATH=$(echo "${VOLUME}" | awk '{print $1}') CONFIG_PATH=$(echo "${VOLUME}" | awk '{print $1}')
fi fi
if [[ -z ${CONFIG_PATH} ]] if [[ -z ${CONFIG_PATH} ]]; then
then
CONFIG_PATH=${DEFAULT_CONFIG_PATH} CONFIG_PATH=${DEFAULT_CONFIG_PATH}
fi fi
else else
@ -121,8 +114,7 @@ function _handle_config_path
function _run_in_new_container function _run_in_new_container
{ {
# start temporary container with specified image # start temporary container with specified image
if ! ${CRI} history -q "${IMAGE_NAME}" &>/dev/null if ! ${CRI} history -q "${IMAGE_NAME}" &>/dev/null; then
then
echo "Image '${IMAGE_NAME}' not found. Pulling ..." echo "Image '${IMAGE_NAME}' not found. Pulling ..."
${CRI} pull "${IMAGE_NAME}" ${CRI} pull "${IMAGE_NAME}"
fi fi
@ -151,8 +143,7 @@ function _main
( * ) DESIRED_CONFIG_PATH="${DIR}/${OPTARG}" ;; ( * ) DESIRED_CONFIG_PATH="${DIR}/${OPTARG}" ;;
esac esac
if [[ ! -d ${DESIRED_CONFIG_PATH} ]] if [[ ! -d ${DESIRED_CONFIG_PATH} ]]; then
then
echo "Specified directory '${DESIRED_CONFIG_PATH}' doesn't exist" >&2 echo "Specified directory '${DESIRED_CONFIG_PATH}' doesn't exist" >&2
exit 1 exit 1
fi fi
@ -169,14 +160,11 @@ function _main
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
if command -v docker &>/dev/null if command -v docker &>/dev/null; then
then
CRI=docker CRI=docker
elif command -v podman &>/dev/null elif command -v podman &>/dev/null; then
then
CRI=podman CRI=podman
if ! ${PODMAN_ROOTLESS} && [[ ${EUID} -ne 0 ]] if ! ${PODMAN_ROOTLESS} && [[ ${EUID} -ne 0 ]]; then
then
read -r -p "You are running Podman in rootless mode. Continue? [Y/n] " read -r -p "You are running Podman in rootless mode. Continue? [Y/n] "
[[ -n ${REPLY} ]] && [[ ${REPLY} =~ (n|N) ]] && exit 0 [[ -n ${REPLY} ]] && [[ ${REPLY} =~ (n|N) ]] && exit 0
fi fi
@ -190,13 +178,11 @@ function _main
[[ -z ${CONTAINER_NAME} ]] && CONTAINER_NAME=${INFO#*;} [[ -z ${CONTAINER_NAME} ]] && CONTAINER_NAME=${INFO#*;}
[[ -z ${IMAGE_NAME} ]] && IMAGE_NAME=${INFO%;*} [[ -z ${IMAGE_NAME} ]] && IMAGE_NAME=${INFO%;*}
if [[ -z ${IMAGE_NAME} ]] if [[ -z ${IMAGE_NAME} ]]; then
then
IMAGE_NAME=${NAME:-${DEFAULT_IMAGE_NAME}} IMAGE_NAME=${NAME:-${DEFAULT_IMAGE_NAME}}
fi fi
if test -t 0 if test -t 0; then
then
USE_TTY="-it" USE_TTY="-it"
else else
# GitHub Actions will fail (or really anything else # GitHub Actions will fail (or really anything else
@ -207,8 +193,7 @@ function _main
_handle_config_path _handle_config_path
if [[ -n ${CONTAINER_NAME} ]] if [[ -n ${CONTAINER_NAME} ]]; then
then
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" setup "${@}" ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" setup "${@}"
else else
_run_in_new_container setup "${@}" _run_in_new_container setup "${@}"