From 3a1aa4c6fbca047e9d353dd6740bba19c1934a5d Mon Sep 17 00:00:00 2001 From: Cold-Egg Date: Wed, 15 Jan 2020 15:34:04 -0500 Subject: [PATCH] add hook, fix demo script --- bin/cert.sh | 6 ++++++ bin/container/appinstallctl.sh | 2 +- bin/container/certhookctl.sh | 12 ++++++++++++ bin/demosite.sh | 21 +++++++++++++++------ config/litespeed/1.6.5.lh/Dockerfile | 2 ++ 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 bin/container/certhookctl.sh diff --git a/bin/cert.sh b/bin/cert.sh index f7c7bd1..89dedee 100755 --- a/bin/cert.sh +++ b/bin/cert.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash DOMAIN='' TYPE=0 +CONT_NAME='litespeed' help_message(){ echo 'Command [your_domain]' @@ -54,10 +55,15 @@ lecertapply(){ fi } +certbothook(){ + docker-compose exec ${CONT_NAME} su -s /bin/bash -c "certhookctl.sh" +} + main(){ www_domain ${1} domain_verify lecertapply ${DOMAIN} + certbothook bash bin/webadmin.sh -r } diff --git a/bin/container/appinstallctl.sh b/bin/container/appinstallctl.sh index 065794b..21251b4 100755 --- a/bin/container/appinstallctl.sh +++ b/bin/container/appinstallctl.sh @@ -71,7 +71,7 @@ set_vh_docroot(){ if [ "${VHNAME}" != '' ]; then VH_ROOT="${DEFAULT_VH_ROOT}/${VHNAME}" VH_DOC_ROOT="${DEFAULT_VH_ROOT}/${VHNAME}/html" - WP_CONS_TCONF="${VH_DOC_ROOT}/wp-content/plugins/litespeed-cache/data/const.default.ini" + WP_CONST_CONF="${VH_DOC_ROOT}/wp-content/plugins/litespeed-cache/data/const.default.ini" elif [ -d ${DEFAULT_VH_ROOT}/${1}/html ]; then VH_ROOT="${DEFAULT_VH_ROOT}/${1}" VH_DOC_ROOT="${DEFAULT_VH_ROOT}/${1}/html" diff --git a/bin/container/certhookctl.sh b/bin/container/certhookctl.sh new file mode 100644 index 0000000..8ce3fe0 --- /dev/null +++ b/bin/container/certhookctl.sh @@ -0,0 +1,12 @@ +#!/bin/bash +BOTCRON='/etc/cron.d/certbot' + +certbothook(){ + grep 'lswsctrl restart' ${BOTCRON} >/dev/null + if [ ${?} = 1 ]; then + echo 'Add LSWS hook to certbot cronjob.' + sed -i 's/0.*renew/& --deploy-hook "\/usr\/local\/lsws\/bin\/lswsctrl restart"/g' ${BOTCRON} + fi +} + +certbothook \ No newline at end of file diff --git a/bin/demosite.sh b/bin/demosite.sh index e803183..8d7c057 100755 --- a/bin/demosite.sh +++ b/bin/demosite.sh @@ -5,7 +5,6 @@ APP_NAME='wordpress' DEMO_PATH="/var/www/${DEMO_VH}" help_message(){ - echo 'Command [-domain]' echo 'Script will get database password and wordpress password from .env file and install the demo wordpress site for you' } @@ -16,17 +15,27 @@ check_input(){ fi } -run_database(){ - bash bin/database.sh -domain ${DEMO_VH} -user ${MYSQL_USER} -password ${MYSQL_PASSWORD} -database ${MYSQL_DATABASE} +store_credential(){ + 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 +"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 litespeed su -c "appinstallctl.sh -app ${1} -domain ${2} -vhname localhost" + docker-compose exec litespeed su -c "appinstallctl.sh -app ${1} -domain ${2} -vhname ${DEMO_VH}" } main(){ - run_database + store_credential ${DEMO_VH} app_download ${APP_NAME} ${DOMAIN} } diff --git a/config/litespeed/1.6.5.lh/Dockerfile b/config/litespeed/1.6.5.lh/Dockerfile index 4a81a7a..d468bb5 100644 --- a/config/litespeed/1.6.5.lh/Dockerfile +++ b/config/litespeed/1.6.5.lh/Dockerfile @@ -21,6 +21,8 @@ RUN apt-get install -y software-properties-common && \ apt-get update && \ apt-get install -y certbot python-certbot-apache +RUN sed 's/0.*.certbot/& --deploy-hook "\/usr\/local\/lsws\/bin\/lswsctrl restart"/g' /etc/cron.d/certbot + RUN rm -rf /usr/local/lsws/conf ADD conf /usr/local/lsws/conf RUN chown 999:999 /usr/local/lsws/conf -R