changed to a single file program
This commit is contained in:
121
src/delete.sh
121
src/delete.sh
@ -1,121 +0,0 @@
|
||||
#!/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}"
|
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check that our enabled containers path is correct
|
||||
[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled" ] || {
|
||||
echo "[error] Enabled containers path ${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled does not exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# get container enabled selection
|
||||
function getContainerEnabled() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
export PS3="Please select container to disable: "
|
||||
# Start our little Menu
|
||||
select menu in $(ls "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"); 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}"
|
||||
# check that we have what we need
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#CONTAINER} -ge 1 ] && [ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}" ] || {
|
||||
CONTAINER=$(getContainerEnabled)
|
||||
# make sure value was entered
|
||||
[ ${#CONTAINER} -ge 1 ] && [ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}" ] || exit
|
||||
}
|
||||
|
||||
# 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}"
|
2598
src/docker-deploy
Executable file
2598
src/docker-deploy
Executable file
File diff suppressed because it is too large
Load Diff
@ -1,466 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BOT name
|
||||
BOT_NAME="docker-deploy v1.0"
|
||||
|
||||
# the src folder path (where all the script are found)
|
||||
export VDM_SRC_PATH="/home/update/this/path/to/src"
|
||||
|
||||
# we load global environment values
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_SRC_PATH}/.env" ] && source "${VDM_SRC_PATH}/.env" || {
|
||||
echo "${VDM_SRC_PATH}/.env file not found, please run install."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# check that our repository path is correct
|
||||
[ -e "${VDM_REPO_PATH}" ] || {
|
||||
echo "Repository path (${VDM_REPO_PATH}) does not exist."
|
||||
exit 1
|
||||
}
|
||||
# check that our projects path is correct
|
||||
[ -e "${VDM_PROJECT_PATH}" ] || {
|
||||
echo "Projects path (${VDM_PROJECT_PATH}) does not exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# help message ʕ•ᴥ•ʔ
|
||||
function show_help() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/:-} [OPTION...]
|
||||
Options
|
||||
======================================================
|
||||
--type <type>
|
||||
set type you would like to work with
|
||||
example: ${0##*/:-} --type joomla
|
||||
======================================================
|
||||
--task <task>
|
||||
set type of task you would like to perform
|
||||
example: ${0##*/:-} --task setup
|
||||
======================================================
|
||||
--update
|
||||
to update your install
|
||||
example: ${0##*/:-} --update
|
||||
======================================================
|
||||
--uninstall
|
||||
to uninstall this script
|
||||
example: ${0##*/:-} --uninstall
|
||||
======================================================
|
||||
AVAILABLE FOR TO ANY CONTAINER
|
||||
======================================================
|
||||
-k|--key <key>
|
||||
set key for the docker compose container naming
|
||||
!! no spaces allowed in the key !!
|
||||
example: ${0##*/:-} -k="vdm"
|
||||
example: ${0##*/:-} --key="vdm"
|
||||
======================================================
|
||||
-e|--env-key <key>
|
||||
set key for the environment variable naming
|
||||
!! no spaces allowed in the key & must be UPPERCASE !!
|
||||
example: ${0##*/:-} -e="VDM"
|
||||
example: ${0##*/:-} --env-key="VDM"
|
||||
======================================================
|
||||
-d|--domain <domain.com>
|
||||
set key website domain
|
||||
!! must be domain.tld !!
|
||||
example: ${0##*/:-} -d="vdm.dev"
|
||||
example: ${0##*/:-} --domain="vdm.dev"
|
||||
======================================================
|
||||
AVAILABLE FOR JOOMLA CONTAINER
|
||||
======================================================
|
||||
-j|--joomla-version <version>
|
||||
set Joomla version number
|
||||
!! only number allowed !!
|
||||
example: ${0##*/:-} -j=3.10
|
||||
example: ${0##*/:-} --joomla-version=3.10
|
||||
======================================================
|
||||
-s|--sub-domain <domain.com>
|
||||
set key website sub domain
|
||||
!! no spaces allowed in the sub domain !!
|
||||
example: ${0##*/:-} -s="jcb"
|
||||
example: ${0##*/:-} --sub-domain="jcb"
|
||||
======================================================
|
||||
AVAILABLE FOR OPENSSH CONTAINER
|
||||
======================================================
|
||||
-u|--username <username>
|
||||
set username of the container
|
||||
example: ${0##*/:-} -u="ubuntu"
|
||||
example: ${0##*/:-} --username="ubuntu"
|
||||
======================================================
|
||||
--uid <id>
|
||||
set container user id
|
||||
example: ${0##*/:-} --uid=1000
|
||||
======================================================
|
||||
--gid <id>
|
||||
set container user group id
|
||||
example: ${0##*/:-} --gid=1000
|
||||
======================================================
|
||||
-p|--port <port>
|
||||
set ssh port to use
|
||||
!! do not use 22 !!
|
||||
example: ${0##*/:-} -p=2239
|
||||
example: ${0##*/:-} --port=2239
|
||||
======================================================
|
||||
--ssh-dir <dir>
|
||||
set ssh directory name found in the .ssh dir
|
||||
of this repo for the container keys
|
||||
This directory has separate files for
|
||||
each public key allowed to access
|
||||
the container
|
||||
example: ${0##*/:-} --ssh-dir="teamname"
|
||||
======================================================
|
||||
--sudo
|
||||
switch to add the container user to the
|
||||
sudo group of the container
|
||||
example: ${0##*/:-} --sudo
|
||||
======================================================
|
||||
-t|--time-zone <time/zone>
|
||||
set time zone of the container
|
||||
!! must valid time zone !!
|
||||
example: ${0##*/:-} -t="Africa/Windhoek"
|
||||
example: ${0##*/:-} --time-zone="Africa/Windhoek"
|
||||
======================================================
|
||||
HELP ʕ•ᴥ•ʔ
|
||||
======================================================
|
||||
-h|--help
|
||||
display this help menu
|
||||
example: ${0##*/:-} -h
|
||||
example: ${0##*/:-} --help
|
||||
======================================================
|
||||
${BOT_NAME}
|
||||
======================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
# check if we have options
|
||||
while :; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
show_help # Display a usage synopsis.
|
||||
exit
|
||||
;;
|
||||
--update)
|
||||
VDM_CONTAINER_TYPE="update"
|
||||
shift
|
||||
;;
|
||||
--uninstall)
|
||||
VDM_CONTAINER_TYPE="uninstall"
|
||||
shift
|
||||
;;
|
||||
--type) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_CONTAINER_TYPE=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--type" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--type=?*)
|
||||
VDM_CONTAINER_TYPE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--type=) # Handle the case of an empty --src-path=
|
||||
echo '[error] "--type=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--task) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_TASK=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--task" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--task=?*)
|
||||
VDM_TASK=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--task=) # Handle the case of an empty --src-path=
|
||||
echo '[error] "--task=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-j | --joomla-version) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_JV=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--joomla-version" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-j=?* | --joomla-version=?*)
|
||||
export VDM_JV=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-j= | --joomla-version=) # Handle the case of an empty --joomla-version=
|
||||
echo '[error] "--joomla-version=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-k | --key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-k=?* | --key=?*)
|
||||
export VDM_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-k= | --key=) # Handle the case of an empty --key=
|
||||
echo '[error] "--key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-e | --env-key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_ENV_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--env-key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-e=?* | --env-key=?*)
|
||||
export VDM_ENV_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-e= | --env-key=) # Handle the case of an empty --env-key=
|
||||
echo '[error] "--env-key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-d | --domain) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_DOMAIN=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--domain" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-d=?* | --domain=?*)
|
||||
export VDM_DOMAIN=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-d= | --domain=) # Handle the case of an empty --domain=
|
||||
echo '[error] "--domain=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-s | --sub-domain) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_SUBDOMAIN=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--sub-domain" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-s=?* | --sub-domain=?*)
|
||||
export VDM_SUBDOMAIN=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-s= | --sub-domain=) # Handle the case of an empty --sub-domain=
|
||||
echo '[error] "--sub-domain=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--sudo)
|
||||
export VDM_SUDO_ACCESS=true
|
||||
shift
|
||||
;;
|
||||
-u | --username) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_USER_NAME=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--username" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-u=?* | --username=?*)
|
||||
export VDM_USER_NAME=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-u= | --username=) # Handle the case of an empty --username=
|
||||
echo '[error] "--username=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--uid) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_PUID=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--uid" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--uid=?*)
|
||||
export VDM_PUID=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--uid=) # Handle the case of an empty --uid=
|
||||
echo '[error] "--uid=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--gid) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_PGID=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--gid" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--gid=?*)
|
||||
export VDM_PGID=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--gid=) # Handle the case of an empty --gid=
|
||||
echo '[error] "--gid=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-p | --port) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_PORT=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--port" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-p=?* | --port=?*)
|
||||
export VDM_PORT=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-p= | --port=) # Handle the case of an empty --port=
|
||||
echo '[error] "--port=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--ssh-dir) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_PUBLIC_KEY_DIR=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--ssh-dir" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--ssh-dir=?*)
|
||||
export VDM_PUBLIC_KEY_DIR=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-ssh-dir=) # Handle the case of an empty --ssh-dir=
|
||||
echo '[error] "--ssh-dir=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-t | --time-zone) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
export VDM_TZ=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--time-zone" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-t=?* | --time-zone=?*)
|
||||
export VDM_TZ=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-t= | --time-zone=) # Handle the case of an empty --time-zone=
|
||||
echo '[error] "--time-zone=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
*) # Default case: No more options, so break out of the loop.
|
||||
break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# get container type
|
||||
function getContainerType() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
export PS3="Please select the type: "
|
||||
# Start our little Menu
|
||||
select menu in "joomla" "openssh" "traefik" "portainer" "update" "uninstall"; do
|
||||
case $REPLY in
|
||||
*)
|
||||
SELECTED="$menu"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
# restore the default
|
||||
export PS3=$PS3_old
|
||||
# return selection
|
||||
echo "$SELECTED"
|
||||
}
|
||||
|
||||
# check that we have what we need
|
||||
[ ${#VDM_CONTAINER_TYPE} -ge 1 ] || {
|
||||
VDM_CONTAINER_TYPE=$(getContainerType)
|
||||
# make sure value was entered
|
||||
[ ${#VDM_CONTAINER_TYPE} -ge 1 ] || {
|
||||
echo "[error] Wrong type selected"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
export VDM_CONTAINER_TYPE
|
||||
|
||||
# get task type
|
||||
function getTaskType() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# build the selection based on the VDM_CONTAINER_TYPE
|
||||
case "$VDM_CONTAINER_TYPE" in
|
||||
"joomla")
|
||||
options=("setup" "enable" "disable" "up" "down" "fix")
|
||||
shift
|
||||
;;
|
||||
"openssh")
|
||||
options=("setup" "enable" "disable" "up" "down")
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "[error] Wrong type selected (${VDM_CONTAINER_TYPE})"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# some defaults
|
||||
export PS3="Please select the kind of task to perform on ${VDM_CONTAINER_TYPE}: "
|
||||
# Start our little Menu
|
||||
select menu in "${options[@]}"; do
|
||||
case $REPLY in
|
||||
*)
|
||||
SELECTED="$menu"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
# restore the default
|
||||
export PS3=$PS3_old
|
||||
# return selection
|
||||
echo "$SELECTED"
|
||||
}
|
||||
|
||||
case "$VDM_CONTAINER_TYPE" in
|
||||
"traefik")
|
||||
VDM_TASK="setup-traefik"
|
||||
;;
|
||||
"portainer")
|
||||
VDM_TASK="setup-portainer"
|
||||
;;
|
||||
"update")
|
||||
VDM_TASK="install"
|
||||
;;
|
||||
"uninstall")
|
||||
VDM_TASK="uninstall"
|
||||
;;
|
||||
esac
|
||||
|
||||
# check that we have what we need
|
||||
[ ${#VDM_TASK} -ge 1 ] || {
|
||||
VDM_TASK=$(getTaskType)
|
||||
# make sure value was entered
|
||||
[ ${#VDM_TASK} -ge 1 ] || {
|
||||
echo "[error] Wrong task type selected for ${VDM_CONTAINER_TYPE}"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# run that task type script
|
||||
# shellcheck disable=SC1090
|
||||
source "${VDM_SRC_PATH}/${VDM_TASK}.sh"
|
||||
|
||||
exit 0
|
18
src/down.sh
18
src/down.sh
@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check that our enabled containers path is correct
|
||||
[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled" ] || {
|
||||
echo "[error] Enabled containers path ${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled does not exist. This means no container is enabled."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# the main function
|
||||
main() {
|
||||
# get all zip files
|
||||
for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do
|
||||
docker-compose --file "${yml}" down
|
||||
done
|
||||
}
|
||||
|
||||
# run main
|
||||
main
|
@ -1,63 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check that our repository path is correct
|
||||
[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/" ] || {
|
||||
echo "[error] The path ${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/ does not exist, first run setup."
|
||||
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
|
||||
}
|
||||
|
||||
# get container available selection
|
||||
function getContainerAvailable() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
export PS3="Please select container to enable: "
|
||||
# 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}"
|
||||
# check that we have what we need
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#CONTAINER} -ge 1 ] && [ -d "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" ] || {
|
||||
CONTAINER=$(getContainerAvailable)
|
||||
# make sure value was entered
|
||||
[ ${#CONTAINER} -ge 1 ] && [ -d "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" ] || exit
|
||||
}
|
||||
|
||||
# create the folder as needed
|
||||
mkdir -p "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"
|
||||
|
||||
# create the soft link
|
||||
[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}" ] || ln -s "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${CONTAINER}" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}"
|
||||
# check if image has its own env file also
|
||||
ENV_FILE=''
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}/.env" ] && ENV_FILE="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}/.env" || {
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && ENV_FILE="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
|
||||
# make sure the docker image is started
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#ENV_FILE} -ge 1 ] && docker-compose --env-file "${ENV_FILE}" --file "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}/docker-compose.yml" up -d || {
|
||||
docker-compose --file "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/${CONTAINER}/docker-compose.yml" up -d
|
||||
}
|
||||
# show env path used
|
||||
echo "[notice] EVN PATH: ${ENV_FILE}"
|
81
src/fix.sh
81
src/fix.sh
@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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 project to fix: "
|
||||
# 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="${1:-$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
|
||||
}
|
||||
|
||||
### Fix the folder ownership of 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"
|
||||
|
||||
### Fix the folder permissions for the Joomla websites
|
||||
#
|
||||
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 {} \;
|
||||
# Change the folder permissions
|
||||
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"
|
||||
|
||||
### 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"
|
||||
#
|
||||
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"
|
||||
#
|
||||
# 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 {} \;
|
13
src/host.sh
13
src/host.sh
@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check if we should add to host file
|
||||
if $VDM_UPDATE_HOST; then
|
||||
# check if already in host file
|
||||
if grep -q "${1:-$VDM_SUBDOMAIN}.${2:-$VDM_DOMAIN}" /etc/hosts; then
|
||||
echo "[notice] ${USER^}, ${1:-$VDM_SUBDOMAIN}.${2:-$VDM_DOMAIN} is already in the /etc/hosts file."
|
||||
else
|
||||
# just a notice for now
|
||||
echo "[notice] ${USER^}, you should add ${1:-$VDM_SUBDOMAIN}.${2:-$VDM_DOMAIN} to the /etc/hosts file."
|
||||
# sudo echo "127.0.0.1 ${VDM_SUBDOMAIN}.${VDM_DOMAIN}" >> /etc/hosts
|
||||
fi
|
||||
fi
|
258
src/install.sh
258
src/install.sh
@ -1,258 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BOT name
|
||||
BOT_NAME="docker-deploy v1.0"
|
||||
|
||||
# only install/setup docker once
|
||||
command -v docker >/dev/null 2>&1 || {
|
||||
# remove old docker
|
||||
sudo apt-get remove docker docker-engine docker.io containerd runc
|
||||
# add docker repo
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
||||
# make sure we have dependencies installed
|
||||
sudo apt-get update
|
||||
sudo apt-get install \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release
|
||||
# now install docker
|
||||
sudo apt-get install docker-ce docker-ce-cli containerd.io
|
||||
# start docker
|
||||
sudo systemctl enable docker.service
|
||||
# persist docker
|
||||
udo systemctl enable containerd.service
|
||||
# make sure the user is in the docker group
|
||||
sudo groupadd docker
|
||||
sudo usermod -aG docker "$USER"
|
||||
}
|
||||
|
||||
# only install docker-compose once
|
||||
command -v docker-compose >/dev/null 2>&1 || {
|
||||
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
}
|
||||
|
||||
# get script path
|
||||
VDM_SRC_PATH="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$VDM_SRC_PATH" || "$VDM_SRC_PATH" == '.' ]]; then VDM_SRC_PATH="$PWD"; fi
|
||||
|
||||
# some globals
|
||||
VDM_FORCE_INSTALL=false
|
||||
VDM_UPDATE_HOST=false
|
||||
|
||||
# help message ʕ•ᴥ•ʔ
|
||||
function show_help() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/:-} [OPTION...]
|
||||
Options
|
||||
======================================================
|
||||
--src-path=<path>|--src=<path>
|
||||
set path to the script source folder
|
||||
example: ${0##*/:-} --src=/home/$USER/Docker/src
|
||||
example: ${0##*/:-} --src-path=/home/$USER/Docker/src
|
||||
======================================================
|
||||
--repo-path=<path>|--repo=<path>
|
||||
set path to the repository folder
|
||||
example: ${0##*/:-} --repo=/home/$USER/Docker
|
||||
example: ${0##*/:-} --repo-path=/home/$USER/Docker
|
||||
======================================================
|
||||
--project-path=<path>|--project=<path>
|
||||
set path to the projects folder
|
||||
example: ${0##*/:-} --project=/home/$USER/Projects
|
||||
example: ${0##*/:-} --project-path=/home/$USER/Projects
|
||||
======================================================
|
||||
-f|--force
|
||||
force installation
|
||||
example: ${0##*/:-} -f
|
||||
example: ${0##*/:-} --force
|
||||
======================================================
|
||||
--host
|
||||
always update your host file
|
||||
example: ${0##*/:-} --host
|
||||
======================================================
|
||||
-h|--help
|
||||
display this help menu
|
||||
example: ${0##*/:-} -h
|
||||
example: ${0##*/:-} --help
|
||||
======================================================
|
||||
${BOT_NAME}
|
||||
======================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
# check if we have options
|
||||
while :; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
show_help # Display a usage synopsis.
|
||||
exit
|
||||
;;
|
||||
-f | --force)
|
||||
VDM_FORCE_INSTALL=true
|
||||
shift
|
||||
;;
|
||||
--host)
|
||||
VDM_UPDATE_HOST=true
|
||||
shift
|
||||
;;
|
||||
--src-path | --src) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_SRC_PATH=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--src-path" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--src-path=?* | --src=?*)
|
||||
VDM_SRC_PATH=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--src-path= | --src=) # Handle the case of an empty --src-path=
|
||||
echo '[error] "--src-path=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--repo-path | --repo) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_REPO_PATH=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--repo-path" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--repo-path=?* | --repo=?*)
|
||||
VDM_REPO_PATH=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--repo-path= | --repo=) # Handle the case of an empty --repo-path=
|
||||
echo '[error] "--repo-path=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--project-path | --project) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_PROJECT_PATH=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--project-path" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--project-path=?* | --project=?*)
|
||||
VDM_PROJECT_PATH=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--project-path= | --project=) # Handle the case of an empty --project-path=
|
||||
echo '[error] "---project-path=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
*) # Default case: No more options, so break out of the loop.
|
||||
break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# make source path available to other scripts
|
||||
export VDM_SRC_PATH="${VDM_SRC_PATH}"
|
||||
|
||||
# now we get the repository path
|
||||
[ -e "${VDM_REPO_PATH}" ] || {
|
||||
echo "[notice] The repository full path is where the container .yml files will live."
|
||||
echo -n "[enter:${VDM_SRC_PATH%/src}] Repository Full Path: "
|
||||
read -r VDM_REPO_PATH
|
||||
# make sure it exist
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#VDM_REPO_PATH} -ge 1 ] && [ -d "${VDM_REPO_PATH}" ] || {
|
||||
# we set the default
|
||||
VDM_REPO_PATH="${VDM_SRC_PATH%/src}"
|
||||
## check if this exist
|
||||
[ -d "${VDM_REPO_PATH}" ] || {
|
||||
echo "[error] Repository path (${VDM_REPO_PATH}) does not exist."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# we set the repo path (easy)
|
||||
grep -q "VDM_REPO_PATH=\"${VDM_REPO_PATH}\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_REPO_PATH=\"${VDM_REPO_PATH}\"" >"${VDM_SRC_PATH}/.env"
|
||||
export VDM_REPO_PATH="${VDM_REPO_PATH}"
|
||||
|
||||
grep -q "VDM_UPDATE_HOST=${VDM_UPDATE_HOST}" "${VDM_SRC_PATH}/.env" || echo "export VDM_UPDATE_HOST=${VDM_UPDATE_HOST}" >>"${VDM_SRC_PATH}/.env"
|
||||
export VDM_UPDATE_HOST
|
||||
|
||||
# notice about the repo path
|
||||
echo "[notice] $VDM_REPO_PATH was set as the repository path in ${VDM_SRC_PATH}/.env"
|
||||
|
||||
# now we must set the Projects path
|
||||
[ -e "${VDM_PROJECT_PATH}" ] || {
|
||||
echo -n "[enter:/home/${USER}/Projects] Projects Full Path: "
|
||||
read -r VDM_PROJECT_PATH
|
||||
# make sure it exist
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#VDM_PROJECT_PATH} -ge 1 ] && [ -d "${VDM_PROJECT_PATH}" ] || {
|
||||
# we set the default
|
||||
VDM_PROJECT_PATH="/home/${USER}/Projects"
|
||||
## check if this exist
|
||||
[ -d "${VDM_PROJECT_PATH}" ] || {
|
||||
echo "[error] Project path (${VDM_PROJECT_PATH}) does not exist."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# we set the projects path (easy)
|
||||
grep -q "VDM_PROJECT_PATH=\"${VDM_PROJECT_PATH}\"" "${VDM_SRC_PATH}/.env" || echo "export VDM_PROJECT_PATH=\"${VDM_PROJECT_PATH}\"" >>"${VDM_SRC_PATH}/.env"
|
||||
export VDM_PROJECT_PATH="${VDM_PROJECT_PATH}"
|
||||
|
||||
# notice about the projects path
|
||||
echo "[notice] $VDM_PROJECT_PATH was set as the project path in ${VDM_SRC_PATH}/.env"
|
||||
|
||||
# now we set the docker-deploy script in the executable path of this user
|
||||
if [ ! $VDM_FORCE_INSTALL ]; then
|
||||
[ -f /usr/local/bin/docker-deploy ] && {
|
||||
echo "[error] /usr/local/bin/docker-deploy already exist! you can force installation:"
|
||||
echo "[fix] $ ${0##*/:-} -f"
|
||||
exit 1
|
||||
}
|
||||
sudo cp "${VDM_SRC_PATH}/docker-deploy.sh" /usr/local/bin/docker-deploy
|
||||
else
|
||||
sudo cp -f "${VDM_SRC_PATH}/docker-deploy.sh" /usr/local/bin/docker-deploy
|
||||
fi
|
||||
|
||||
# we need to add helper for our docker-deploy script to find the .env file
|
||||
sudo sed -i -e "s|/home/update/this/path/to/src|${VDM_SRC_PATH}|g" /usr/local/bin/docker-deploy
|
||||
|
||||
# notice of the src path
|
||||
echo "[notice] ${VDM_SRC_PATH} is the src path to all scripts, and should not be deleted."
|
||||
|
||||
# we first make sure run is executable
|
||||
echo "[sudo] making the /usr/local/bin/docker-deploy script executable"
|
||||
sudo chmod +x "/usr/local/bin/docker-deploy"
|
||||
|
||||
# Note: If the command docker-deploy fails after installation, check your path.
|
||||
# You can also create a symbolic link to /usr/bin or any other directory in your path.
|
||||
# For example:
|
||||
# $ sudo ln -s /usr/local/bin/docker-deploy /usr/bin/docker-deploy
|
||||
|
||||
# we load global environment values
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_SRC_PATH}/.env" ] && source "${VDM_SRC_PATH}/.env"
|
||||
|
||||
# check if we should setup traefik
|
||||
echo -n "[enter:y] Setup Traefik (y/n): "
|
||||
read -r VDM_SETUP_TRAEFIK
|
||||
# make sure value was entered
|
||||
if [ "${VDM_SETUP_TRAEFIK,,}" != 'n' ]; then
|
||||
# run that task type script
|
||||
# shellcheck disable=SC1090
|
||||
source "${VDM_SRC_PATH}/setup-traefik.sh"
|
||||
fi
|
||||
# check if we should setup portainer
|
||||
echo -n "[enter:y] Setup Portainer (y/n): "
|
||||
read -r VDM_SETUP_PORTAINER
|
||||
# make sure value was entered
|
||||
if [ "${VDM_SETUP_PORTAINER,,}" != 'n' ]; then
|
||||
# run that task type script
|
||||
# shellcheck disable=SC1090
|
||||
source "${VDM_SRC_PATH}/setup-portainer.sh"
|
||||
fi
|
||||
|
||||
exit 0
|
@ -1,354 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BOT name
|
||||
BOT_NAME="docker-deploy v1.0"
|
||||
|
||||
# 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
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}"
|
||||
|
||||
# check if we have global env file
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && source "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" || {
|
||||
touch "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
chmod 600 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
|
||||
# we must get a random key
|
||||
function getPass() {
|
||||
# simple basic random
|
||||
# shellcheck disable=SC2046
|
||||
echo $(tr -dc 'A-HJ-NP-Za-km-z2-9' </dev/urandom | dd bs="${1:-128}" count=1 status=none)
|
||||
}
|
||||
|
||||
# help message ʕ•ᴥ•ʔ
|
||||
function show_help() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/:-} [OPTION...]
|
||||
Options
|
||||
======================================================
|
||||
-j|--joomla-version <version>
|
||||
set Joomla version number
|
||||
!! only number allowed !!
|
||||
example: ${0##*/:-} -j=3.10
|
||||
example: ${0##*/:-} --joomla-version=3.10
|
||||
======================================================
|
||||
-k|--key <key>
|
||||
set key for the docker compose container naming
|
||||
!! no spaces allowed in the key !!
|
||||
example: ${0##*/:-} -k="vdm"
|
||||
example: ${0##*/:-} --key="vdm"
|
||||
======================================================
|
||||
-e|--env-key <key>
|
||||
set key for the environment variable naming
|
||||
!! no spaces allowed in the key & must be UPPERCASE !!
|
||||
example: ${0##*/:-} -e="VDM"
|
||||
example: ${0##*/:-} --env-key="VDM"
|
||||
======================================================
|
||||
-d|--domain <domain.com>
|
||||
set key website domain
|
||||
!! must be domain.tld !!
|
||||
example: ${0##*/:-} -d="vdm.dev"
|
||||
example: ${0##*/:-} --domain="vdm.dev"
|
||||
======================================================
|
||||
-s|--sub-domain <domain.com>
|
||||
set key website sub domain
|
||||
!! no spaces allowed in the sub domain !!
|
||||
example: ${0##*/:-} -s="jcb"
|
||||
example: ${0##*/:-} --sub-domain="jcb"
|
||||
======================================================
|
||||
-h|--help
|
||||
display this help menu
|
||||
example: ${0##*/:-} -h
|
||||
example: ${0##*/:-} --help
|
||||
======================================================
|
||||
${BOT_NAME}
|
||||
======================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
# set the local values
|
||||
while :; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
show_help # Display a usage synopsis.
|
||||
exit
|
||||
;;
|
||||
-j | --joomla-version) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_JV=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--joomla-version" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-j=?* | --joomla-version=?*)
|
||||
VDM_JV=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-j= | --joomla-version=) # Handle the case of an empty --joomla-version=
|
||||
echo '[error] "--joomla-version=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-k | --key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-k=?* | --key=?*)
|
||||
VDM_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-k= | --key=) # Handle the case of an empty --key=
|
||||
echo '[error] "--key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-e | --env-key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_ENV_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--env-key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-e=?* | --env-key=?*)
|
||||
VDM_ENV_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-e= | --env-key=) # Handle the case of an empty --env-key=
|
||||
echo '[error] "--env-key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-d | --domain) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_DOMAIN=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--domain" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-d=?* | --domain=?*)
|
||||
VDM_DOMAIN=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-d= | --domain=) # Handle the case of an empty --domain=
|
||||
echo '[error] "--domain=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-s | --sub-domain) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_SUBDOMAIN=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--sub-domain" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-s=?* | --sub-domain=?*)
|
||||
VDM_SUBDOMAIN=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-s= | --sub-domain=) # Handle the case of an empty --sub-domain=
|
||||
echo '[error] "--sub-domain=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
*) # Default case: No more options, so break out of the loop.
|
||||
break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# check that we have what we need
|
||||
[ ${#VDM_JV} -ge 1 ] || {
|
||||
echo -n "[enter] Joomla Version: "
|
||||
read -r VDM_JV
|
||||
# make sure value was entered
|
||||
[ ${#VDM_JV} -ge 1 ] || exit
|
||||
}
|
||||
[ ${#VDM_KEY} -ge 1 ] || {
|
||||
echo -n "[enter] key: "
|
||||
read -r VDM_KEY
|
||||
# make sure value was entered
|
||||
[ ${#VDM_KEY} -ge 1 ] || exit
|
||||
}
|
||||
[ ${#VDM_ENV_KEY} -ge 1 ] || {
|
||||
echo -n "[enter:A] env key: "
|
||||
read -r VDM_ENV_KEY
|
||||
# make sure value was entered
|
||||
[ ${#VDM_ENV_KEY} -ge 1 ] || VDM_ENV_KEY="A"
|
||||
}
|
||||
[ ${#VDM_SUBDOMAIN} -ge 1 ] || {
|
||||
echo -n "[enter:${VDM_KEY}] Sub-domain: "
|
||||
read -r VDM_SUBDOMAIN
|
||||
# make sure value was entered
|
||||
[ ${#VDM_SUBDOMAIN} -ge 1 ] || VDM_SUBDOMAIN=${VDM_KEY}
|
||||
}
|
||||
[ ${#VDM_DOMAIN} -ge 1 ] || {
|
||||
VDM_DOMAIN="vdm.dev"
|
||||
}
|
||||
# check the security switch
|
||||
REMOVE_SECURE=''
|
||||
ENTRY_POINT="websecure"
|
||||
# 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
|
||||
# check if env is already set
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && grep -q "VDM_${VDM_ENV_KEY}_DB=" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" || {
|
||||
# add a space or create the file
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && echo '' >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
# get the database name needed
|
||||
echo -n "[enter:vdm_io] Database name: "
|
||||
read -r vdm_database_name
|
||||
# make sure value was entered
|
||||
[ ${#vdm_database_name} -ge 1 ] || vdm_database_name="vdm_io"
|
||||
# add to env
|
||||
echo "VDM_${VDM_ENV_KEY}_DB=\"${vdm_database_name}\"" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
# get the database user name needed
|
||||
echo -n "[enter:vdm_user] Database user: "
|
||||
read -r vdm_database_user
|
||||
# make sure value was entered
|
||||
[ ${#vdm_database_user} -ge 1 ] || vdm_database_user="vdm_user"
|
||||
# add to env
|
||||
echo "VDM_${VDM_ENV_KEY}_DB_USER=\"${vdm_database_user}\"" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
# get the database user name needed
|
||||
echo -n "[enter:random] Database user password: "
|
||||
read -r vdm_database_pass
|
||||
# make sure value was entered
|
||||
[ ${#vdm_database_pass} -ge 1 ] || vdm_database_pass=$(getPass 20)
|
||||
# add to env
|
||||
echo "VDM_${VDM_ENV_KEY}_DB_PASS=\"${vdm_database_pass}\"" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
# get the database user name needed
|
||||
echo -n "[enter:random] Database root password: "
|
||||
read -r vdm_database_rootpass
|
||||
# make sure value was entered
|
||||
[ ${#vdm_database_rootpass} -ge 1 ] || vdm_database_rootpass=$(getPass 40)
|
||||
# add to env
|
||||
echo "VDM_${VDM_ENV_KEY}_DB_ROOT=\"${vdm_database_rootpass}\"" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
# add the projects path
|
||||
grep -q "VDM_PROJECT_PATH=" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" || {
|
||||
# add to env
|
||||
echo "VDM_PROJECT_PATH=\"${VDM_PROJECT_PATH}\"" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
}
|
||||
|
||||
# build function
|
||||
function buildContainer() {
|
||||
# we build the yml file
|
||||
cat <<EOF
|
||||
version: '2'
|
||||
services:
|
||||
mariadb_${VDM_KEY}:
|
||||
image: mariadb:latest
|
||||
container_name: mariadb_${VDM_KEY}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- MARIADB_DATABASE=\${VDM_${VDM_ENV_KEY}_DB}
|
||||
- MARIADB_USER=\${VDM_${VDM_ENV_KEY}_DB_USER}
|
||||
- MARIADB_PASSWORD=\${VDM_${VDM_ENV_KEY}_DB_PASS}
|
||||
- MARIADB_ROOT_PASSWORD=\${VDM_${VDM_ENV_KEY}_DB_ROOT}
|
||||
volumes:
|
||||
- "\${VDM_PROJECT_PATH}/${VDM_KEY}/db:/var/lib/mysql"
|
||||
networks:
|
||||
- traefik
|
||||
joomla_${VDM_KEY}:
|
||||
image: joomla:${VDM_JV}
|
||||
container_name: joomla_${VDM_KEY}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- JOOMLA_DB_HOST=mariadb_${VDM_KEY}:3306
|
||||
- JOOMLA_DB_NAME=\${VDM_${VDM_ENV_KEY}_DB}
|
||||
- JOOMLA_DB_USER=\${VDM_${VDM_ENV_KEY}_DB_USER}
|
||||
- JOOMLA_DB_PASSWORD=\${VDM_${VDM_ENV_KEY}_DB_PASS}
|
||||
depends_on:
|
||||
- mariadb_${VDM_KEY}
|
||||
volumes:
|
||||
- "\${VDM_PROJECT_PATH}/${VDM_KEY}/joomla:/var/www/html"
|
||||
networks:
|
||||
- traefik
|
||||
labels:
|
||||
# joomla
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.joomla_${VDM_KEY}.rule=Host(\`${VDM_SUBDOMAIN}.${VDM_DOMAIN}\`)"
|
||||
- "traefik.http.routers.joomla_${VDM_KEY}.entrypoints=${ENTRY_POINT}"
|
||||
${REMOVE_SECURE} - "traefik.http.routers.joomla_${VDM_KEY}.tls.certresolver=vdmresolver"
|
||||
- "traefik.http.routers.joomla_${VDM_KEY}.service=joomla_${VDM_KEY}"
|
||||
- "traefik.http.services.joomla_${VDM_KEY}.loadbalancer.server.port=80"
|
||||
phpmyadmin_${VDM_KEY}:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
container_name: phpmyadmin_${VDM_KEY}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PMA_HOST: mariadb_${VDM_KEY}
|
||||
PMA_PORT: 3306
|
||||
UPLOAD_LIMIT: 300M
|
||||
depends_on:
|
||||
- mariadb_${VDM_KEY}
|
||||
networks:
|
||||
- traefik
|
||||
labels:
|
||||
# phpmyadmin
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.phpmyadmin_${VDM_KEY}.rule=Host(\`${VDM_SUBDOMAIN}db.${VDM_DOMAIN}\`)"
|
||||
- "traefik.http.routers.phpmyadmin_${VDM_KEY}.entrypoints=${ENTRY_POINT}"
|
||||
${REMOVE_SECURE} - "traefik.http.routers.phpmyadmin_${VDM_KEY}.tls.certresolver=vdmresolver"
|
||||
- "traefik.http.routers.phpmyadmin_${VDM_KEY}.service=phpmyadmin_${VDM_KEY}"
|
||||
- "traefik.http.services.phpmyadmin_${VDM_KEY}.loadbalancer.server.port=80"
|
||||
|
||||
|
||||
networks:
|
||||
traefik:
|
||||
external:
|
||||
name: traefik_webgateway
|
||||
EOF
|
||||
}
|
||||
|
||||
# set host file if needed
|
||||
source "${VDM_SRC_PATH}/host.sh"
|
||||
|
||||
# create the directory if it does not yet already exist
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN}.${VDM_DOMAIN}"
|
||||
# place this docker composer file in its place
|
||||
buildContainer >"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN}.${VDM_DOMAIN}/docker-compose.yml"
|
||||
# set permissions
|
||||
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!"
|
@ -1,455 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}"
|
||||
# be sure to .ssh path exist
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.ssh"
|
||||
|
||||
# check if we have global env file
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && source "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" || {
|
||||
touch "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
chmod 600 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
|
||||
# help message ʕ•ᴥ•ʔ
|
||||
function show_help() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/:-} [OPTION...]
|
||||
Options
|
||||
======================================================
|
||||
-u|--username <username>
|
||||
set username of the container
|
||||
example: ${0##*/:-} -u="ubuntu"
|
||||
example: ${0##*/:-} --username="ubuntu"
|
||||
======================================================
|
||||
--uid <id>
|
||||
set container user id
|
||||
example: ${0##*/:-} --uid=1000
|
||||
======================================================
|
||||
--gid <id>
|
||||
set container user group id
|
||||
example: ${0##*/:-} --gid=1000
|
||||
======================================================
|
||||
-p|--port <port>
|
||||
set ssh port to use
|
||||
!! do not use 22 !!
|
||||
example: ${0##*/:-} -p=2239
|
||||
example: ${0##*/:-} --port=2239
|
||||
======================================================
|
||||
--ssh-dir <dir>
|
||||
set ssh directory name found in the .ssh dir
|
||||
of this repo for the container keys
|
||||
This directory has separate files for
|
||||
each public key allowed to access
|
||||
the container
|
||||
example: ${0##*/:-} --ssh-dir="teamname"
|
||||
======================================================
|
||||
--sudo
|
||||
switch to add the container user to the
|
||||
sudo group of the container
|
||||
example: ${0##*/:-} --sudo
|
||||
======================================================
|
||||
-k|--key <key>
|
||||
set key for the docker compose container naming
|
||||
!! no spaces allowed in the key !!
|
||||
example: ${0##*/:-} -k="vdm"
|
||||
example: ${0##*/:-} --key="vdm"
|
||||
======================================================
|
||||
-e|--env-key <key>
|
||||
set key for the environment variable naming
|
||||
!! no spaces allowed in the key & must be UPPERCASE !!
|
||||
example: ${0##*/:-} -e="VDM"
|
||||
example: ${0##*/:-} --env-key="VDM"
|
||||
======================================================
|
||||
-d|--domain <domain.com>
|
||||
set key website domain
|
||||
!! must be domain.tld !!
|
||||
example: ${0##*/:-} -d="vdm.dev"
|
||||
example: ${0##*/:-} --domain="vdm.dev"
|
||||
======================================================
|
||||
-t|--time-zone <time/zone>
|
||||
set time zone of the container
|
||||
!! must valid time zone !!
|
||||
example: ${0##*/:-} -t="Africa/Windhoek"
|
||||
example: ${0##*/:-} --time-zone="Africa/Windhoek"
|
||||
======================================================
|
||||
-h|--help
|
||||
display this help menu
|
||||
example: ${0##*/:-} -h
|
||||
example: ${0##*/:-} --help
|
||||
======================================================
|
||||
${BOT_NAME}
|
||||
======================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
# set the local values
|
||||
while :; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
show_help # Display a usage synopsis.
|
||||
exit
|
||||
;;
|
||||
--sudo)
|
||||
VDM_SUDO_ACCESS=true
|
||||
shift
|
||||
;;
|
||||
-u | --username) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_USER_NAME=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--username" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-u=?* | --username=?*)
|
||||
VDM_USER_NAME=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-u= | --username=) # Handle the case of an empty --username=
|
||||
echo '[error] "--username=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--uid) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_PUID=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--uid" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--uid=?*)
|
||||
VDM_PUID=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--uid=) # Handle the case of an empty --uid=
|
||||
echo '[error] "--uid=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--gid) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_PGID=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--gid" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--gid=?*)
|
||||
VDM_PGID=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--gid=) # Handle the case of an empty --gid=
|
||||
echo '[error] "--gid=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-p | --port) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_PORT=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--port" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-p=?* | --port=?*)
|
||||
VDM_PORT=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-p= | --port=) # Handle the case of an empty --port=
|
||||
echo '[error] "--port=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
--ssh-dir) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_PUBLIC_KEY_DIR=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--ssh-dir" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
--ssh-dir=?*)
|
||||
VDM_PUBLIC_KEY_DIR=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-ssh-dir=) # Handle the case of an empty --ssh-dir=
|
||||
echo '[error] "--ssh-dir=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-k | --key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-k=?* | --key=?*)
|
||||
VDM_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-k= | --key=) # Handle the case of an empty --key=
|
||||
echo '[error] "--key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-e | --env-key) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_ENV_KEY=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--env-key" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-e=?* | --env-key=?*)
|
||||
VDM_ENV_KEY=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-e= | --env-key=) # Handle the case of an empty --env-key=
|
||||
echo '[error] "--env-key=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-d | --domain) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_DOMAIN=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--domain" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-d=?* | --domain=?*)
|
||||
VDM_DOMAIN=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-d= | --domain=) # Handle the case of an empty --domain=
|
||||
echo '[error] "--domain=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
-t | --time-zone) # Takes an option argument; ensure it has been specified.
|
||||
if [ "$2" ]; then
|
||||
VDM_TZ=$2
|
||||
shift
|
||||
else
|
||||
echo '[error] "--time-zone" requires a non-empty option argument.'
|
||||
exit 17
|
||||
fi
|
||||
;;
|
||||
-t=?* | --time-zone=?*)
|
||||
VDM_TZ=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
-t= | --time-zone=) # Handle the case of an empty --time-zone=
|
||||
echo '[error] "--time-zone=" requires a non-empty option argument.'
|
||||
exit 17
|
||||
;;
|
||||
*) # Default case: No more options, so break out of the loop.
|
||||
break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# check that we have what we need
|
||||
[ ${#VDM_PORT} -ge 1 ] || {
|
||||
echo -n "[enter] SSH Port: "
|
||||
read -r VDM_PORT
|
||||
# make sure value was entered
|
||||
[ ${#VDM_PORT} -ge 1 ] || exit
|
||||
}
|
||||
[ ${#VDM_USER_NAME} -ge 1 ] || {
|
||||
echo -n "[enter:ubuntu] UserName: "
|
||||
read -r VDM_USER_NAME
|
||||
}
|
||||
[ ${#VDM_KEY} -ge 1 ] || {
|
||||
echo -n "[enter:${VDM_USER_NAME:-ubuntu}] key: "
|
||||
read -r VDM_KEY
|
||||
# make sure value was entered
|
||||
[ ${#VDM_KEY} -ge 1 ] || VDM_KEY="${VDM_USER_NAME:-ubuntu}"
|
||||
}
|
||||
[ ${#VDM_ENV_KEY} -ge 1 ] || {
|
||||
echo -n "[enter:A] env key: "
|
||||
read -r VDM_ENV_KEY
|
||||
# make sure value was entered
|
||||
[ ${#VDM_ENV_KEY} -ge 1 ] || VDM_ENV_KEY="A"
|
||||
}
|
||||
# we must get the global public key path
|
||||
VDM_ENV_PUBLIC_KEY_GLOBAL_DIR="VDM_${VDM_ENV_KEY^^}_PUBLIC_KEY_GLOBAL_DIR"
|
||||
VDM_PUBLIC_KEY_GLOBAL_DIR=${!VDM_ENV_PUBLIC_KEY_GLOBAL_DIR}
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#VDM_PUBLIC_KEY_GLOBAL_DIR} -ge 1 ] && [ -d "${VDM_PUBLIC_KEY_GLOBAL_DIR}" ] || {
|
||||
VDM_PUBLIC_KEY_GLOBAL_DIR="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.ssh"
|
||||
# make sure value was entered
|
||||
[ ${#VDM_PUBLIC_KEY_GLOBAL_DIR} -ge 1 ] && [ -d "${VDM_PUBLIC_KEY_GLOBAL_DIR}" ] || exit
|
||||
# add to env file
|
||||
echo "${VDM_ENV_PUBLIC_KEY_GLOBAL_DIR}=${VDM_PUBLIC_KEY_GLOBAL_DIR}" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
# get available public dir
|
||||
function getPublicKeyDir() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
export PS3="[select] Public ssh key directory: "
|
||||
# we start the selection array
|
||||
local SELECTED
|
||||
# Start our little Menu
|
||||
select public_dir in $(ls "${VDM_PUBLIC_KEY_GLOBAL_DIR}"); do
|
||||
case $REPLY in
|
||||
*)
|
||||
SELECTED="${public_dir}"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
# restore the default
|
||||
export PS3=$PS3_old
|
||||
# return selection
|
||||
echo "${SELECTED}"
|
||||
}
|
||||
|
||||
[ ${#VDM_PUBLIC_KEY_DIR} -ge 1 ] || {
|
||||
VDM_PUBLIC_KEY_DIR=$(getPublicKeyDir)
|
||||
# make sure value was entered
|
||||
[ ${#VDM_PUBLIC_KEY_DIR} -ge 1 ] && [ -d "${VDM_PUBLIC_KEY_GLOBAL_DIR}/${VDM_PUBLIC_KEY_DIR}" ] || exit
|
||||
}
|
||||
# set the global key env string for the ssh keys
|
||||
VDM_ENV_PUBLIC_KEY_U_DIR="VDM_${VDM_ENV_KEY^^}_PUBLIC_KEY_${VDM_PUBLIC_KEY_DIR^^}_DIR"
|
||||
VDM_PUBLIC_KEY_U_DIR=${!VDM_ENV_PUBLIC_KEY_U_DIR}
|
||||
# check if env is already set
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" ] && grep -q "${VDM_ENV_PUBLIC_KEY_U_DIR}=" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env" || {
|
||||
# add to env if not exist
|
||||
[ ${#VDM_PUBLIC_KEY_U_DIR} -ge 1 ] && [ -d "${VDM_PUBLIC_KEY_U_DIR}" ] || {
|
||||
echo "${VDM_ENV_PUBLIC_KEY_U_DIR}=${VDM_PUBLIC_KEY_GLOBAL_DIR}/${VDM_PUBLIC_KEY_DIR}" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
}
|
||||
# we must get the project path
|
||||
VDM_ENV_PROJECT_DIR="VDM_${VDM_ENV_KEY^^}_PROJECT_DIR"
|
||||
VDM_PROJECT_DIR=${!VDM_ENV_PROJECT_DIR}
|
||||
# shellcheck disable=SC2015
|
||||
[ ${#VDM_PROJECT_DIR} -ge 1 ] && [ -d "${VDM_PROJECT_DIR}" ] || {
|
||||
VDM_PROJECT_DIR="${VDM_PROJECT_PATH}"
|
||||
# make sure value was entered
|
||||
[ ${#VDM_PROJECT_DIR} -ge 1 ] && [ -d "${VDM_PROJECT_DIR}" ] || exit
|
||||
# add to env file
|
||||
echo "VDM_${VDM_ENV_KEY^^}_PROJECT_DIR=${VDM_PROJECT_DIR}" >>"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
}
|
||||
# return volume line
|
||||
function getVolumeLine() {
|
||||
# get the projects to mount
|
||||
local line="$1"
|
||||
# return line
|
||||
cat <<EOF
|
||||
|
||||
- ${line}
|
||||
EOF
|
||||
}
|
||||
# get available mounting projects
|
||||
function getMountingProjects() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
# some defaults
|
||||
export PS3="[select] Projects to mount: "
|
||||
# some buckets
|
||||
FINISHED="n"
|
||||
SELECTED=$(getVolumeLine "\${${VDM_ENV_PUBLIC_KEY_U_DIR}}:/config/ssh_public_keys")
|
||||
until [ "${FINISHED}" = "y" ]; do
|
||||
# Start our little Menu
|
||||
select key in $(ls "${VDM_PROJECT_DIR}"); do
|
||||
case $REPLY in
|
||||
q | quit)
|
||||
FINISHED="y"
|
||||
;;
|
||||
*)
|
||||
SELECTED+=$(getVolumeLine "\${VDM_${VDM_ENV_KEY^^}_PROJECT_DIR}/${key}/joomla:/app/${key}")
|
||||
FINISHED="n"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
done
|
||||
# restore the default
|
||||
export PS3=$PS3_old
|
||||
# return selection
|
||||
echo "${SELECTED}"
|
||||
}
|
||||
# now load the projects
|
||||
[ ${#VDM_MOUNT_PROJECTS} -ge 1 ] || {
|
||||
echo "[enter] q to quit selecting"
|
||||
# get the projects to mount
|
||||
VDM_MOUNT_PROJECTS=$(getMountingProjects)
|
||||
# get the mounting options
|
||||
[ ${#VDM_MOUNT_PROJECTS} -ge 1 ] || exit 1
|
||||
}
|
||||
|
||||
# all values loaded notice
|
||||
echo "[All value loaded]"
|
||||
|
||||
# build function
|
||||
function buildContainer() {
|
||||
# get the projects to mount
|
||||
local mount_projects="$1"
|
||||
# we build the yml file
|
||||
# we use 33 as this is the www-data ID
|
||||
cat <<EOF
|
||||
version: "2.1"
|
||||
services:
|
||||
openssh-server-${VDM_KEY}:
|
||||
image: lscr.io/linuxserver/openssh-server
|
||||
container_name: openssh-server-${VDM_KEY}
|
||||
restart: unless-stopped
|
||||
hostname: ${VDM_DOMAIN:-vdm.dev}
|
||||
environment:
|
||||
- PUID=${VDM_PUID:-33}
|
||||
- PGID=${VDM_PGID:-33}
|
||||
- TZ=${VDM_TZ:-Africa/Windhoek}
|
||||
- PUBLIC_KEY_DIR=/config/ssh_public_keys
|
||||
- SUDO_ACCESS=${VDM_SUDO_ACCESS:-false}
|
||||
- USER_NAME=${VDM_USER_NAME:-ubuntu}
|
||||
volumes:${mount_projects}
|
||||
ports:
|
||||
- ${VDM_PORT}:2222
|
||||
networks:
|
||||
- openssh
|
||||
|
||||
networks:
|
||||
openssh:
|
||||
external:
|
||||
name: openssh_gateway
|
||||
EOF
|
||||
}
|
||||
|
||||
# create the directory if it does not yet already exist
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_USER_NAME:-ubuntu}.${VDM_DOMAIN:-vdm.dev}"
|
||||
# place this docker composer file in its place
|
||||
buildContainer "${VDM_MOUNT_PROJECTS}" >"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_USER_NAME:-ubuntu}.${VDM_DOMAIN:-vdm.dev}/docker-compose.yml"
|
||||
# set permissions
|
||||
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!"
|
@ -1,119 +0,0 @@
|
||||
#!/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 <<EOF
|
||||
version: "3.3"
|
||||
|
||||
services:
|
||||
portainer:
|
||||
image: portainer/portainer-ce:latest
|
||||
container_name: portainer
|
||||
command: -H unix:///var/run/docker.sock
|
||||
restart: always
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- portainer_data:/data
|
||||
labels:
|
||||
# Frontend
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.portainer.rule=Host(\`port.${VDM_DOMAIN}\`)"
|
||||
- "traefik.http.routers.portainer.entrypoints=${ENTRY_POINT}"
|
||||
${REMOVE_SECURE} - "traefik.http.routers.portainer.tls.certresolver=vdmresolver"
|
||||
- "traefik.http.routers.portainer.service=portainer"
|
||||
- "traefik.http.services.portainer.loadbalancer.server.port=9000"
|
||||
|
||||
# Edge
|
||||
# - "traefik.http.routers.portaineredge.rule=Host(\`edge.${VDM_DOMAIN}\`)"
|
||||
# - "traefik.http.routers.portaineredge.entrypoints=${ENTRY_POINT}"
|
||||
# - "traefik.http.routers.portaineredge.tls.certresolver=vdmresolver"
|
||||
# - "traefik.http.routers.portaineredge.service=portaineredge"
|
||||
# - "traefik.http.services.portaineredge.loadbalancer.server.port=8000"
|
||||
networks:
|
||||
- traefik
|
||||
|
||||
volumes:
|
||||
portainer_data:
|
||||
|
||||
networks:
|
||||
traefik:
|
||||
external:
|
||||
name: traefik_webgateway
|
||||
EOF
|
||||
}
|
||||
|
||||
# set host file if needed
|
||||
source "${VDM_SRC_PATH}/host.sh" "port"
|
||||
|
||||
## 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
|
@ -1,140 +0,0 @@
|
||||
#!/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=''
|
||||
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): "
|
||||
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="#"
|
||||
HTTP_SCHEME="http"
|
||||
fi
|
||||
|
||||
# build function
|
||||
function buildContainer() {
|
||||
# we build the yml file
|
||||
cat <<EOF
|
||||
version: "3.3"
|
||||
|
||||
services:
|
||||
traefik:
|
||||
container_name: traefik
|
||||
image: "traefik:latest"
|
||||
command:
|
||||
- --entrypoints.web.address=:80
|
||||
- --entrypoints.websecure.address=:443
|
||||
# - --api.dashboard=true
|
||||
# - --api.insecure=true
|
||||
- --providers.docker
|
||||
- --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}
|
||||
${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.storage=/acme.json
|
||||
${REMOVE_SECURE} - --certificatesresolvers.vdmresolver.acme.httpchallenge.entrypoint=web
|
||||
# - --providers.file.directory=/conf
|
||||
# - --providers.file.watch=true
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
# - "8080:8080"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
# - "\${VDM_PROJECT_PATH}/traefik/conf:/conf"
|
||||
${REMOVE_SECURE} - "\${VDM_PROJECT_PATH}/traefik/acme.json:/acme.json"
|
||||
- "\${VDM_PROJECT_PATH}/traefik/errors:/errors"
|
||||
labels:
|
||||
# settings for all containers
|
||||
- "traefik.http.routers.http-catchall.rule=hostregexp(\`{host:.+}\`)"
|
||||
- "traefik.http.routers.http-catchall.entrypoints=web"
|
||||
- "traefik.http.routers.http-catchall.middlewares=redirect-to-me"
|
||||
- "traefik.http.middlewares.redirect-to-me.redirectscheme.scheme=${HTTP_SCHEME}"
|
||||
networks:
|
||||
- traefik
|
||||
|
||||
networks:
|
||||
traefik:
|
||||
external:
|
||||
name: traefik_webgateway
|
||||
EOF
|
||||
}
|
||||
|
||||
## create the directory if it does not yet already exist
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m 700 "${VDM_REPO_PATH}/traefik"
|
||||
## place this docker composer file in its place
|
||||
buildContainer >"${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
|
51
src/setup.sh
51
src/setup.sh
@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check that our repository path is correct
|
||||
[ -e "${VDM_SRC_PATH}" ] || {
|
||||
echo "[error] Source path (${VDM_SRC_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
|
||||
}
|
||||
|
||||
# get container type
|
||||
function getContainerType() {
|
||||
# some house cleaning
|
||||
PS3_old=$PS3
|
||||
# some defaults
|
||||
export PS3="Please select the kind of container to setup: "
|
||||
# Start our little Menu (only these two for now)
|
||||
select menu in "joomla" "openssh"; 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_CONTAINER_TYPE="${1:-$VDM_CONTAINER_TYPE}"
|
||||
# check that we have what we need
|
||||
[ ${#VDM_CONTAINER_TYPE} -ge 1 ] || {
|
||||
VDM_CONTAINER_TYPE=$(getContainerType)
|
||||
# make sure value was entered
|
||||
[ ${#VDM_CONTAINER_TYPE} -ge 1 ] || {
|
||||
echo "[error] Wrong container type selected"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
export VDM_CONTAINER_TYPE
|
||||
|
||||
# run that container setup script
|
||||
# shellcheck disable=SC1090
|
||||
source "${VDM_SRC_PATH}/setup-${VDM_CONTAINER_TYPE}.sh"
|
@ -1,77 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BOT name
|
||||
BOT_NAME="docker-deploy v1.0"
|
||||
|
||||
# we load global environment values
|
||||
# shellcheck disable=SC2015
|
||||
[ -f "${VDM_SRC_PATH}/.env" ] && source "${VDM_SRC_PATH}/.env" || {
|
||||
echo "${VDM_SRC_PATH}/.env file not found, please run install."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# take down all containers
|
||||
# shellcheck disable=SC1090
|
||||
# ----------------------------------------------------- MULTI CONTAINERS
|
||||
# check if we have possible joomla containers
|
||||
if [ -e "${VDM_REPO_PATH}/joomla/enabled" ]; then
|
||||
echo -n "[enter:y] Take down Joomla containers [y/n]: "
|
||||
read -r VDM_DOWN_JOOMLA
|
||||
# set the default if empty
|
||||
VDM_DOWN_JOOMLA="${VDM_DOWN_JOOMLA:-y}"
|
||||
# make sure it exist
|
||||
if [ "${VDM_DOWN_JOOMLA,,}" != 'n' ]; then
|
||||
export VDM_CONTAINER_TYPE="joomla"
|
||||
source "${VDM_SRC_PATH}/down.sh"
|
||||
fi
|
||||
# remove all enabled
|
||||
rm -fr "${VDM_REPO_PATH}/joomla/enabled"
|
||||
fi
|
||||
# check if we have possible openssh containers
|
||||
if [ -e "${VDM_REPO_PATH}/openssh/enabled" ]; then
|
||||
echo -n "[enter:y] Take down Openssh containers [y/n]: "
|
||||
read -r VDM_DOWN_OPENSSH
|
||||
# set the default if empty
|
||||
VDM_DOWN_OPENSSH="${VDM_DOWN_OPENSSH:-y}"
|
||||
# make sure it exist
|
||||
if [ "${VDM_DOWN_OPENSSH,,}" != 'n' ]; then
|
||||
export VDM_CONTAINER_TYPE="openssh"
|
||||
source "${VDM_SRC_PATH}/down.sh"
|
||||
fi
|
||||
# remove all enabled
|
||||
rm -fr "${VDM_REPO_PATH}/openssh/enabled"
|
||||
fi
|
||||
# ----------------------------------------------------- SINGLE CONTAINER
|
||||
# check if we have possible portainer container
|
||||
if [ -f "${VDM_REPO_PATH}/portainer/docker-compose.yml" ]; then
|
||||
echo -n "[enter:y] Take down Portainer container [y/n]: "
|
||||
read -r VDM_DOWN_PORTAINER
|
||||
# set the default if empty
|
||||
VDM_DOWN_PORTAINER="${VDM_DOWN_PORTAINER:-y}"
|
||||
# make sure it exist
|
||||
if [ "${VDM_DOWN_PORTAINER,,}" != 'n' ]; then
|
||||
docker-compose --file "${VDM_REPO_PATH}/portainer/docker-compose.yml" down
|
||||
fi
|
||||
# we just have one yml file here (so dont remove it for now)
|
||||
# rm -fr "${VDM_REPO_PATH}/portainer"
|
||||
fi
|
||||
# check if we have possible traefik container
|
||||
if [ -f "${VDM_REPO_PATH}/traefik/docker-compose.yml" ]; then
|
||||
echo -n "[enter:y] Take down Traefik container [y/n]: "
|
||||
read -r VDM_DOWN_TRAEFIK
|
||||
# set the default if empty
|
||||
VDM_DOWN_TRAEFIK="${VDM_DOWN_TRAEFIK:-y}"
|
||||
# make sure it exist
|
||||
if [ "${VDM_DOWN_TRAEFIK,,}" != 'n' ]; then
|
||||
docker-compose --file "${VDM_REPO_PATH}/traefik/docker-compose.yml" down
|
||||
fi
|
||||
# we just have one yml file here (so dont remove it for now)
|
||||
# rm -fr "${VDM_REPO_PATH}/traefik"
|
||||
fi
|
||||
# ----------------------------------------------------- REMOVE SCRIPT
|
||||
# now remove the docker-deploy script
|
||||
sudo rm /usr/local/bin/docker-deploy
|
||||
|
||||
echo "[notice] ${BOT_NAME} has been uninstalled."
|
||||
|
||||
exit 0
|
27
src/up.sh
27
src/up.sh
@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check that our repository path is correct
|
||||
[ -e "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled" ] || {
|
||||
echo "[error] Repository path (${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled) does not exist, first enable some containers."
|
||||
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
|
||||
}
|
||||
|
||||
# the main function
|
||||
main() {
|
||||
# get all zip files
|
||||
for yml in "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/enabled/"*/*.yml; do
|
||||
# get the vdm_container value
|
||||
vdm_container="${yml%/docker-compose.yml}"
|
||||
# check if image has its own env file also
|
||||
[ -f "${vdm_container}/.env" ] && ENV_FILE="${vdm_container}/.env" || ENV_FILE="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/.env"
|
||||
docker-compose --env-file "${ENV_FILE}" --file "${yml}" up -d
|
||||
done
|
||||
}
|
||||
|
||||
# run main
|
||||
main
|
Reference in New Issue
Block a user