From a792a748643f3ac4e6ae8e37143e587ff6958644 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 1 Jul 2021 11:42:13 +0200 Subject: [PATCH] adds delete with various tweaks --- src/delete.sh | 121 +++++++++++++++++++++++++++++++++++++++++++ src/fix.sh | 50 ++++++++++-------- src/setup-joomla.sh | 15 ++++++ src/setup-openssh.sh | 15 ++++++ src/setup-traefik.sh | 12 +++-- 5 files changed, 186 insertions(+), 27 deletions(-) create mode 100644 src/delete.sh diff --git a/src/delete.sh b/src/delete.sh new file mode 100644 index 0000000..acf6f46 --- /dev/null +++ b/src/delete.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +# check that our enabled containers path is correct +[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available" ] || { + echo "[error] Available containers path ${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available does not exist." + exit 1 +} + +# action to delete +function askToDelete() { + # some house cleaning + PS3_old=$PS3 + # set the local value + local question + local path + local target + # now set the values + question="$1" + path="$2" + target="$3" + # some defaults + echo "${question}" + # set the terminal + export PS3="[select]: " + # Start our little Menu + select yn in "Yes" "No"; do + case $yn in + Yes ) sudo rm -rf "${path}"; echo "[notice] ${target} was deleted.";; + No ) echo "[notice] ${target} was not deleted.";; + esac + break + done + # restore the default + export PS3=$PS3_old +} + +# get container available for deletion +function getContainer() { + # some house cleaning + PS3_old=$PS3 + # some defaults + export PS3="Please select ${VDM_CONTAINER_TYPE} container deploy files to delete: " + # Start our little Menu + select menu in $(ls "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/"); do + case $REPLY in + *) + SELECTED="$menu" + ;; + esac + break + done + # restore the default + export PS3=$PS3_old + # return selection + echo "$SELECTED" +} + +# set the container +CONTAINER="${1:-$CONTAINER}" +[ ${#CONTAINER} -ge 1 ] && [ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" ] || { + CONTAINER=$(getContainer) + # make sure value was entered + [ ${#CONTAINER} -ge 1 ] && [ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" ] || exit +} + +# disable +if [ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}" ]; then + # make sure the docker image is stopped + docker-compose --file "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}/docker-compose.yml" down + # then remove soft link + rm "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}" +fi + +# remove the files with one last confirmation +askToDelete \ + "Are you absolutely sure you would like to complete delete the ${VDM_CONTAINER_TYPE} ${CONTAINER} deploy files?" \ + "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" \ + "${CONTAINER}" + +# check that our project path is correct +[ -e "${VDM_PROJECT_PATH}" ] || { + echo "[error] Project path (${VDM_PROJECT_PATH}) does not exist." + exit 1 +} + +# make sites available selection +function getProjectsAvailable() { + # some house cleaning + PS3_old=$PS3 + # some defaults + export PS3="Please select persistent volume folder to delete: " + # Start our little Menu + select menu in $(ls "${VDM_PROJECT_PATH}"); do + case $REPLY in + *) + SELECTED="$menu" + ;; + esac + break + done + # restore the default + export PS3=$PS3_old + # return selection + echo "$SELECTED" +} + +# set the local values +VDM_PROJECT="${2:-$VDM_PROJECT}" +# check that we have what we need +# shellcheck disable=SC2015 +[ ${#VDM_PROJECT} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${VDM_PROJECT}" ] || { + VDM_PROJECT=$(getProjectsAvailable) + # make sure value was entered + [ ${#VDM_PROJECT} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${VDM_PROJECT}" ] || exit +} + +# remove the files with one last confirmation +askToDelete \ + "Are you absolutely sure you would like to delete the ${VDM_PROJECT} persistent volume folders?" \ + "${VDM_PROJECT_PATH}/${VDM_PROJECT}" \ + "${VDM_PROJECT}" diff --git a/src/fix.sh b/src/fix.sh index 1d3440a..cf8ddc0 100644 --- a/src/fix.sh +++ b/src/fix.sh @@ -28,48 +28,54 @@ function getProjectsAvailable() { } # set the local values -vdm_project="${1:-$VDM_PROJECT}" +VDM_PROJECT="${1:-$VDM_PROJECT}" # check that we have what we need -[ ${#vdm_project} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${vdm_project}" ] || { - vdm_project=$(getProjectsAvailable) +# shellcheck disable=SC2015 +[ ${#VDM_PROJECT} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${VDM_PROJECT}" ] || { + VDM_PROJECT=$(getProjectsAvailable) # make sure value was entered - [ ${#vdm_project} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${vdm_project}" ] || exit + [ ${#VDM_PROJECT} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}/${VDM_PROJECT}" ] || exit } ### Fix the folder ownership of Joomla folders # -echo "[notice] Fix the folder ownership of ${vdm_project} Joomla folders" +echo "[notice] Fix the folder ownership of ${VDM_PROJECT} Joomla folders" # -sudo chown -R www-data:www-data "${VDM_PROJECT_PATH}/${vdm_project}/joomla" -sudo setfacl -R -m u:llewellyn:rwx "${VDM_PROJECT_PATH}/${vdm_project}/joomla" +sudo chown -R www-data:www-data "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla" ### Fix the folder permissions for the Joomla websites # -echo "[notice] Fix the file and folder permissions for the ${vdm_project} Joomla website" +echo "[notice] Fix the file and folder permissions for the ${VDM_PROJECT} Joomla website" # # Change the file permissions -sudo find "${VDM_PROJECT_PATH}/${vdm_project}/joomla" -type f -exec chmod 644 {} \; -sudo find "${VDM_PROJECT_PATH}/${vdm_project}/joomla/configuration.php" -type f -exec chmod 444 {} \; -[ -f "${VDM_PROJECT_PATH}/${vdm_project}/joomla/.htaccess" ] && - sudo find "${VDM_PROJECT_PATH}/${vdm_project}/joomla/.htaccess" -type f -exec chmod 400 {} \; -[ -f "${VDM_PROJECT_PATH}/${vdm_project}/joomla/php.ini" ] && - sudo find "${VDM_PROJECT_PATH}/${vdm_project}/joomla/php.ini" -type f -exec chmod 400 {} \; +sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla" -type f -exec chmod 644 {} \; +sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/configuration.php" -type f -exec chmod 444 {} \; +[ -f "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/.htaccess" ] && + sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/.htaccess" -type f -exec chmod 400 {} \; +[ -f "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/php.ini" ] && + sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/php.ini" -type f -exec chmod 400 {} \; # Change the folder permissions -sudo find /"home/${USER}/Projects/${vdm_project}/joomla" -type d -exec chmod 755 {} \; +sudo find /"home/${USER}/Projects/${VDM_PROJECT}/joomla" -type d -exec chmod 755 {} \; # Change the image folder permissions -# chmod 707 "${VDM_PROJECT_PATH}/${vdm_project}/joomla/images" -# chmod 707 "${VDM_PROJECT_PATH}/${vdm_project}/joomla/images/stories" +# chmod 707 "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/images" +# chmod 707 "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla/images/stories" + +### Fix the folder permissions so the active user (1000) can access the files +# +echo "[notice] Fix the folder permissions of ${VDM_PROJECT} joomla so user:1000 can access them" +# +sudo setfacl -R -m u:1000:rwx "${VDM_PROJECT_PATH}/${VDM_PROJECT}/joomla" ### Fix the folder ownership of database folders # -echo "[notice] Fix the folder ownership of ${vdm_project} database folders" +echo "[notice] Fix the folder ownership of ${VDM_PROJECT} database folders" # -sudo chown -R systemd-coredump:systemd-coredump "${VDM_PROJECT_PATH}/${vdm_project}/db" +sudo chown -R systemd-coredump:systemd-coredump "${VDM_PROJECT_PATH}/${VDM_PROJECT}/db" ### Fix the folder permissions for the database files # -echo "[notice] Fix the file and folder permissions for the ${vdm_project} database files" +echo "[notice] Fix the file and folder permissions for the ${VDM_PROJECT} database files" # # Change the file permissions -sudo find "${VDM_PROJECT_PATH}/${vdm_project}/db" -type f -exec chmod 660 {} \; -sudo find "${VDM_PROJECT_PATH}/${vdm_project}/db" -type d -exec chmod 700 {} \; +sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/db" -type f -exec chmod 660 {} \; +sudo find "${VDM_PROJECT_PATH}/${VDM_PROJECT}/db" -type d -exec chmod 700 {} \; diff --git a/src/setup-joomla.sh b/src/setup-joomla.sh index 43d959e..3d9f87f 100644 --- a/src/setup-joomla.sh +++ b/src/setup-joomla.sh @@ -336,4 +336,19 @@ buildContainer >"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAI chmod 600 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN}.${VDM_DOMAIN}/docker-compose.yml" # saved the file echo "[save] ${VDM_CONTAINER_TYPE}:docker-compose.yml" +# some house cleaning +PS3_old=$PS3 +# ask if we should right now enable the container +echo "[question] Would you like to enable this new ${VDM_CONTAINER_TYPE} container?" +# set the terminal +export PS3="[select]: " +# shellcheck disable=SC1090 +select yn in "Yes" "No"; do + case $yn in + Yes ) source "${VDM_SRC_PATH}/enable.sh" "${VDM_SUBDOMAIN}.${VDM_DOMAIN}";; + esac + break +done +# restore the default +export PS3=$PS3_old echo "[setup] Completed!" diff --git a/src/setup-openssh.sh b/src/setup-openssh.sh index 6e904d2..a1a9b78 100644 --- a/src/setup-openssh.sh +++ b/src/setup-openssh.sh @@ -437,4 +437,19 @@ buildContainer "${VDM_MOUNT_PROJECTS}" >"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/ chmod 600 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_USER_NAME:-ubuntu}.${VDM_DOMAIN:-vdm.dev}/docker-compose.yml" # saved the file echo "[save] ${VDM_CONTAINER_TYPE}:docker-compose.yml" +# some house cleaning +PS3_old=$PS3 +# ask if we should right now enable the container +echo "[question] Would you like to enable this new ${VDM_CONTAINER_TYPE} container?" +# set the terminal +export PS3="[select]: " +# shellcheck disable=SC1090 +select yn in "Yes" "No"; do + case $yn in + Yes ) source "${VDM_SRC_PATH}/enable.sh" "${VDM_USER_NAME:-ubuntu}.${VDM_DOMAIN:-vdm.dev}";; + esac + break +done +# restore the default +export PS3=$PS3_old echo "[setup] Completed!" diff --git a/src/setup-traefik.sh b/src/setup-traefik.sh index 3456259..de73248 100644 --- a/src/setup-traefik.sh +++ b/src/setup-traefik.sh @@ -24,6 +24,7 @@ mkdir -p -m 700 "${VDM_REPO_PATH}/traefik" # set the local values REMOVE_SECURE='' +HTTP_SCHEME="https" # check that we have what we need if [ "${VDM_SECURE,,}" != 'y' ] && [ "${VDM_SECURE,,}" != 'n' ]; then echo -n "[enter] Use letsencrypt (y/n): " @@ -59,6 +60,7 @@ else grep -q "VDM_SECURE=\"n\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_SECURE=\"n\"" >>"${VDM_SRC_PATH}/.env" # remove secure from build REMOVE_SECURE="#" + HTTP_SCHEME="http" fi # build function @@ -73,11 +75,11 @@ services: image: "traefik:latest" command: - --entrypoints.web.address=:80 -${REMOVE_SECURE} - --entrypoints.websecure.address=:443 + - --entrypoints.websecure.address=:443 # - --api.dashboard=true # - --api.insecure=true - --providers.docker - - --log.level=ERROR + - --log.level=INFO ${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.httpchallenge=true ${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.keytype=RSA4096 ${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.email=${VDM_SECURE_EMAIL:-user@demo.com} @@ -88,7 +90,7 @@ ${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.httpchallenge.e restart: unless-stopped ports: - "80:80" -${REMOVE_SECURE} - "443:443" + - "443:443" # - "8080:8080" volumes: - /var/run/docker.sock:/var/run/docker.sock @@ -99,8 +101,8 @@ ${REMOVE_SECURE} - "\${VDM_PROJECT_PATH}/traefik/acme.json:/acme.json" # settings for all containers - "traefik.http.routers.http-catchall.rule=hostregexp(\`{host:.+}\`)" - "traefik.http.routers.http-catchall.entrypoints=web" -${REMOVE_SECURE} - "traefik.http.routers.http-catchall.middlewares=redirect-to-https" -${REMOVE_SECURE} - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https" + - "traefik.http.routers.http-catchall.middlewares=redirect-to-me" + - "traefik.http.middlewares.redirect-to-me.redirectscheme.scheme=${HTTP_SCHEME}" networks: - traefik