Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(memcached): support Debian and Ubuntu #206

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/src/memcached/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "memcached",
"id": "memcached",
"version": "1.2.1",
"version": "1.3.0",
"description": "Sets up memcached into the Dev Environment",
"options": {
"enabled": {
Expand Down
58 changes: 48 additions & 10 deletions features/src/memcached/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,61 @@ if [ "$(id -u || true)" -ne 0 ]; then
exit 1
fi

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

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

if [ -z "${_REMOTE_USER}" ] || [ "${_REMOTE_USER}" = "root" ]; then
PHP_USER="www-data"
else
PHP_USER="${_REMOTE_USER}"
# shellcheck source=/dev/null
. /etc/os-release
: "${ID:=}"
: "${ID_LIKE:=${ID}}"
RUN_AS=""

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

apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}
apt-get clean
rm -rf /var/lib/apt/lists/*
update-rc.d memcached remove
RUN_AS="memcache"
;;

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

# shellcheck disable=SC2086
apk add --no-cache ${PACKAGES}
RUN_AS="memcached"
;;

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

if [ -d /wp/wp-content ]; then
install -m 0644 -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" object-cache.php /wp/wp-content/
fi

apk add --no-cache memcached
install -D -m 0755 -o root -g root service-run /etc/sv/memcached/run
install -d -m 0755 -o root -g root /etc/service
install -d -m 0755 -o "${PHP_USER}" -g "${PHP_USER}" /wp
install -d -m 0755 -o "${PHP_USER}" -g "${PHP_USER}" /wp/wp-content
install -m 0644 -o "${PHP_USER}" -g "${PHP_USER}" object-cache.php /wp/wp-content/
export RUN_AS

install -D -d -m 0755 -o root -g root /etc/service /etc/sv/memcached
# shellcheck disable=SC2016
envsubst '$RUN_AS' < service-run.tpl > /etc/sv/memcached/run && chmod 0755 /etc/sv/memcached/run
ln -sf /etc/sv/memcached /etc/service/memcached

echo 'Done!'
fi
6 changes: 0 additions & 6 deletions features/src/memcached/service-run

This file was deleted.

7 changes: 7 additions & 0 deletions features/src/memcached/service-run.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -eu
exec 2>&1

# shellcheck disable=SC2154 # set by `install.sh`
exec /usr/bin/memcached -u "${RUN_AS}"