Skip to content

Instantly share code, notes, and snippets.

@chwnam
Created May 3, 2021 05:01
Show Gist options
  • Save chwnam/8ef3a49a10801a0721d79ed255df5c3d to your computer and use it in GitHub Desktop.
Save chwnam/8ef3a49a10801a0721d79ed255df5c3d to your computer and use it in GitHub Desktop.
워드프레스 자동 설치 스크립트 샘플
#!/bin/bash
#
# Changwoo Blog 1일1워프 포스팅
# https://blog.changwoo.pe.kr/wp-install/
if [[ $# -ne 1 ]]; then
echo "Input name, please."
exit
fi
NAME=$1
WP_ROOT="/path/to/wp/root"
DB_ROOT_PASS='0000'
DB_NAME=${NAME/-/_}
DB_USER=${NAME/-/_}
DB_PASS=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w12 | head -n1)
# WP Admin User
ADMIN_USER=user
[email protected]
ADMIN_PASS=pass
# SMTP
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SSL=tls
[email protected]
SMTP_PASS=pass
if [[ -d "${WP_ROOT}" ]]; then
cd "${WP_ROOT}"
if [[ -d "${WP_ROOT}/${NAME}" ]]; then
echo "${WP_ROOT}/${NAME} exists!"
exit
fi
echo "Creating user ${DB_USER} / ${DB_PASS}"
mysql -u"root" -p"${DB_ROOT_PASS}" -e"CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';" || exit
echo "Creating database ${DB_NAME} ..."
mysql -u"root" -p"${DB_ROOT_PASS}" -e"CREATE DATABASE ${DB_NAME};" || exit
echo "Granting privileges on ${DB_USER} ..."
mysql -u"root" -p"${DB_ROOT_PASS}" -e"GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';" || exit
mysql -u"root" -p"${DB_ROOT_PASS}" -e"GRANT ALL PRIVILEGES ON \`${DB_NAME}\_%\`.* TO '${DB_USER}'@'localhost';" || exit
mkdir "${WP_ROOT}/${NAME}"
cd "${NAME}"
wp core download
wp config create --dbname="${DB_NAME}" --dbuser="${DB_USER}" --dbpass="${DB_PASS}" --locale=ko_KR
wp core install --url="http://${NAME}.dev.site" --title="${NAME}" --admin_user="${ADMIN_USER}" --admin_email="${ADMIN_EMAIL}" --admin_password="${ADMIN_PASS}" --skip-email
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_DISPLAY true --raw
wp config set WP_DEBUG_LOG false --raw
wp config set SAVEQUERIES false --raw
wp config set WP_DISABLE_FATAL_ERROR_HANDLER true --raw
wp config set SCRIPT_DEBUG true --raw
wp config set AUTOSAVE_INTERVAL 0 --raw
wp config set WP_POST_REVISIONS false --raw
wp language core install ko_KR --activate
wp option set siteurl "https://${NAME}.dev.site"
wp option set home "https://${NAME}.dev.site"
wp option set timezone_string 'Asia/Seoul'
wp option set date_format 'Y년 F j일'
wp option set time_format 'a g:i'
wp option set blog_public yes
wp option set permalink_structure '/%postname%/'
wp rewrite flush
wp theme delete twentysixteen twentyseventeen
wp plugin delete akismet hello
wp plugin install user-role-editor user-switching debug-bar debug-bar-rewrite-rules debug-bar-slow-actions wp-mail-smtp
# Naran plugins for development.
pushd .
cd ./wp-content/plugins
git clone https://github.com/chwnam/naran-hide-welcome-guide.git
git clone https://github.com/chwnam/naran-persistent-login.git
git clone https://github.com/chwnam/naran-disable-heartbeat.git
git clone https://github.com/chwnam/naran-screen-width.git
git clone https://github.com/chwnam/naran-option-editor.git
git clone [email protected]:chwnam/naran-image-sizes.git
popd
# Naran Persistent Login setup
wp config set NPL_ENABLED true --raw
wp config set NPL_USER changwoo
wp config set NPL_NOTICE no
wp plugin activate \
naran-hide-welcome-guide \
naran-persistent-login \
naran-disable-heartbeat \
naran-screen-width \
naran-option-editor \
naran-image-sizes
# WP Mail SMTP Configuration
wp config set WPMS_ON true --raw
wp config set WPMS_MAILER smtp
wp config set WPMS_SMTP_HOST ${SMTP_HOST}
wp config set WPMS_SMTP_PORT ${SMTP_PORT}
wp config set WPMS_SSL ${SMTP_SSL}
wp config set WPMS_SMTP_AUTH true --raw
wp config set WPMS_SMTP_USER ${SMTP_USER}
wp config set WPMS_SMTP_PASS ${SMTP_PASS}
wp config set WPMS_SMTP_AUTOTLS true --raw
echo "Successfully installed. DB USER/PASS: ${DB_USER} / ${DB_PASS}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment