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

feat(wp-cli): add support for Debian-based distros #156

Merged
merged 2 commits into from
Mar 18, 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/wp-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "wp-cli",
"name": "WP CLI",
"version": "1.0.2",
"version": "1.1.0",
"description": "Sets up wp-cli into the Dev Environment",
"options": {
"nightly": {
Expand Down
61 changes: 51 additions & 10 deletions features/src/wp-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,67 @@ if [ "$(id -u || true)" -ne 0 ]; then
exit 1
fi

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

: "${NIGHTLY:=}"

echo '(*) Installing wp-cli...'

if [ "${NIGHTLY}" = "true" ]; then
url="https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar"
else
url="https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
fi

wget -q "${url}" -O /usr/local/bin/wp
chmod 0755 /usr/local/bin/wp
if ! hash wget >/dev/null 2>&1; then
: "${ID:=}"
: "${ID_LIKE:=${ID}}"

if [ -z "${ID}" ]; then
echo 'Unable to determine the distribution.'
exit 1
fi

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

apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}

if [ -n "$(command -v php || true)" ]; then
sudo -u "${USER}" wp cli info || true
wget -q "${url}" -O /usr/local/bin/wp

# shellcheck disable=SC2086
apt-get purge -y --auto-remove ${PACKAGES}
apt-get clean
rm -rf /var/lib/apt/lists/*
;;

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

# shellcheck disable=SC2086
apk add --no-cache ${PACKAGES}

wget -q "${url}" -O /usr/local/bin/wp

# shellcheck disable=SC2086
apk del --no-cache ${PACKAGES}
;;

*)
echo "(!) Unsupported distribution: ${ID}"
exit 1
;;
esac
else
wget -q "${url}" -O /usr/local/bin/wp
fi

chmod 0755 /usr/local/bin/wp
echo 'Done!'
8 changes: 8 additions & 0 deletions features/test/wp-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# shellcheck source=/dev/null
source dev-container-features-test-lib

check "wp-cli exists" sh -c "[ -x /usr/local/bin/wp ]"

reportResults