diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8e38c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +joomla +traefik +portainer diff --git a/src/setup-portainer.sh b/src/setup-portainer.sh new file mode 100644 index 0000000..48dc721 --- /dev/null +++ b/src/setup-portainer.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +# check that our source path is correct +[ -e "${VDM_SRC_PATH}" ] || { + echo "[error] Source path (${VDM_SRC_PATH}) does not exist." + exit 1 +} +# check that our repository path is correct +[ -e "${VDM_REPO_PATH}" ] || { + echo "[error] Repository path (${VDM_REPO_PATH}) does not exist." + exit 1 +} +# check that our projects path is correct +[ -e "${VDM_PROJECT_PATH}" ] || { + echo "[error] Projects path (${VDM_PROJECT_PATH}) does not exist." + exit 1 +} +# be sure to create the container type path for traefik (just one container really) +# shellcheck disable=SC2174 +mkdir -p -m 700 "${VDM_REPO_PATH}/traefik" + +# check if we have global env file +[ -f "${VDM_REPO_PATH}/portainer/.env" ] && source "${VDM_REPO_PATH}/portainer/.env" + +# set the local values +REMOVE_SECURE='' +ENTRY_POINT="websecure" +# check that we have what we need +if [ "${VDM_SECURE,,}" != 'y' ] && [ "${VDM_SECURE,,}" != 'n' ]; then + echo -n "[enter] Use letsencrypt (y/n): " + read -r VDM_SECURE + # make sure value was entered + if [ "${VDM_SECURE,,}" != 'y' ] && [ "${VDM_SECURE,,}" != 'n' ]; then + echo "[error] you must choose y or n" + exit 1 + fi +fi +# get the domain if not set +[ ${#VDM_DOMAIN} -ge 1 ] || { + echo -n "[enter:localhost] Domain: " + read -r VDM_DOMAIN + # make sure value was entered + [ ${#VDM_DOMAIN} -ge 1 ] || exit + # we add the domain to the env (may have the VDM_DOMAIN value, but not the same domain) + grep -q "VDM_DOMAIN=\"${VDM_DOMAIN}\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_DOMAIN=\"${VDM_DOMAIN}\"" >>"${VDM_SRC_PATH}/.env" +} +# setup letsencrypt stuff +if [ "${VDM_SECURE,,}" == 'y' ]; then + # we add this switch to the env values + grep -q "VDM_SECURE=\"y\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_SECURE=\"y\"" >>"${VDM_SRC_PATH}/.env" +else + # we add this switch to the env values + grep -q "VDM_SECURE=\"n\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_SECURE=\"n\"" >>"${VDM_SRC_PATH}/.env" + # remove secure from build + REMOVE_SECURE="#" + ENTRY_POINT="web" +fi + +# build function +function buildContainer() { + # we build the yml file + cat <> /etc/hosts" +# } +#fi + +## create the directory if it does not yet already exist +# shellcheck disable=SC2174 +mkdir -p -m 700 "${VDM_REPO_PATH}/portainer" +## place this docker composer file in its place +buildContainer >"${VDM_REPO_PATH}/portainer/docker-compose.yml" +## set permissions +chmod 600 "${VDM_REPO_PATH}/portainer/docker-compose.yml" +[ -f "${VDM_REPO_PATH}/portainer/.env" ] && chmod 600 "${VDM_REPO_PATH}/portainer/.env" && + ENV_FILE="${VDM_REPO_PATH}/portainer/.env" || ENV_FILE="${VDM_REPO_PATH}/src/.env" +## saved the file +echo "[saved] portainer:docker-compose.yml" +echo "[setup] Completed!" + +# now start the container +docker-compose --env-file "${ENV_FILE}" --file "${VDM_REPO_PATH}/portainer/docker-compose.yml" up -d diff --git a/src/setup-traefik.sh b/src/setup-traefik.sh new file mode 100644 index 0000000..3456259 --- /dev/null +++ b/src/setup-traefik.sh @@ -0,0 +1,138 @@ +#!/bin/bash + +# check that our source path is correct +[ -e "${VDM_SRC_PATH}" ] || { + echo "[error] Source path (${VDM_SRC_PATH}) does not exist." + exit 1 +} +# check that our repository path is correct +[ -e "${VDM_REPO_PATH}" ] || { + echo "[error] Repository path (${VDM_REPO_PATH}) does not exist." + exit 1 +} +# check that our projects path is correct +[ -e "${VDM_PROJECT_PATH}" ] || { + echo "[error] Projects path (${VDM_PROJECT_PATH}) does not exist." + exit 1 +} +# be sure to create the container type path for traefik (just one container really) +# shellcheck disable=SC2174 +mkdir -p -m 700 "${VDM_REPO_PATH}/traefik" + +# check if we have global env file +[ -f "${VDM_REPO_PATH}/traefik/.env" ] && source "${VDM_REPO_PATH}/traefik/.env" + +# set the local values +REMOVE_SECURE='' +# check that we have what we need +if [ "${VDM_SECURE,,}" != 'y' ] && [ "${VDM_SECURE,,}" != 'n' ]; then + echo -n "[enter] Use letsencrypt (y/n): " + read -r VDM_SECURE + # make sure value was entered + if [ "${VDM_SECURE,,}" != 'y' ] && [ "${VDM_SECURE,,}" != 'n' ]; then + echo "[error] you must choose y or n" + exit 1 + fi +fi +# get the domain if not set +[ ${#VDM_DOMAIN} -ge 1 ] || { + echo -n "[enter:localhost] Domain: " + read -r VDM_DOMAIN + # make sure value was entered + [ ${#VDM_DOMAIN} -ge 1 ] || exit + # we add the domain to the env (may have the VDM_DOMAIN value, but not the same domain) + grep -q "VDM_DOMAIN=\"${VDM_DOMAIN}\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_DOMAIN=\"${VDM_DOMAIN}\"" >>"${VDM_SRC_PATH}/.env" +} +# setup letsencrypt stuff +if [ "${VDM_SECURE,,}" == 'y' ]; then + # we add this switch to the env values + grep -q "VDM_SECURE=\"y\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_SECURE=\"y\"" >>"${VDM_SRC_PATH}/.env" + # get the email if not set + [ ${#VDM_SECURE_EMAIL} -ge 1 ] || { + echo -n "[enter] Email: " + read -r VDM_SECURE_EMAIL + # make sure value was entered + [ ${#VDM_SECURE_EMAIL} -ge 1 ] || exit + } +else + # we add this switch to the env values + grep -q "VDM_SECURE=\"n\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_SECURE=\"n\"" >>"${VDM_SRC_PATH}/.env" + # remove secure from build + REMOVE_SECURE="#" +fi + +# build function +function buildContainer() { + # we build the yml file + cat <"${VDM_REPO_PATH}/traefik/docker-compose.yml" +## set permissions +chmod 600 "${VDM_REPO_PATH}/traefik/docker-compose.yml" +[ -f "${VDM_REPO_PATH}/traefik/.env" ] && chmod 600 "${VDM_REPO_PATH}/traefik/.env" && + ENV_FILE="${VDM_REPO_PATH}/traefik/.env" || ENV_FILE="${VDM_REPO_PATH}/src/.env" +## saved the file +echo "[saved] traefik:docker-compose.yml" +echo "[setup] Completed!" + +# we create the networks +docker network inspect traefik_webgateway >/dev/null 2>&1 || + docker network create traefik_webgateway +docker network inspect openssh_gateway >/dev/null 2>&1 || + docker network create openssh_gateway +# make sure port 80 is not used by apache +command -v apache2 >/dev/null 2>&1 && [[ $(service apache2 status) == *"active (running)"* ]] && { + sudo systemctl stop apache2.service + sudo systemctl disable apache2.service +} +# now start the container +docker-compose --env-file "${ENV_FILE}" --file "${VDM_REPO_PATH}/traefik/docker-compose.yml" up -d