update demo sh

master
Cold-Egg 5 years ago
parent 6d5bf46f70
commit cc073c305c

@ -52,9 +52,9 @@ email_filter(){
fi 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])?\$" 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 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 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 exit 1
fi fi
fi fi
@ -73,17 +73,17 @@ www_domain(){
domain_verify(){ domain_verify(){
curl -Is http://${DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 curl -Is http://${DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1
if [ ${?} = 0 ]; then 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 TYPE=1
curl -Is http://${WWW_DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 curl -Is http://${WWW_DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1
if [ ${?} = 0 ]; then 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 TYPE=2
else else
echo -e "[!] The domain you entered ${WWW_DOMAIN} is inaccessible." echo -e "[!] The domain name ${WWW_DOMAIN} is inaccessible."
fi fi
else 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 exit 1
fi fi
} }
@ -96,9 +96,9 @@ doc_root_verify(){
fi fi
docker-compose exec ${CONT_NAME} su -c "[ -e ${DOC_PATH} ]" docker-compose exec ${CONT_NAME} su -c "[ -e ${DOC_PATH} ]"
if [ ${?} -eq 0 ]; then 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 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 exit 1
fi fi
} }

@ -35,14 +35,14 @@ linechange(){
ck_ed(){ ck_ed(){
if [ ! -f /bin/ed ]; then if [ ! -f /bin/ed ]; then
echo "Install ed .." echo "Install ed package.."
apt-get install ed -y > /dev/null 2>&1 apt-get install ed -y > /dev/null 2>&1
fi fi
} }
ck_unzip(){ ck_unzip(){
if [ ! -f /usr/bin/unzip ]; then if [ ! -f /usr/bin/unzip ]; then
echo "Install unzip .." echo "Install unzip package.."
apt-get install unzip -y > /dev/null 2>&1 apt-get install unzip -y > /dev/null 2>&1
fi fi
} }
@ -51,9 +51,9 @@ get_owner(){
WWW_UID=$(stat -c "%u" ${DEFAULT_VH_ROOT}) WWW_UID=$(stat -c "%u" ${DEFAULT_VH_ROOT})
WWW_GID=$(stat -c "%g" ${DEFAULT_VH_ROOT}) WWW_GID=$(stat -c "%g" ${DEFAULT_VH_ROOT})
if [ ${WWW_UID} -eq 0 ] || [ ${WWW_GID} -eq 0 ]; then 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_UID=1000
WWW_GID=1000 WWW_GID=1000
echo "Set owner to ${WWW_UID}"
fi fi
} }
@ -238,7 +238,7 @@ app_wordpress_dl(){
--allow-root \ --allow-root \
--quiet --quiet
else else
echo 'wp-config*.php already exist, abort!' echo 'wordpress already exist, abort!'
exit 1 exit 1
fi fi
} }

@ -1,57 +1,87 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .env source .env
DEMO_VH='localhost'
APP_NAME='wordpress' APP_NAME='wordpress'
CONT_NAME='litespeed' CONT_NAME='litespeed'
DEMO_PATH="/var/www/${DEMO_VH}" DOC_FD=''
help_message(){ 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(){ domain_filter(){
if [ -z "${1}" ]; then if [ ! -n "${DOMAIN}" ]; then
help_message echo "Parameters not supplied, please check!"
exit 1 exit 1
fi 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 [ -d "./sites/${1}" ]; then
if [ -f ./sites/${1}/.db_pass ]; then echo -e "[O] The root folder \033[32m${DOC_FD}\033[0m exist."
mv ./sites/${1}/.db_pass ./sites/${1}/.db_pass.bk 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 fi
cat > "./sites/${1}/.db_pass" << EOT 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}" "Database":"${MYSQL_DATABASE}"
"Username":"${MYSQL_USER}" "Username":"${MYSQL_USER}"
"Password":"$(echo ${MYSQL_PASSWORD} | tr -d "'")" "Password":"$(echo ${MYSQL_PASSWORD} | tr -d "'")"
EOT EOT
else
echo "./sites/${1} not found, abort credential store!"
fi
} }
app_download(){ 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(){ lsws_restart(){
docker-compose exec ${CONT_NAME} su -c '/usr/local/lsws/bin/lswsctrl restart >/dev/null' bash bin/webadmin.sh -r
} }
main(){ main(){
store_credential ${DEMO_VH} domain_filter ${DOMAIN}
gen_root_fd ${DOMAIN}
store_credential
app_download ${APP_NAME} ${DOMAIN} app_download ${APP_NAME} ${DOMAIN}
lsws_restart lsws_restart
help_message 2
} }
while [ ! -z "${1}" ]; do while [ ! -z "${1}" ]; do
case ${1} in case ${1} in
-[hH] | -help | --help) -[hH] | -help | --help)
help_message help_message 1
;; ;;
*) *)
help_message help_message 1
;; ;;
esac esac
shift shift

Loading…
Cancel
Save