Files
azionelab-v2/wp-cli/bootstrap.sh
T
2026-06-25 07:36:25 +02:00

99 lines
3.4 KiB
Bash

#!/bin/sh
set -eu
cd /var/www/html
if [ "${WP_ENVIRONMENT_TYPE:-local}" = production ]; then
admin_password="${WP_ADMIN_PASSWORD:-}"
case "$admin_password" in
"" | *replace-with*)
echo "A non-placeholder WP_ADMIN_PASSWORD is required in production." >&2
exit 1
;;
esac
if [ "${#admin_password}" -lt 16 ]; then
echo "WP_ADMIN_PASSWORD must contain at least 16 characters in production." >&2
exit 1
fi
fi
attempt=1
until wp db check >/dev/null 2>&1; do
if [ "$attempt" -ge 30 ]; then
echo "WordPress database was not ready after $attempt attempts." >&2
exit 1
fi
attempt=$((attempt + 1))
sleep 2
done
if ! wp core is-installed; then
wp core install \
--url="${WP_URL:?WP_URL is required}" \
--title="${WP_TITLE:-Azione!Lab}" \
--admin_user="${WP_ADMIN_USER:?WP_ADMIN_USER is required}" \
--admin_password="${WP_ADMIN_PASSWORD:?WP_ADMIN_PASSWORD is required}" \
--admin_email="${WP_ADMIN_EMAIL:?WP_ADMIN_EMAIL is required}" \
--skip-email
fi
wp option update home "$WP_URL"
wp option update siteurl "$WP_URL"
wp option update blogname "${WP_TITLE:-Azione!Lab}"
wp option update blogdescription "Il teatro diventa presenza."
wp option update timezone_string "Europe/Rome"
wp option update permalink_structure '/%postname%/'
if ! wp theme is-active azionelab; then
wp theme activate azionelab
fi
for sample_id in 1 2; do
if ! wp post get "$sample_id" --field=ID >/dev/null 2>&1; then
continue
fi
sample_slug="$(wp post get "$sample_id" --field=post_name)"
case "$sample_slug" in
hello-world | sample-page)
wp post delete "$sample_id" --force >/dev/null
;;
esac
done
ensure_show() {
slug="$1"
title="$2"
excerpt="$3"
year="$4"
location="$5"
order="$6"
post_id="$(wp post list --post_type=azl_show --name="$slug" --field=ID --format=ids)"
if [ -z "$post_id" ]; then
post_id="$(wp post create --post_type=azl_show --post_status=publish --post_name="$slug" --post_title="$title" --post_excerpt="$excerpt" --menu_order="$order" --porcelain)"
fi
wp post meta update "$post_id" azl_show_year "$year" >/dev/null
wp post meta update "$post_id" azl_show_location "$location" >/dev/null
}
ensure_gallery() {
slug="$1"
title="$2"
category="$3"
order="$4"
post_id="$(wp post list --post_type=azl_gallery --name="$slug" --field=ID --format=ids)"
if [ -z "$post_id" ]; then
post_id="$(wp post create --post_type=azl_gallery --post_status=publish --post_name="$slug" --post_title="$title" --menu_order="$order" --porcelain)"
fi
wp post meta update "$post_id" azl_gallery_category "$category" >/dev/null
}
ensure_show "le-cose-che-restano" "Le cose che restano" "Un lavoro corale su memoria, gesti quotidiani e piccoli cambiamenti." "2025" "Teatro di Quartiere" "1"
ensure_show "fuori-campo" "Fuori campo" "Storie ai margini della scena che chiedono, finalmente, di essere ascoltate." "2024" "Spazio Scena" "2"
ensure_gallery "ascolto-e-movimento" "Ascolto e movimento" "Lezioni" "1"
ensure_gallery "prima-della-scena" "Prima di entrare in scena" "Backstage" "2"
ensure_gallery "spettacolo-finale" "Le cose che restano" "Spettacoli" "3"
ensure_gallery "il-gruppo" "Il laboratorio, insieme" "Gruppo" "4"
wp rewrite flush >/dev/null
echo "Azione!Lab WordPress content is ready."