Skip to content

Commit

Permalink
Merge pull request #193 from Automattic/refactor-mailpit
Browse files Browse the repository at this point in the history
refactor(mailpit): add support for Debian and Ubuntu
  • Loading branch information
sjinks authored May 30, 2024
2 parents 9b02227 + 097f133 commit 249d079
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
2 changes: 1 addition & 1 deletion features/src/mailpit/conf-mailpit.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MAILPIT_USER=${MAILPIT_USER}
MAILPIT_USER=${_REMOTE_USER}
2 changes: 1 addition & 1 deletion features/src/mailpit/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "mailpit",
"name": "Mailpit",
"description": "Sets up Mailpit into the Dev Environment",
"version": "1.0.3",
"version": "1.1.0",
"options": {
"enabled": {
"type": "boolean",
Expand Down
87 changes: 73 additions & 14 deletions features/src/mailpit/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,76 @@ if [ "$(id -u || true)" -ne 0 ]; then
exit 1
fi

if [ -z "${_REMOTE_USER}" ] || [ "${_REMOTE_USER}" = "root" ]; then
MAILPIT_USER=nobody
else
MAILPIT_USER="${_REMOTE_USER}"
fi

: "${_REMOTE_USER:?"_REMOTE_USER is required"}"
: "${ENABLED:=}"

if [ "${ENABLED}" = "true" ]; then
echo '(*) Installing Mailpit...'

# shellcheck source=/dev/null
. /etc/os-release

: "${ID:=}"
: "${ID_LIKE:=${ID}}"
PHP_INI_DIR=
NEED_ENMOD=

case "${ID_LIKE}" in
"debian")
PACKAGES=""
if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash update-ca-certificates >/dev/null 2>&1; then
PACKAGES="${PACKAGES} ca-certificates"
fi

if ! hash envsubst >/dev/null 2>&1; then
PACKAGES="${PACKAGES} gettext"
fi

if [ -n "${PACKAGES}" ]; then
apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}
fi

apt-get clean
rm -rf /var/lib/apt/lists/*

if hash php >/dev/null 2>&1; then
PHP_INI_DIR="/etc/php/$(php -r 'echo PHP_MAJOR_VERSION, ".", PHP_MINOR_VERSION;')/mods-available"
NEED_ENMOD=1
fi
;;

"alpine")
PACKAGES=""
if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash envsubst >/dev/null 2>&1; then
PACKAGES="${PACKAGES} gettext"
fi

if [ -n "${PACKAGES}" ]; then
# shellcheck disable=SC2086
apk add --no-cache ${PACKAGES}
fi

if hash php >/dev/null 2>&1; then
PHP_INI_DIR="/etc/php$(php -r 'echo PHP_MAJOR_VERSION, PHP_MINOR_VERSION;')/conf.d"
fi
;;

*)
echo "(!) Unsupported distribution: ${ID}"
exit 1
;;
esac

ARCH="$(arch)"
LATEST=$(curl -w '%{url_effective}' -I -L -s -S https://github.com/axllent/mailpit/releases/latest -o /dev/null | sed -e 's|.*/||')
if [ "${ARCH}" = "arm64" ] || [ "${ARCH}" = "aarch64" ]; then
Expand All @@ -34,24 +93,24 @@ if [ "${ENABLED}" = "true" ]; then
mkdir -p /tmp/mailpit
( \
cd /tmp/mailpit && \
wget -q "https://github.com/axllent/mailpit/releases/download/${LATEST}/mailpit-linux-${ARCH}.tar.gz" -O - | tar -xz && \
curl -SL "https://github.com/axllent/mailpit/releases/download/${LATEST}/mailpit-linux-${ARCH}.tar.gz" | tar -xz && \
install -m 0755 -o root -g root mailpit /usr/local/bin/mailpit && \
cd .. && \
rm -rf /tmp/mailpit \
)

: "${PHP_INI_DIR:=/etc/php}":

chmod 0755 /usr/local/bin/mailpit
install -m 0644 php-mailpit.ini "${PHP_INI_DIR}/conf.d/mailpit.ini"
if [ -n "${PHP_INI_DIR}" ]; then
install -m 0644 php-mailpit.ini "${PHP_INI_DIR}/mailpit.ini"
if [ -n "${NEED_ENMOD}" ]; then
phpenmod mailpit
fi
fi

install -D -m 0755 -o root -g root service-run /etc/sv/mailpit/run
install -d -m 0755 -o root -g root /etc/service
ln -sf /etc/sv/mailpit /etc/service/mailpit

export MAILPIT_USER
# shellcheck disable=SC2016
envsubst '$MAILPIT_USER' < conf-mailpit.tpl > /etc/conf.d/mailpit
envsubst '$_REMOTE_USER' < conf-mailpit.tpl > /etc/conf.d/mailpit

echo 'Done!'
fi

0 comments on commit 249d079

Please sign in to comment.