From cc073c305c3babe566b5d2181dd98a61db8cc640 Mon Sep 17 00:00:00 2001 From: Cold-Egg Date: Fri, 14 Feb 2020 11:21:38 -0500 Subject: [PATCH] update demo sh --- bin/cert.sh | 16 ++++---- bin/container/appinstallctl.sh | 8 ++-- bin/demosite.sh | 68 ++++++++++++++++++++++++---------- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/bin/cert.sh b/bin/cert.sh index 13ecb93..2889624 100755 --- a/bin/cert.sh +++ b/bin/cert.sh @@ -52,9 +52,9 @@ email_filter(){ fi CKREG="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$" if [[ ${1} =~ ${CKREG} ]] ; then - echo -e "[O] The E-mail you entered \033[32m${EMAIL}\033[0m is valid." + echo -e "[O] The E-mail \033[32m${EMAIL}\033[0m is valid." else - echo -e "[X] The E-mail you entered \e[31m${EMAIL}\e[39m is invalid" + echo -e "[X] The E-mail \e[31m${EMAIL}\e[39m is invalid" exit 1 fi fi @@ -73,17 +73,17 @@ www_domain(){ domain_verify(){ curl -Is http://${DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 if [ ${?} = 0 ]; then - echo -e "[O] The domain you entered \033[32m${DOMAIN}\033[0m is accessible." + echo -e "[O] The domain name \033[32m${DOMAIN}\033[0m is accessible." TYPE=1 curl -Is http://${WWW_DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 if [ ${?} = 0 ]; then - echo -e "[O] The domain you entered \033[32m${WWW_DOMAIN}\033[0m is accessible." + echo -e "[O] The domain name \033[32m${WWW_DOMAIN}\033[0m is accessible." TYPE=2 else - echo -e "[!] The domain you entered ${WWW_DOMAIN} is inaccessible." + echo -e "[!] The domain name ${WWW_DOMAIN} is inaccessible." fi else - echo -e "[X] The domain you entered \e[31m${DOMAIN}\e[39m is inaccessible, please verify." + echo -e "[X] The domain name \e[31m${DOMAIN}\e[39m is inaccessible, please verify." exit 1 fi } @@ -96,9 +96,9 @@ doc_root_verify(){ fi docker-compose exec ${CONT_NAME} su -c "[ -e ${DOC_PATH} ]" if [ ${?} -eq 0 ]; then - echo -e "[O] The document root folder \033[32m${DOC_PATH}\033[0m is exit." + echo -e "[O] The document root folder \033[32m${DOC_PATH}\033[0m does exist." else - echo -e "[X] The document root folder you entered \e[31m${DOC_PATH}\e[39m is not exist!" + echo -e "[X] The document root folder \e[31m${DOC_PATH}\e[39m does not exist!" exit 1 fi } diff --git a/bin/container/appinstallctl.sh b/bin/container/appinstallctl.sh index 21251b4..66c11e0 100755 --- a/bin/container/appinstallctl.sh +++ b/bin/container/appinstallctl.sh @@ -35,14 +35,14 @@ linechange(){ ck_ed(){ if [ ! -f /bin/ed ]; then - echo "Install ed .." + echo "Install ed package.." apt-get install ed -y > /dev/null 2>&1 fi } ck_unzip(){ if [ ! -f /usr/bin/unzip ]; then - echo "Install unzip .." + echo "Install unzip package.." apt-get install unzip -y > /dev/null 2>&1 fi } @@ -51,9 +51,9 @@ get_owner(){ WWW_UID=$(stat -c "%u" ${DEFAULT_VH_ROOT}) WWW_GID=$(stat -c "%g" ${DEFAULT_VH_ROOT}) if [ ${WWW_UID} -eq 0 ] || [ ${WWW_GID} -eq 0 ]; then - echo "Found ${WWW_UID}:${WWW_GID} has root, will auto fix to 1000" WWW_UID=1000 WWW_GID=1000 + echo "Set owner to ${WWW_UID}" fi } @@ -238,7 +238,7 @@ app_wordpress_dl(){ --allow-root \ --quiet else - echo 'wp-config*.php already exist, abort!' + echo 'wordpress already exist, abort!' exit 1 fi } diff --git a/bin/demosite.sh b/bin/demosite.sh index d5e0e5b..d64f8d7 100755 --- a/bin/demosite.sh +++ b/bin/demosite.sh @@ -1,57 +1,87 @@ #!/usr/bin/env bash source .env -DEMO_VH='localhost' APP_NAME='wordpress' CONT_NAME='litespeed' -DEMO_PATH="/var/www/${DEMO_VH}" +DOC_FD='' help_message(){ - echo 'Script will get database password and wordpress password from .env file and install the demo wordpress site for you' + case ${1} in + "1") + echo "Script will get 'DOMAIN' and 'database info'from .env file and install the wordpress site for you at the first time." + ;; + "2") + echo 'Service finished, enjoy your accelarated LiteSpeed server!' + ;; + esac } -check_input(){ - if [ -z "${1}" ]; then - help_message +domain_filter(){ + if [ ! -n "${DOMAIN}" ]; then + echo "Parameters not supplied, please check!" exit 1 fi + DOMAIN="${1}" + DOMAIN="${DOMAIN#http://}" + DOMAIN="${DOMAIN#https://}" + DOMAIN="${DOMAIN#ftp://}" + DOMAIN="${DOMAIN#scp://}" + DOMAIN="${DOMAIN#scp://}" + DOMAIN="${DOMAIN#sftp://}" + DOMAIN=${DOMAIN%%/*} } -store_credential(){ +gen_root_fd(){ + DOC_FD="./sites/${1}/" if [ -d "./sites/${1}" ]; then - if [ -f ./sites/${1}/.db_pass ]; then - mv ./sites/${1}/.db_pass ./sites/${1}/.db_pass.bk - fi - cat > "./sites/${1}/.db_pass" << EOT + echo -e "[O] The root folder \033[32m${DOC_FD}\033[0m exist." + else + echo "Creating document root..." + bash bin/domain.sh -add ${1} + echo "Finished document root." + fi +} + +store_credential(){ + if [ -f ${DOC_FD}/.db_pass ]; then + echo 'Back up old db file.' + mv ${DOC_FD}/.db_pass ${DOC_FD}/.db_pass.bk + fi + if [ ! -n "${MYSQL_DATABASE}" ] || [ ! -n "${MYSQL_USER}" ] || [ ! -n "${MYSQL_PASSWORD}" ]; then + echo "Parameters not supplied, please check!" + exit 1 + fi + echo 'Storing database parameter' + cat > "${DOC_FD}/.db_pass" << EOT "Database":"${MYSQL_DATABASE}" "Username":"${MYSQL_USER}" "Password":"$(echo ${MYSQL_PASSWORD} | tr -d "'")" EOT - else - echo "./sites/${1} not found, abort credential store!" - fi } app_download(){ - docker-compose exec ${CONT_NAME} su -c "appinstallctl.sh -app ${1} -domain ${2} -vhname ${DEMO_VH}" + docker-compose exec ${CONT_NAME} su -c "appinstallctl.sh -app ${1} -domain ${2}" } lsws_restart(){ - docker-compose exec ${CONT_NAME} su -c '/usr/local/lsws/bin/lswsctrl restart >/dev/null' + bash bin/webadmin.sh -r } main(){ - store_credential ${DEMO_VH} + domain_filter ${DOMAIN} + gen_root_fd ${DOMAIN} + store_credential app_download ${APP_NAME} ${DOMAIN} lsws_restart + help_message 2 } while [ ! -z "${1}" ]; do case ${1} in -[hH] | -help | --help) - help_message + help_message 1 ;; *) - help_message + help_message 1 ;; esac shift