/wordpress-install.sh
Shell | 199 lines | 124 code | 64 blank | 11 comment | 10 complexity | 46c31db0859b11b7032d28e7cbf5c702 MD5 | raw file
- #!/bin/bash
- WP_TITLE=$1
- WP_ID=${WP_TITLE,,}
- WP_HOST=${WP_ID}.wp.net
- WP_URL=https://${WP_HOST}
- WP_VERSION=latest
- WP_PATH=$BASE_PATH/$WP_ID/wordpress
- WP_LOG_FILE=$BASE_PATH/$WP_ID/wordpress.log
- WP_NGINX_CACHE_PATH=$WP_PATH/wp-content/cache/nginx
- WP_DB_NAME=wordpress_${WP_ID}
- WP_DB_USER=root
- WP_DB_PASSWORD=root
- WP_DB_HOST=localhost
- WP_DB_CHARSET=utf8mb4
- WP_DB_COLLATE=utf8mb4_general_ci
- WP_THEME_SLUG=${WP_ID,,}theme
- WP_THEME_NAME=${WP_TITLE}Theme
- WP_THEME_CONSTANT_PREFIX=${WP_THEME_NAME^^}
- WP_THEME_BASE_PATH=$WP_PATH/wp-content/themes
- WP_THEME_PATH=$WP_THEME_BASE_PATH/$WP_THEME_SLUG
- WP_THEME_REF=basetheme
- WP_THEME_REF_PATH=$WORDPRESS_UTILS/resources/themes/$WP_THEME_REF
- WP_PLUGINS=(
- "wp-redis"
- "nginx-cache"
- )
- WP_PLUGINS_INACTIVE=(
- )
- WP_PLUGINS_LOCAL=(
- )
- if [ "$SERVER_PORT" != "443" ]; then
- WP_URL=$WP_URL:$SERVER_PORT
- fi
- if [ -z "$WP_ID" ]; then
- exit
- fi
- if [ -d "$WP_PATH" ]; then
- rm -rf "${BASE_PATH}/${WP_ID}"
- fi
- mkdir -p $WP_PATH
- cd $WP_PATH
- # .ENV --------------------
- salt () {
- </dev/urandom tr -dc '1234567890abcdefghijklmnopqrstuvwxyz' | head -c$1; echo ""
- }
- cat <<EOT > $BASE_PATH/$WP_ID/.env
- WORDPRESS_DB_NAME=$WP_DB_NAME
- WORDPRESS_DB_USER=$WP_DB_USER
- WORDPRESS_DB_PASSWORD=$WP_DB_PASSWORD
- WORDPRESS_DB_HOST=$WP_DB_HOST
- WORDPRESS_DB_CHARSET=$WP_DB_CHARSET
- WORDPRESS_DB_COLLATE=$WP_DB_COLLATE
- WORDPRESS_REDIS_HOST=127.0.0.1
- WORDPRESS_REDIS_PORT=6379
- WORDPRESS_REDIS_AUTH=null
- WORDPRESS_REDIS_DATABASE=0
- WORDPRESS_WP_DEBUG=true
- WORDPRESS_WP_DEBUG_DISPLAY=false
- WORDPRESS_WP_DEBUG_LOG=$WP_LOG_FILE
- WORDPRESS_AUTH_KEY=$(salt 64)
- WORDPRESS_AUTH_SALT=$(salt 64)
- WORDPRESS_SECURE_AUTH_KEY=$(salt 64)
- WORDPRESS_SECURE_AUTH_SALT=$(salt 64)
- WORDPRESS_LOGGED_IN_KEY=$(salt 64)
- WORDPRESS_LOGGED_IN_SALT=$(salt 64)
- WORDPRESS_NONCE_KEY=$(salt 64)
- WORDPRESS_NONCE_SALT=$(salt 64)
- WORDPRESS_WP_CACHE_KEY_SALT=$(salt 4)--
- EOT
- # DB SETUP --------------------
- 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;"
- # WP INSTALL --------------------
- wp core download --locale=en_US --version=$WP_VERSION --skip-content
- wp config create --dbname=$WP_DB_NAME --dbuser=$WP_DB_USER --dbpass=$WP_DB_PASSWORD --dbcharset=utf8mb4
- wp core install --url=${WP_URL} --title=$WP_TITLE --admin_user=admin --admin_password=admin --admin_email=admin@local.com --skip-email
- # WP PLUGINS --------------------
- for plugin in "${WP_PLUGINS[@]}"; do
- wp plugin install $plugin --activate
- done
- for plugin in "${WP_PLUGINS_INACTIVE[@]}"; do
- wp plugin install $plugin
- done
- for plugin in "${WP_PLUGINS_LOCAL[@]}"; do
- wp plugin install $WORDPRESS_UTILS/resources/plugins/${plugin} --activate
- done
- # WP OPTIONS --------------------
- mkdir -p $WP_NGINX_CACHE_PATH
- echo '/%postname%/' | wp option update permalink_structure
- wp option update start_of_week '0'
- wp option update timezone_string 'America/Lima'
- wp option update nginx_auto_purge '1'
- wp option update nginx_cache_path $WP_NGINX_CACHE_PATH
- # WP THEME --------------------
- mkdir -p $WP_THEME_BASE_PATH
- cp -R $WP_THEME_REF_PATH $WP_THEME_BASE_PATH
- mv $WP_THEME_BASE_PATH/$WP_THEME_REF $WP_THEME_PATH
- find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/basetheme/$WP_THEME_SLUG/g"
- find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/BaseTheme/$WP_THEME_NAME/g"
- find $WP_THEME_PATH -type f -print0 | xargs -0 sed -i "s/BASETHEME/$WP_THEME_CONSTANT_PREFIX/g"
- cd $WP_THEME_PATH
- composer install && composer dump-autoload
- npm install
- cd $WP_PATH
- wp theme activate $WP_THEME_SLUG
- # WP CONFIG --------------------
- cp -f $WORDPRESS_UTILS/resources/wp-config.php $WP_PATH
- sed -i "s/{WP_THEME}/$WP_THEME_SLUG/g" $WP_PATH/wp-config.php
- cd $WP_PATH/wp-content
- ln -s plugins/wp-redis/object-cache.php object-cache.php
- cd $WP_PATH
- cp -f $WORDPRESS_UTILS/resources/wordpress.gitignore $BASE_PATH/$WP_ID/.gitignore
- # CLEAN FILES --------------------
- FILES_TO_CLEAN=(
- ".htaccess"
- "readme.html"
- "license.txt"
- "wp-config-sample.php"
- )
- for file in "${FILES_TO_CLEAN[@]}"; do
- if [ -f "$WP_PATH/$file" ]; then
- rm $WP_PATH/$file
- fi
- done
- # WP LANGUAGE UPDATES --------------------
- wp language core update
- wp language theme update --all
- wp language plugin update --all
- # NGINX CONF --------------------
- NGINXCONF_FILE=$NGINXCONF_PATH/$WP_HOST.conf
- cp $WORDPRESS_UTILS/nginx/server.conf $NGINXCONF_FILE
- sed -i "s|{HOST}|$WP_HOST|g" $NGINXCONF_FILE
- sed -i "s|{PORT}|$SERVER_PORT|g" $NGINXCONF_FILE
- sed -i "s|{DOCROOT}|$WP_PATH|g" $NGINXCONF_FILE
- sed -i "s|{CACHE_PATH}|$WP_NGINX_CACHE_PATH|g" $NGINXCONF_FILE
- sed -i "s|{CONF_PATH}|$WORDPRESS_UTILS|g" $NGINXCONF_FILE