From e30eb685f23c2d8fea8b912baf019cd666454b44 Mon Sep 17 00:00:00 2001 From: Cold-Egg Date: Fri, 10 Jan 2020 11:47:15 -0500 Subject: [PATCH] scripts update --- .env | 6 --- bin/cert.sh | 40 +++++++++++++++---- bin/container/appinstallctl.sh | 24 ++++++------ bin/domain.sh | 4 +- bin/{setwebadmin.sh => webadmin.sh} | 16 ++++++-- config/litespeed/1.6.4.build/Dockerfile | 4 -- config/litespeed/1.6.4.lh/entrypoint.sh | 51 ------------------------- config/litespeed/1.6.4/entrypoint.sh | 47 +---------------------- lsws/conf/httpd_config.conf | 2 +- lsws/conf/templates/ccl.conf | 3 +- 10 files changed, 66 insertions(+), 131 deletions(-) rename bin/{setwebadmin.sh => webadmin.sh} (62%) diff --git a/.env b/.env index 07d6de2..6eca553 100644 --- a/.env +++ b/.env @@ -7,9 +7,3 @@ MYSQL_PASSWORD=password #wordpress DOMAIN=localhost -ADMIN_USERNAME=admin -ADMIN_PASSWORD=password -ADMIN_EMAIL=test@test.com -WP_TITLE="OpenLiteSpeed running in docker" -WP_DB_PREFIX=wp_ - diff --git a/bin/cert.sh b/bin/cert.sh index bae6c27..0bd6df2 100755 --- a/bin/cert.sh +++ b/bin/cert.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash DOMAIN='' +TYPE=0 help_message(){ echo 'Command [your_domain]' @@ -13,22 +14,49 @@ check_input(){ fi } -strip_www(){ +www_domain(){ CHECK_WWW=$(echo ${1} | cut -c1-4) if [[ ${CHECK_WWW} == www. ]] ; then DOMAIN=$(echo ${1} | cut -c 5-) else DOMAIN=${1} fi + WWW_DOMAIN="www.${DOMAIN}" +} + +domain_verify(){ + curl -Is http://${DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 + if [ ${?} = 0 ]; then + echo "[OK] ${DOMAIN} is accessible." + TYPE=1 + curl -Is http://${WWW_DOMAIN}/ | grep -i LiteSpeed > /dev/null 2>&1 + if [ ${?} = 0 ]; then + echo "[OK] ${WWW_DOMAIN} is accessible." + TYPE=2 + else + echo "${WWW_DOMAIN} is inaccessible." + fi + else + echo "${MY_DOMAIN} is inaccessible, please verify."; exit 1 + fi } lecertapply(){ - docker-compose exec litespeed su -c "certbot certonly --agree-tos --register-unsafely-without-email \ - --non-interactive --webroot -w /var/www/vhosts/${1}/html -d ${1} -d www.${1}" + if [ ${TYPE} = 1 ]; then + docker-compose exec litespeed su -c "certbot certonly --agree-tos --register-unsafely-without-email \ + --non-interactive --webroot -w /var/www/vhosts/${1}/html -d ${1}" + elif [ ${TYPE} = 2 ]; then + docker-compose exec litespeed su -c "certbot certonly --agree-tos --register-unsafely-without-email \ + --non-interactive --webroot -w /var/www/vhosts/${1}/html -d ${1} -d www.${1}" + else + echo 'unknown Type!' + exit 2 + fi } main(){ - strip_www ${1} + www_domain ${1} + domain_verify lecertapply ${DOMAIN} } @@ -43,6 +71,4 @@ while [ ! -z "${1}" ]; do ;; esac shift -done - - +done \ No newline at end of file diff --git a/bin/container/appinstallctl.sh b/bin/container/appinstallctl.sh index e6cb9e6..86c5d0a 100755 --- a/bin/container/appinstallctl.sh +++ b/bin/container/appinstallctl.sh @@ -7,7 +7,7 @@ DOMAIN='' WWW_UID='' WWW_GID='' WP_CONST_CONF='' -PUB_IP=$(curl http://checkip.amazonaws.com) +PUB_IP=$(curl -s http://checkip.amazonaws.com) PLUGINLIST="litespeed-cache.zip" THEME='twentytwenty' @@ -33,18 +33,14 @@ linechange(){ } ck_ed(){ - if [ -f /bin/ed ]; then - echo "ed exist" - else + if [ ! -f /bin/ed ]; then echo "no ed, ready to install" apt-get install ed -y > /dev/null 2>&1 fi } ck_unzip(){ - if [ -f /usr/bin/unzip ]; then - echo "unzip exist" - else + if [ ! -f /usr/bin/unzip ]; then echo "no unzip, ready to install" apt-get install unzip -y > /dev/null 2>&1 fi @@ -239,17 +235,21 @@ app_wordpress_dl(){ wp core download \ --allow-root \ --quiet + else + echo 'wp-config*.php already exist, abort!' + exit 1 + fi +} + +change_owner(){ if [ "${VHNAME}" != '' ]; then chown -R ${WWW_UID}:${WWW_GID} ${DEFAULT_VH_ROOT}/${VHNAME} else chown -R ${WWW_UID}:${WWW_GID} ${DEFAULT_VH_ROOT}/${DOMAIN} fi - else - echo 'wp-config*.php already exist, abort!' - exit 1 - fi } + main(){ set_vh_docroot ${DOMAIN} get_owner @@ -261,6 +261,7 @@ main(){ install_wp_plugin set_htaccess set_lscache + change_owner exit 0 else echo "APP: ${APP_NAME} not support, exit!" @@ -268,6 +269,7 @@ main(){ fi } +check_input ${1} while [ ! -z "${1}" ]; do case ${1} in -[hH] | -help | --help) diff --git a/bin/domain.sh b/bin/domain.sh index 11c4be5..b787496 100755 --- a/bin/domain.sh +++ b/bin/domain.sh @@ -19,12 +19,14 @@ add_domain(){ docker-compose exec ${CONT_NAME} su -s /bin/bash lsadm -c "cd /usr/local/lsws/conf && domainctl.sh -add ${1}" if [ ! -d "./sites/${1}" ]; then mkdir -p ./sites/${1}/{html,logs,certs} - fi + fi + bash bin/webadmin.sh -r } del_domain(){ check_input ${1} docker-compose exec ${CONT_NAME} su -s /bin/bash lsadm -c "cd /usr/local/lsws/conf && domainctl.sh -del ${1}" + bash bin/webadmin.sh -r } check_input ${1} diff --git a/bin/setwebadmin.sh b/bin/webadmin.sh similarity index 62% rename from bin/setwebadmin.sh rename to bin/webadmin.sh index b5bb0e8..988b8f8 100755 --- a/bin/setwebadmin.sh +++ b/bin/webadmin.sh @@ -2,7 +2,10 @@ help_message(){ echo 'Command [PASSWORD]' - echo 'Example: setwebadmin.sh mypassword' + echo 'Example: webadmin.sh mypassword' + echo 'Command [-r]' + echo 'Example: webadmin.sh -r' + echo 'Will restart LiteSpeed Web Server' exit 0 } @@ -18,8 +21,12 @@ set_web_admin(){ 'echo "admin:$(/usr/local/lsws/admin/fcgi-bin/admin_php* -q /usr/local/lsws/admin/misc/htpasswd.php '${1}')" > /usr/local/lsws/admin/conf/htpasswd'; } +lsws_restart(){ + docker-compose exec litespeed su -c '/usr/local/lsws/bin/lswsctrl restart' +} + main(){ - set_web_admin + set_web_admin ${1} } check_input ${1} @@ -27,7 +34,10 @@ while [ ! -z "${1}" ]; do case ${1} in -[hH] | -help | --help) help_message - ;; + ;; + -[rR] | -restart | --restart) + lsws_restart + ;; *) main ${1} ;; diff --git a/config/litespeed/1.6.4.build/Dockerfile b/config/litespeed/1.6.4.build/Dockerfile index ef3dc70..76a9c60 100644 --- a/config/litespeed/1.6.4.build/Dockerfile +++ b/config/litespeed/1.6.4.build/Dockerfile @@ -16,7 +16,3 @@ RUN apt-get install -y software-properties-common && \ apt-get install -y certbot python-certbot-apache - -#RUN echo "admin:$(/usr/local/lsws/admin/fcgi-bin/admin_php* -q /usr/local/lsws/admin/misc/htpasswd.php ${WEB_ADMIN_PASSWORD})" \ -# > /usr/local/lsws/admin/conf/htpasswd - diff --git a/config/litespeed/1.6.4.lh/entrypoint.sh b/config/litespeed/1.6.4.lh/entrypoint.sh index 8cdfe03..c634dc9 100644 --- a/config/litespeed/1.6.4.lh/entrypoint.sh +++ b/config/litespeed/1.6.4.lh/entrypoint.sh @@ -1,55 +1,4 @@ #!/bin/bash chown 999:999 /usr/local/lsws/conf -R chown 999:1000 /usr/local/lsws/admin/conf -R -cd /var/www/vhosts/localhost/html -if [ ! -f "./wp-config.php" ]; then - # su -s /bin/bash www-data -c - COUNTER=0 - until [ "$(curl -v mysql:3306 2>&1 | grep native)" ]; - do - echo "Counter: ${COUNTER}" - COUNTER=$((COUNTER+1)) - if [ ${COUNTER} = 10 ]; then - echo '--- MySQL is starting, please wait... ---' - elif [ ${COUNTER} = 60 ]; then - echo '--- MySQL is timeout, exit! ---' - exit 1 - fi - sleep 1 - done - wp core download \ - --allow-root \ - --force - wp core config \ - --dbname="${MYSQL_DATABASE}" \ - --dbuser="${MYSQL_USER}" \ - --dbpass="${MYSQL_PASSWORD}" \ - --dbhost=mysql \ - --dbprefix="${WP_DB_PREFIX}" \ - --allow-root \ - --force - wp core install \ - --title="${WP_TITLE}" \ - --url="${DOMAIN}" \ - --admin_user="${ADMIN_USERNAME}" \ - --admin_email="${ADMIN_EMAIL}" \ - --admin_password="${ADMIN_PASSWORD}" \ - --skip-email \ - --allow-root - wp plugin install litespeed-cache \ - --activate \ - --allow-root - first_www_uid=$(stat -c "%u" /var/www/vhosts/localhost) - first_www_gid=$(stat -c "%g" /var/www/vhosts/localhost) - chown $first_www_uid:$first_www_gid /var/www/vhosts/localhost -R - -fi - -www_uid=$(stat -c "%u" /var/www/vhosts/localhost) -if [ ${www_uid} -eq 0 ]; then - #echo "./sites/localhost is owned by root, auto changing ownership of ./sites/localhost to uid 1000" - chown 1000:1000 /var/www/vhosts/localhost -R -fi - -echo "WordPress installation finished." exec "$@" diff --git a/config/litespeed/1.6.4/entrypoint.sh b/config/litespeed/1.6.4/entrypoint.sh index 15db6da..e08c451 100644 --- a/config/litespeed/1.6.4/entrypoint.sh +++ b/config/litespeed/1.6.4/entrypoint.sh @@ -1,49 +1,4 @@ #!/bin/bash chown 999:999 /usr/local/lsws/conf -R -cd /var/www/html -if [ ! -f "./wp-config.php" ]; then - # su -s /bin/bash www-data -c - COUNTER=0 - until [ "$(curl -v mysql:3306 2>&1 | grep native)" ]; - do - echo "Counter: ${COUNTER}" - COUNTER=$((COUNTER+1)) - if [ ${COUNTER} = 10 ]; then - echo '--- MySQL is starting, please wait... ---' - elif [ ${COUNTER} = 100 ]; then - echo '--- MySQL is timeout, exit! ---' - exit 1 - fi - sleep 1 - done - wp core download \ - --allow-root \ - --force - wp core config \ - --dbname="${MYSQL_DATABASE}" \ - --dbuser="${MYSQL_USER}" \ - --dbpass="${MYSQL_PASSWORD}" \ - --dbhost=mysql \ - --dbprefix="${WP_DB_PREFIX}" \ - --allow-root \ - --force - wp core install \ - --title="${WP_TITLE}" \ - --url="${DOMAIN}" \ - --admin_user="${ADMIN_USERNAME}" \ - --admin_email="${ADMIN_EMAIL}" \ - --admin_password="${ADMIN_PASSWORD}" \ - --skip-email \ - --allow-root - wp plugin install litespeed-cache \ - --activate \ - --allow-root -fi - -www_uid=$(stat -c "%u" /var/www/vhosts/localhost) -if [ ${www_uid} -eq 0 ]; then - chown 1000:1000 /var/www/vhosts/localhost -R -fi - -echo "WordPress installation finished." +chown 999:1000 /usr/local/lsws/admin/conf -R exec "$@" \ No newline at end of file diff --git a/lsws/conf/httpd_config.conf b/lsws/conf/httpd_config.conf index 817cc86..646b6ef 100644 --- a/lsws/conf/httpd_config.conf +++ b/lsws/conf/httpd_config.conf @@ -237,7 +237,7 @@ vhTemplate centralConfigLog { listeners Default, HTTP, HTTPS member localhost { - vhDomain localhost + vhDomain localhost, * } } diff --git a/lsws/conf/templates/ccl.conf b/lsws/conf/templates/ccl.conf index 6071729..8c92b75 100644 --- a/lsws/conf/templates/ccl.conf +++ b/lsws/conf/templates/ccl.conf @@ -50,7 +50,8 @@ RewriteFile .htaccess } rewrite { - enable 0 + enable 1 + autoLoadHtaccess 1 logLevel 0 }