From 725b25aa38fcac94f37e40af128dd39ba2fb4005 Mon Sep 17 00:00:00 2001 From: Thuan Bui Date: Wed, 20 Mar 2024 09:22:17 +0700 Subject: [PATCH] Update bash script --- wp-init.sh | 145 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 55 deletions(-) diff --git a/wp-init.sh b/wp-init.sh index faf8c14..8d71faa 100755 --- a/wp-init.sh +++ b/wp-init.sh @@ -6,67 +6,102 @@ WORDPRESS_PASSWORD=$(sed -e 's#.*=\(\)#\1#' <<< "$(awk '/WORDPRESS_ADMIN_PASSWOR WORDPRESS_PLUGINS_TO_INSTALL=$(sed -e 's#.*=\(\)#\1#' <<< "$(awk '/WORDPRESS_PLUGINS_TO_INSTALL/{print}' .env)" | xargs) WORDPRESS_THEME_TO_INSTALL=$(sed -e 's#.*=\(\)#\1#' <<< "$(awk '/WORDPRESS_THEME_TO_INSTALL/{print}' .env)" | xargs) -echo "== Installing WordPress ==" -## Install Wodpress -docker compose run wpcli core install \ - --url=${SERVER_NAME} \ - --title="${WORDPRESS_TITLE}" \ - --admin_user=${WORDPRESS_USER} \ - --admin_email=${WORDPRESS_EMAIL} \ - --admin_password=${WORDPRESS_PASSWORD} \ - --skip-email +# Function to ask for yes/no confirmation +ask_yes_no() { + QUESTION=$1 + while true; do + # Customize your prompt message here + read -p "$QUESTION" answer + # Default to Yes if no answer is given + if [[ -z "$answer" ]]; then + answer="Y" + fi -echo "== Configure Permalinks ==" -## Configure Permalinks -docker compose run wpcli rewrite structure '/%postname%/' + case $answer in + [Yy]* ) ANSWER=true; break;; + [Nn]* ) ANSWER=false;break;; + * ) echo "Please answer yes or no.";; + esac + done +} -echo "== Install Plugins ==" -## Install Plugins -docker compose run wpcli plugin install ${WORDPRESS_PLUGINS_TO_INSTALL} --activate -## Enable Redis Cache Object -#docker compose run wpcli redis enable -## Enable and config Cache Enabler -docker compose run wpcli option update cache_enabler '{ - "version": "1.8.0", - "use_trailing_slashes": 1, - "permalink_structure": "has_trailing_slash", - "cache_expires": 1, - "cache_expiry_time": 8, - "clear_site_cache_on_saved_post": 0, - "clear_site_cache_on_saved_comment": 0, - "clear_site_cache_on_saved_term": 0, - "clear_site_cache_on_saved_user": 0, - "clear_site_cache_on_changed_plugin": 0, - "convert_image_urls_to_webp": 0, - "mobile_cache": 0, - "compress_cache": 1, - "minify_html": 1, - "minify_inline_css_js": 1, - "excluded_post_ids": "", - "excluded_page_paths": "", - "excluded_query_strings": "", - "excluded_cookies": "" -}' --format=json +if ! docker compose run wpcli core is-installed ; then + ## Install Wodpress + echo "== Installing WordPress ==" + docker compose run wpcli core install \ + --url=${SERVER_NAME} \ + --title="${WORDPRESS_TITLE}" \ + --admin_user=${WORDPRESS_USER} \ + --admin_email=${WORDPRESS_EMAIL} \ + --admin_password=${WORDPRESS_PASSWORD} \ + --skip-email -echo "== Installing themes ==" -# Theme installation -docker compose run wpcli theme install "${WORDPRESS_THEME_TO_INSTALL}" --activate + ## Configure Permalinks + echo "== Configure Permalinks ==" + docker compose run wpcli rewrite structure '/%postname%/' -echo -e "\nREPORT\n" + ## Install Plugins + ask_yes_no "Do you want to install recommended plugins? [Y/n]" + DOIT=$ANSWER + if [ "$DOIT" = true ]; then + echo "== Install Plugins ==" + + docker compose run wpcli plugin install ${WORDPRESS_PLUGINS_TO_INSTALL} --activate -# List users -echo "== User List ==" -docker compose run wpcli user list -echo "" + ## Enable Redis Cache Object + #docker compose run wpcli redis enable -# Show installed plugin -echo "== Theme List ==" -docker compose run wpcli theme list -echo "" + ## Enable and config Cache Enabler + docker compose run wpcli option update cache_enabler '{ + "version": "1.8.0", + "use_trailing_slashes": 1, + "permalink_structure": "has_trailing_slash", + "cache_expires": 1, + "cache_expiry_time": 8, + "clear_site_cache_on_saved_post": 0, + "clear_site_cache_on_saved_comment": 0, + "clear_site_cache_on_saved_term": 0, + "clear_site_cache_on_saved_user": 0, + "clear_site_cache_on_changed_plugin": 0, + "convert_image_urls_to_webp": 0, + "mobile_cache": 0, + "compress_cache": 1, + "minify_html": 1, + "minify_inline_css_js": 1, + "excluded_post_ids": "", + "excluded_page_paths": "", + "excluded_query_strings": "", + "excluded_cookies": "" + }' --format=json + fi -# Show installed plugin -echo "== Plugin List ==" -docker compose run wpcli plugin list -echo "" + # Theme installation + ask_yes_no "Do you want to install recommended theme? [Y/n]" + DOIT=$ANSWER + if [ "$DOIT" = true ]; then + echo "== Installing themes ==" + docker compose run wpcli theme install "${WORDPRESS_THEME_TO_INSTALL}" --activate + fi + + + echo -e "\nREPORT\n" + + # List users + echo "== User List ==" + docker compose run wpcli user list + echo "" + + # Show installed plugin + echo "== Theme List ==" + docker compose run wpcli theme list + echo "" + + # Show installed plugin + echo "== Plugin List ==" + docker compose run wpcli plugin list + echo "" +else + echo "WordPress is already installed. Exiting now..." +fi