PageRenderTime 140ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress-install.sh

https://gitlab.com/leo020588/wordpress-wsl
Shell | 199 lines | 124 code | 64 blank | 11 comment | 10 complexity | 46c31db0859b11b7032d28e7cbf5c702 MD5 | raw file
  1. #!/bin/bash
  2. WP_TITLE=$1
  3. WP_ID=${WP_TITLE,,}
  4. WP_HOST=${WP_ID}.wp.net
  5. WP_URL=https://${WP_HOST}
  6. WP_VERSION=latest
  7. WP_PATH=$BASE_PATH/$WP_ID/wordpress
  8. WP_LOG_FILE=$BASE_PATH/$WP_ID/wordpress.log
  9. WP_NGINX_CACHE_PATH=$WP_PATH/wp-content/cache/nginx
  10. WP_DB_NAME=wordpress_${WP_ID}
  11. WP_DB_USER=root
  12. WP_DB_PASSWORD=root
  13. WP_DB_HOST=localhost
  14. WP_DB_CHARSET=utf8mb4
  15. WP_DB_COLLATE=utf8mb4_general_ci
  16. WP_THEME_SLUG=${WP_ID,,}theme
  17. WP_THEME_NAME=${WP_TITLE}Theme
  18. WP_THEME_CONSTANT_PREFIX=${WP_THEME_NAME^^}
  19. WP_THEME_BASE_PATH=$WP_PATH/wp-content/themes
  20. WP_THEME_PATH=$WP_THEME_BASE_PATH/$WP_THEME_SLUG
  21. WP_THEME_REF=basetheme
  22. WP_THEME_REF_PATH=$WORDPRESS_UTILS/resources/themes/$WP_THEME_REF
  23. WP_PLUGINS=(
  24. "wp-redis"
  25. "nginx-cache"
  26. )
  27. WP_PLUGINS_INACTIVE=(
  28. )
  29. WP_PLUGINS_LOCAL=(
  30. )
  31. if [ "$SERVER_PORT" != "443" ]; then
  32. WP_URL=$WP_URL:$SERVER_PORT
  33. fi
  34. if [ -z "$WP_ID" ]; then
  35. exit
  36. fi
  37. if [ -d "$WP_PATH" ]; then
  38. rm -rf "${BASE_PATH}/${WP_ID}"
  39. fi
  40. mkdir -p $WP_PATH
  41. cd $WP_PATH
  42. # .ENV --------------------
  43. salt () {
  44. </dev/urandom tr -dc '1234567890abcdefghijklmnopqrstuvwxyz' | head -c$1; echo ""
  45. }
  46. cat <<EOT > $BASE_PATH/$WP_ID/.env
  47. WORDPRESS_DB_NAME=$WP_DB_NAME
  48. WORDPRESS_DB_USER=$WP_DB_USER
  49. WORDPRESS_DB_PASSWORD=$WP_DB_PASSWORD
  50. WORDPRESS_DB_HOST=$WP_DB_HOST
  51. WORDPRESS_DB_CHARSET=$WP_DB_CHARSET
  52. WORDPRESS_DB_COLLATE=$WP_DB_COLLATE
  53. WORDPRESS_REDIS_HOST=127.0.0.1
  54. WORDPRESS_REDIS_PORT=6379
  55. WORDPRESS_REDIS_AUTH=null
  56. WORDPRESS_REDIS_DATABASE=0
  57. WORDPRESS_WP_DEBUG=true
  58. WORDPRESS_WP_DEBUG_DISPLAY=false
  59. WORDPRESS_WP_DEBUG_LOG=$WP_LOG_FILE
  60. WORDPRESS_AUTH_KEY=$(salt 64)
  61. WORDPRESS_AUTH_SALT=$(salt 64)
  62. WORDPRESS_SECURE_AUTH_KEY=$(salt 64)
  63. WORDPRESS_SECURE_AUTH_SALT=$(salt 64)
  64. WORDPRESS_LOGGED_IN_KEY=$(salt 64)
  65. WORDPRESS_LOGGED_IN_SALT=$(salt 64)
  66. WORDPRESS_NONCE_KEY=$(salt 64)
  67. WORDPRESS_NONCE_SALT=$(salt 64)
  68. WORDPRESS_WP_CACHE_KEY_SALT=$(salt 4)--
  69. EOT
  70. # DB SETUP --------------------
  71. mysql -u $WP_DB_USER -p$WP_DB_PASSWORD -e "DROP DATABASE IF EXISTS $WP_DB_NAME; CREATE DATABASE $WP_DB_NAME CHARACTER SET $WP_DB_CHARSET COLLATE $WP_DB_COLLATE;"
  72. # WP INSTALL --------------------
  73. wp core download --locale=en_US --version=$WP_VERSION --skip-content
  74. wp config create --dbname=$WP_DB_NAME --dbuser=$WP_DB_USER --dbpass=$WP_DB_PASSWORD --dbcharset=utf8mb4
  75. wp core install --url=${WP_URL} --title=$WP_TITLE --admin_user=admin --admin_password=admin --admin_email=admin@local.com --skip-email
  76. # WP PLUGINS --------------------
  77. for plugin in "${WP_PLUGINS[@]}"; do
  78. wp plugin install $plugin --activate
  79. done
  80. for plugin in "${WP_PLUGINS_INACTIVE[@]}"; do
  81. wp plugin install $plugin
  82. done
  83. for plugin in "${WP_PLUGINS_LOCAL[@]}"; do
  84. wp plugin install $WORDPRESS_UTILS/resources/plugins/${plugin} --activate
  85. done
  86. # WP OPTIONS --------------------
  87. mkdir -p $WP_NGINX_CACHE_PATH
  88. echo '/%postname%/' | wp option update permalink_structure
  89. wp option update start_of_week '0'
  90. wp option update timezone_string 'America/Lima'
  91. wp option update nginx_auto_purge '1'
  92. wp option update nginx_cache_path $WP_NGINX_CACHE_PATH
  93. # WP THEME --------------------
  94. mkdir -p $WP_THEME_BASE_PATH
  95. cp -R $WP_THEME_REF_PATH $WP_THEME_BASE_PATH
  96. mv $WP_THEME_BASE_PATH/$WP_THEME_REF $WP_THEME_PATH
  97. find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/basetheme/$WP_THEME_SLUG/g"
  98. find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/BaseTheme/$WP_THEME_NAME/g"
  99. find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/BASETHEME/$WP_THEME_CONSTANT_PREFIX/g"
  100. cd $WP_THEME_PATH
  101. composer install && composer dump-autoload
  102. npm install
  103. cd $WP_PATH
  104. wp theme activate $WP_THEME_SLUG
  105. # WP CONFIG --------------------
  106. cp -f $WORDPRESS_UTILS/resources/wp-config.php $WP_PATH
  107. sed -i "s/{WP_THEME}/$WP_THEME_SLUG/g" $WP_PATH/wp-config.php
  108. cd $WP_PATH/wp-content
  109. ln -s plugins/wp-redis/object-cache.php object-cache.php
  110. cd $WP_PATH
  111. cp -f $WORDPRESS_UTILS/resources/wordpress.gitignore $BASE_PATH/$WP_ID/.gitignore
  112. # CLEAN FILES --------------------
  113. FILES_TO_CLEAN=(
  114. ".htaccess"
  115. "readme.html"
  116. "license.txt"
  117. "wp-config-sample.php"
  118. )
  119. for file in "${FILES_TO_CLEAN[@]}"; do
  120. if [ -f "$WP_PATH/$file" ]; then
  121. rm $WP_PATH/$file
  122. fi
  123. done
  124. # WP LANGUAGE UPDATES --------------------
  125. wp language core update
  126. wp language theme update --all
  127. wp language plugin update --all
  128. # NGINX CONF --------------------
  129. NGINXCONF_FILE=$NGINXCONF_PATH/$WP_HOST.conf
  130. cp $WORDPRESS_UTILS/nginx/server.conf $NGINXCONF_FILE
  131. sed -i "s|{HOST}|$WP_HOST|g" $NGINXCONF_FILE
  132. sed -i "s|{PORT}|$SERVER_PORT|g" $NGINXCONF_FILE
  133. sed -i "s|{DOCROOT}|$WP_PATH|g" $NGINXCONF_FILE
  134. sed -i "s|{CACHE_PATH}|$WP_NGINX_CACHE_PATH|g" $NGINXCONF_FILE
  135. sed -i "s|{CONF_PATH}|$WORDPRESS_UTILS|g" $NGINXCONF_FILE