6 Commits

2 changed files with 362 additions and 230 deletions

View File

@ -1,4 +1,4 @@
# Easy Docker Deployment (UBUNTU ONLY)
# Octojoom - Easy Docker Deployment
With this script we can easily deploy docker containers of Joomla and Openssh. This combination of these tools give rise to a powerful and very secure shared development environment.
This program has **command input** options as seen in the menus below, but these command are _not the only way_ to set these values.
@ -8,40 +8,34 @@ There are more than one .env file and the script will set those up for you whene
the script will check if those values exist, and if they don't it will ask for them, and store them automatically for future use.
That same time the output message to the terminal will show you where the specific .env file can be found.
> program only for ubuntu/debian systems at this time (should you like to use it on other OS's please open and issue...)
---
# Install
```shell
$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/docker-deploy/raw/src/docker-deploy?access_token=xxxx" -o /usr/local/bin/docker-deploy
$ sudo chmod +x /usr/local/bin/docker-deploy
$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/octojoom/raw/src/octojoom" -o /usr/local/bin/octojoom
$ sudo chmod +x /usr/local/bin/octojoom
```
### How to get the Access Token
Sign in to [https://git.vdm.dev/](https://git.vdm.dev/user/login) with your **GitHub** or **Gitlab** account.
Then open your [applications settings](https://git.vdm.dev/user/settings/applications) and create a new access token.
![image](https://user-images.githubusercontent.com/5607939/143513412-946843be-acd8-4973-be44-00902226f6ba.png)
The first time you use the program, it will ask for the access token again, so it can do updates in the future.
---
# Usage
> To see the usage help menu
```shell
$ docker-deploy -h
$ octojoom -h
```
### Help Menu (docker-deploy)
### Help Menu (octojoom)
```txt
Usage: docker-deploy [OPTION...]
Usage: octojoom [OPTION...]
Options
======================================================
--type <type>
set type you would like to work with
example: docker-deploy --type joomla
example: octojoom --type joomla
======================================================
--task <task>
set type of task you would like to perform
example: docker-deploy --task setup
example: octojoom --task setup
======================================================
--container <container.domain.name>
Directly enabling or disabling a container with
@ -49,74 +43,74 @@ Usage: docker-deploy [OPTION...]
The container must exist, which means it was
setup previously
Used without type and task Joomla-Enable is (default)
example: docker-deploy --container "io.vdm.dev"
example: octojoom --container "io.vdm.dev"
======================================================
--update
to update your install
example: docker-deploy --update
example: octojoom --update
======================================================
--access-token <token>
to update the program you will need an access token
from https://git.vdm.dev/user/settings/applications
example: docker-deploy --access-token xxxxxxxxxxx
example: octojoom --access-token xxxxxxxxxxx
======================================================
--uninstall
to uninstall this script
example: docker-deploy --uninstall
example: octojoom --uninstall
======================================================
AVAILABLE FOR TO ANY CONTAINER
======================================================
-k|--key <key>
set key for the docker compose container naming
!! no spaces allowed in the key !!
example: docker-deploy -k="vdm"
example: docker-deploy --key="vdm"
example: octojoom -k="vdm"
example: octojoom --key="vdm"
======================================================
-e|--env-key <key>
set key for the environment variable naming
!! no spaces allowed in the key & must be UPPERCASE !!
example: docker-deploy -e="VDM"
example: docker-deploy --env-key="VDM"
example: octojoom -e="VDM"
example: octojoom --env-key="VDM"
======================================================
-d|--domain <domain.com>
set key website domain
!! must be domain.tld !!
example: docker-deploy -d="joomla.org"
example: docker-deploy --domain="joomla.org"
example: octojoom -d="joomla.org"
example: octojoom --domain="joomla.org"
======================================================
-s|--sub-domain <domain.com>
set key website sub domain
!! no spaces allowed in the sub domain !!
example: docker-deploy -s="jcb"
example: docker-deploy --sub-domain="jcb"
example: octojoom -s="jcb"
example: octojoom --sub-domain="jcb"
======================================================
AVAILABLE FOR JOOMLA CONTAINER
======================================================
-j|--joomla-version <version-tag>
see available tags here https://hub.docker.com/_/joomla
example: docker-deploy -j=3.10
example: docker-deploy --joomla-version=3.10
example: octojoom -j=3.10
example: octojoom --joomla-version=3.10
======================================================
AVAILABLE FOR OPENSSH CONTAINER
======================================================
-u|--username <username>
set username of the container
example: docker-deploy -u="ubuntu"
example: docker-deploy --username="ubuntu"
example: octojoom -u="ubuntu"
example: octojoom --username="ubuntu"
======================================================
--uid <id>
set container user id
example: docker-deploy --uid=1000
example: octojoom --uid=1000
======================================================
--gid <id>
set container user group id
example: docker-deploy --gid=1000
example: octojoom --gid=1000
======================================================
-p|--port <port>
set ssh port to use
!! do not use 22 !!
example: docker-deploy -p=2239
example: docker-deploy --port=2239
example: octojoom -p=2239
example: octojoom --port=2239
======================================================
--ssh-dir <dir>
set ssh directory name found in the .ssh dir
@ -124,34 +118,34 @@ Usage: docker-deploy [OPTION...]
This directory has separate files for
each public key allowed to access
the container
example: docker-deploy --ssh-dir="teamname"
example: octojoom --ssh-dir="teamname"
======================================================
--sudo
switch to add the container user to the
sudo group of the container
example: docker-deploy --sudo
example: octojoom --sudo
======================================================
-t|--time-zone <time/zone>
set time zone of the container
!! must valid time zone !!
example: docker-deploy -t="Africa/Windhoek"
example: docker-deploy --time-zone="Africa/Windhoek"
example: octojoom -t="Africa/Windhoek"
example: octojoom --time-zone="Africa/Windhoek"
======================================================
HELP ʕ•ᴥ•ʔ
======================================================
-h|--help
display this help menu
example: docker-deploy -h
example: docker-deploy --help
example: octojoom -h
example: octojoom --help
======================================================
Docker Deployment v2.1.0
Octojoom
======================================================
```
---
# Uninstall
```shell
$ docker-deploy --uninstall
$ octojoom --uninstall
```
---
# Free Software License

View File

@ -1,11 +1,11 @@
#!/bin/bash
# The most recent program version.
_VERSION="2.1.0"
_V="2.1"
_VERSION="3.0.1"
_V="3.0"
# The program full name
PROGRAM_NAME="Docker Deployment"
PROGRAM_NAME="Octojoom"
# make sure whiptail is installed
command -v whiptail >/dev/null 2>&1 || {
@ -176,8 +176,6 @@ function portainer__TRuST__setup() {
# container
export VDM_REMOVE_SECURE
export VDM_ENTRY_POINT
# set the update of the host file once
setUpdateHostFile
# set host file if needed
updateHostFile
## create the directory if it does not yet already exist
@ -261,13 +259,21 @@ function joomla__TRuST__setup() {
local vdm_env_pass
local vdm_key_root
local vdm_env_root
# get the Joomla image source
VDM_J_REPO=$(getImageSource)
# build the URL
if [ "${VDM_J_REPO}" = 'joomla' ]; then
vdm_image_repo_url="https://hub.docker.com/_/${VDM_J_REPO}?tab=tags"
else
vdm_image_repo_url="https://hub.docker.com/r/${VDM_J_REPO}/tags"
fi
# get the Joomla version if not set
while [ ${#VDM_JV} -le 1 ]; do
# get the value
VDM_JV=$(getInput 'Enter Joomla version tag for this container.\n[See available tags here https://hub.docker.com/_/joomla]' '3.10' 'Enter Version Tag')
VDM_JV=$(getInput "Enter Joomla version tag for this container.\n[See available tags here ${vdm_image_repo_url}]" '3.10' 'Enter Version Tag')
# keep asking
[ ${#VDM_JV} -ge 1 ] || {
showError "You must enter a version tag. See available tags here https://hub.docker.com/_/joomla"
showError "You must enter a version tag. See available tags here ${vdm_image_repo_url}"
}
done
# get the key if not set
@ -352,6 +358,16 @@ function joomla__TRuST__setup() {
}
# add the projects path
setContainerEnvVariable "VDM_PROJECT_PATH=\"${VDM_PROJECT_PATH}\""
# set the container user detail id needed
if [ "${VDM_J_REPO}" = 'llewellyn/joomla' ]; then
# if this is our octoleo images we can also set the user ID and user-group ID
setContainerUser
# check that we got the details
if [ -n "${VDM_PUID}" ] && [ -n "${VDM_PGID}" ]; then
setContainerEnvVariable "VDM_${VDM_ENV_KEY^^}_PUID=\"#${VDM_PUID}\""
setContainerEnvVariable "VDM_${VDM_ENV_KEY^^}_PGID=\"#${VDM_PGID}\""
fi
fi
# add this value if not set variable
[ ${#vdm_database_name} -ge 1 ] && setContainerEnvVariable "VDM_${VDM_ENV_KEY^^}_DB=\"${vdm_database_name}\""
# add this value if not set variable
@ -367,6 +383,7 @@ function joomla__TRuST__setup() {
export VDM_REPO_PATH
export VDM_PROJECT_PATH
# container
export VDM_J_REPO
export VDM_JV
export VDM_REMOVE_SECURE
export VDM_ENTRY_POINT
@ -376,8 +393,6 @@ function joomla__TRuST__setup() {
export vdm_database_user
export vdm_database_pass
export vdm_database_rootpass
# set the update of the host file once
setUpdateHostFile
# set host file if needed
updateHostFile
# also set the database domain
@ -404,12 +419,15 @@ function joomla__TRuST__setup() {
### unset all no longer needed
# container
unset VDM_SUBDOMAIN
unset VDM_J_REPO
unset VDM_JV
unset VDM_KEY
unset VDM_ENV_KEY
unset VDM_REMOVE_SECURE
unset VDM_ENTRY_POINT
unset VDM_HTTP_SCHEME
unset VDM_PUID
unset VDM_PGID
# container lower
unset vdm_database_name
unset vdm_database_user
@ -421,6 +439,13 @@ function joomla__TRuST__setup() {
# return the Joomla Container setup yml
function joomlaContainer() {
# set the USER if set
vdm_container_user=''
if [ -n "${VDM_PUID}" ] && [ -n "${VDM_PGID}" ]; then
vdm_container_user="
- APACHE_RUN_USER=\${VDM_${VDM_ENV_KEY^^}_PUID}
- APACHE_RUN_GROUP=\${VDM_${VDM_ENV_KEY^^}_PGID}"
fi
# we build the yml file
cat <<EOF
version: '2'
@ -439,10 +464,10 @@ services:
networks:
- traefik
joomla_${VDM_KEY}:
image: joomla:${VDM_JV}
image: ${VDM_J_REPO}:${VDM_JV}
container_name: joomla_${VDM_KEY}
restart: unless-stopped
environment:
environment:${vdm_container_user}
- JOOMLA_DB_HOST=mariadb_${VDM_KEY}:3306
- JOOMLA_DB_NAME=\${VDM_${VDM_ENV_KEY^^}_DB}
- JOOMLA_DB_USER=\${VDM_${VDM_ENV_KEY^^}_DB_USER}
@ -517,6 +542,8 @@ function openssh__TRuST__setup() {
showError "You must enter a username for the container"
fi
done
# be sure to set the container USER ID
setContainerUser 33
# get the key if not set
setUniqueKey "Enter key used for container naming."
# get the env key if not set
@ -662,6 +689,8 @@ function openssh__TRuST__setup() {
# container
unset VDM_PORT
unset VDM_USER_NAME
unset VDM_PUID
unset VDM_PGID
unset VDM_KEY
unset VDM_ENV_KEY
unset VDM_PUBLIC_KEY_GLOBAL_DIR
@ -686,8 +715,8 @@ services:
restart: unless-stopped
hostname: ${VDM_DOMAIN:-vdm.dev}
environment:
- PUID=${VDM_PUID:-33}
- PGID=${VDM_PGID:-33}
- PUID=${VDM_PUID}
- PGID=${VDM_PGID}
- TZ=${VDM_TZ:-Africa/Windhoek}
- PUBLIC_KEY_DIR=/config/ssh_public_keys
- SUDO_ACCESS=${VDM_SUDO_ACCESS:-false}
@ -716,7 +745,7 @@ function joomla__TRuST__edit() {
local vdm_edit_me
local container
# list containers... and allow selection to edit
container=$(getSelectedDirectory "Select a container to manually edit if you like." \
container=$(getSelectedDirectory "Select a container to manually edit the docker-composer.yml file.\n[Only continue if you know what your doing!]" \
"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/" '' "Edit ${VDM_CONTAINER_TYPE^} Container")
# check that we have something, else return to main menu
if [ ${#container} -ge 1 ]; then
@ -724,6 +753,8 @@ function joomla__TRuST__edit() {
vdm_edit_me="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${container}/docker-compose.yml"
# check if this docker-composer.yml exist
if [ -f "${vdm_edit_me}" ]; then
# give little heads-up
showNotice "${USER^}, to save the changes you've made or to just close the file again press:\n\n[ctrl+x] with nano on ubuntu." 13
# lets open the file with nano for now
"${EDITOR:-nano}" "${vdm_edit_me}"
# if this container is enabled ask if it should be redeployed
@ -750,7 +781,7 @@ function openssh__TRuST__edit() {
local vdm_edit_me
local container
# list containers... and allow selection to edit
container=$(getSelectedDirectory "Select a container to manually edit if you like." \
container=$(getSelectedDirectory "Select a container to manually edit the docker-composer.yml file.\n[Only continue if you know what your doing!]" \
"${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/" '' "Edit ${VDM_CONTAINER_TYPE^} Container")
# check that we have something, else return to main menu
if [ ${#container} -ge 1 ]; then
@ -758,6 +789,8 @@ function openssh__TRuST__edit() {
vdm_edit_me="${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${container}/docker-compose.yml"
# check if this docker-composer.yml exist
if [ -f "${vdm_edit_me}" ]; then
# give little heads-up
showNotice "${USER^}, to save the changes you've made or to just close the file again press:\n\n[ctrl+x] with nano on ubuntu." 13
# lets open the file with nano for now
"${EDITOR:-nano}" "${vdm_edit_me}"
# if this container is enabled ask if it should be redeployed
@ -780,6 +813,10 @@ function traefik__TRuST__edit() {
if [ ! -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/docker-compose.yml" ]; then
showError "There is no ${VDM_CONTAINER_TYPE^} container to edit."
else
# give little warning for less command ready people
if (whiptail --yesno "Only continue if you know what your doing!\n\n\
${USER^}, to save the changes you've made or to just close the file again press:\n\n\
[ctrl+x] with nano on ubuntu." --title "Continue to edit ${VDM_CONTAINER_TYPE^} config." 15 112); then
# lets open the file with nano for now
"${EDITOR:-nano}" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/docker-compose.yml"
# if this container is enabled ask if it should be redeployed
@ -788,6 +825,7 @@ function traefik__TRuST__edit() {
enableContainer "${VDM_CONTAINER_TYPE}"
fi
fi
fi
}
#####################################################################################################################VDM
@ -797,6 +835,10 @@ function portainer__TRuST__edit() {
if [ ! -f "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/docker-compose.yml" ]; then
showError "There is no ${VDM_CONTAINER_TYPE^} container to edit."
else
# give little warning for less command ready people
if (whiptail --yesno "Only continue if you know what your doing!\n\n\
${USER^}, to save the changes you've made or to just close the file again press:\n\n\
[ctrl+x] with nano on ubuntu." --title "Continue to edit ${VDM_CONTAINER_TYPE^} config." 15 112); then
# lets open the file with nano for now
"${EDITOR:-nano}" "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/docker-compose.yml"
# if this container is enabled ask if it should be redeployed
@ -805,6 +847,7 @@ function portainer__TRuST__edit() {
enableContainer "${VDM_CONTAINER_TYPE}"
fi
fi
fi
}
#####################################################################################################################VDM
@ -818,7 +861,7 @@ function joomla__TRuST__enable() {
elif [ ! -d "${VDM_PROJECT_PATH}" ]; then
# this should never happen, but in case
showError "The path ${VDM_PROJECT_PATH} does not exist, so we can't mount the persistent volumes. This error should never show, \
please open an issue and report docker-deploy-error-1234 with the steps of how you got here?"
please open an issue and report octojoom-error-1234 with the steps of how you got here?"
elif [ ${#VDM_CONTAINER} -ge 1 ]; then
# this means we have a single already selected container to enable if it exists
if [ -d "${VDM_REPO_PATH}/${VDM_CONTAINER_TYPE}/available/${VDM_CONTAINER}" ]; then
@ -1506,39 +1549,37 @@ function deletePersistentVolumes() {
function runUpdate() {
# we need sudo permissions
if (whiptail --yesno "${USER^}, to update ${PROGRAM_NAME} we need sudo privileges." --title "Give sudo Privileges" 8 112); then
# check that we have an access token
getAccessToken || return 1
# remove the current version
if [ -f /usr/local/bin/docker-deploy ]; then
if [ -f /usr/local/bin/octojoom ]; then
# just backup in case of failure
sudo mv /usr/local/bin/docker-deploy /usr/local/bin/docker-deploy.bak
sudo mv /usr/local/bin/octojoom /usr/local/bin/octojoom.bak
fi
# some local values
local branch
# get the target branch to use in our update
branch=$(getTargetBranch)
# pull the latest version. Master is always the latest
if sudo curl --fail -L "https://git.vdm.dev/api/v1/repos/octoleo/docker-deploy/raw/src/docker-deploy?ref=${branch:-master}&access_token=${VDM_ACCESS_TOKEN}" -o /usr/local/bin/docker-deploy 2>/dev/null; then
if sudo curl --fail -L "https://git.vdm.dev/api/v1/repos/octoleo/octojoom/raw/src/octojoom?ref=${branch:-master}" -o /usr/local/bin/octojoom 2>/dev/null; then
# give success message
echo "SUCCESS: Update was successful."
# do we have a backup
if [ -f /usr/local/bin/docker-deploy.bak ]; then
if [ -f /usr/local/bin/octojoom.bak ]; then
# lets remove it now
sudo rm -f /usr/local/bin/docker-deploy.bak
sudo rm -f /usr/local/bin/octojoom.bak
fi
else
# show the error
echo >&2 "ERROR: Update failed! Please try again later."
# do we have a backup
if [ -f /usr/local/bin/docker-deploy.bak ]; then
if [ -f /usr/local/bin/octojoom.bak ]; then
# move backup back
sudo mv /usr/local/bin/docker-deploy.bak /usr/local/bin/docker-deploy
sudo mv /usr/local/bin/octojoom.bak /usr/local/bin/octojoom
fi
fi
# always set the permission again if we have a file
if [ -f /usr/local/bin/docker-deploy ]; then
if [ -f /usr/local/bin/octojoom ]; then
# the we make sure its executable
sudo chmod +x /usr/local/bin/docker-deploy
sudo chmod +x /usr/local/bin/octojoom
fi
# always exit so the new script can load
exit 0
@ -1591,9 +1632,9 @@ function runUninstall() {
sudo rm -fr "${VDM_REPO_PATH}"
fi
elif (whiptail --yesno "Would you like to only remove the actual ${PROGRAM_NAME} v${_V} script but keep all the Docker stuff?" --title "Keep Docker Stuff" 8 112); then
# now remove the docker-deploy script
if [ -f /usr/local/bin/docker-deploy ]; then
sudo rm -f /usr/local/bin/docker-deploy
# now remove the octojoom script
if [ -f /usr/local/bin/octojoom ]; then
sudo rm -f /usr/local/bin/octojoom
fi
# give the final message
whiptail --title "${PROGRAM_NAME} v${_VERSION} is UNINSTALLED" --msgbox "\n\
@ -1677,9 +1718,9 @@ function runUninstall() {
sudo rm -fr "${VDM_SRC_PATH}"
fi
fi
# now remove the docker-deploy script
if [ -f /usr/local/bin/docker-deploy ]; then
sudo rm -f /usr/local/bin/docker-deploy
# now remove the octojoom script
if [ -f /usr/local/bin/octojoom ]; then
sudo rm -f /usr/local/bin/octojoom
fi
# last and final question as this is most dangerous and serious issue.
if [ -d "${VDM_PROJECT_PATH}" ] &&
@ -1695,10 +1736,10 @@ function runUninstall() {
}
# we show the octoleo info quietly
octoleoQuietly() {
octojoomQuietly() {
local message
# now set the message
message=" https://git.vdm.dev/octoleo/docker-deploy
message=" https://git.vdm.dev/octoleo/octojoom
Welcome to an Octoleo Program (${PROGRAM_NAME} v$_VERSION)
@ -1887,7 +1928,7 @@ function showTraefik() {
menu_options+=("delete" "Delete Traefik") && i=$((i + 1))
# get the selection
CHOICE=$(
whiptail --menu "Make your selection" 16 112 $i \
whiptail --menu "Make your selection" 20 112 $i \
--title "Traefik | ${PROGRAM_NAME} v${_V}" --fb \
--backtitle " Octoleo" --nocancel --notags \
"${menu_options[@]}" 3>&2 2>&1 1>&3
@ -1936,7 +1977,7 @@ function showPortainer() {
menu_options+=("delete" "Delete Portainer") && i=$((i + 1))
# get the selection
CHOICE=$(
whiptail --menu "Make your selection" 16 112 $i \
whiptail --menu "Make your selection" 20 112 $i \
--title "Portainer | ${PROGRAM_NAME} v${_V}" --fb \
--backtitle " Octoleo" --nocancel --notags \
"${menu_options[@]}" 3>&2 2>&1 1>&3
@ -1973,6 +2014,9 @@ function showHelpMenu() {
menu_options+=("command-help" "Help with commands")
# Show folder paths
menu_options+=("important-paths" "Important paths")
# Edit the global config
[ -f "${VDM_SRC_PATH}/.env" ] &&
menu_options+=("edit-config" "Edit Config") && i=$((i + 1))
# Report an Issue
menu_options+=("report-issue" "Report an issue")
# Update the whole script
@ -1980,10 +2024,10 @@ function showHelpMenu() {
# Uninstall the whole script
menu_options+=("uninstall" "Uninstall ${PROGRAM_NAME,,}")
# Octoleo details
menu_options+=("octoleo" "Octoleo")
menu_options+=("octojoom" "Octojoom")
# get the selection
CHOICE=$(
whiptail --menu "Make your selection" 16 112 $i \
whiptail --menu "Make your selection" 20 112 $i \
--title "Help Menu | ${PROGRAM_NAME} v${_V}" --fb \
--backtitle " Octoleo" --nocancel --notags \
"${menu_options[@]}" 3>&2 2>&1 1>&3
@ -1996,8 +2040,11 @@ function showHelpMenu() {
"important-paths")
showImportantPaths
;;
"edit-config")
editConfigFile
;;
"report-issue")
showLink "https://git.vdm.dev/octoleo/docker-deploy/issues" "To report an issue go to:" "Report an Issue"
showLink "https://git.vdm.dev/octoleo/octojoom/issues" "To report an issue go to:" "Report an Issue"
;;
"update")
runUpdate
@ -2005,8 +2052,8 @@ function showHelpMenu() {
"uninstall")
runUninstall
;;
"octoleo")
octoleoQuietly
"octojoom")
octojoomQuietly
;;
esac
}
@ -2020,14 +2067,18 @@ function domainsMenu() {
# load the back menu
menu_options+=("back" "<-- Return to the main menu.")
# add more domains
menu_options+=("add" "Add Domain")
allowMultiDomains &&
menu_options+=("add" "Add Domain") && i=$((i + 1))
# remove existing domains
[ -f "${VDM_SRC_PATH}/.domains" ] &&
menu_options+=("delete" "Delete Domain") && i=$((i + 1))
# edit available container
allowEditHostFile &&
menu_options+=("edit" "Edit Host File") && i=$((i + 1))
# get the selection
CHOICE=$(
whiptail --menu "Make your selection" 16 112 $i \
--title "Help Menu | ${PROGRAM_NAME} v${_V}" --fb \
whiptail --menu "Make your selection" 20 112 $i \
--title "Domains Menu | ${PROGRAM_NAME} v${_V}" --fb \
--backtitle " Octoleo" --nocancel --notags \
"${menu_options[@]}" 3>&2 2>&1 1>&3
)
@ -2039,6 +2090,9 @@ function domainsMenu() {
"delete")
deleteMultiDomains
;;
"edit")
editHostFile
;;
esac
}
@ -2047,7 +2101,7 @@ function mainMenu() {
# menu for dynamic addition
local menu_options=()
# our counter
local i=9
local i=6
# Joomla containers
menu_options+=("joomla" "Joomla Containers")
# Openssh containers
@ -2057,8 +2111,10 @@ function mainMenu() {
# Portainer container
menu_options+=("portainer" "Portainer Container")
# Manage Domains
allowMultiDomains &&
menu_options+=("domains" "Manage Domains") && i=$((i + 1))
if allowEditHostFile || allowMultiDomains; then
menu_options+=("domains" "Manage Domains")
i=$((i + 1))
fi
# Delete Persistent Volumes
hasDirectories '' "${VDM_PROJECT_PATH}" &&
menu_options+=("delete" "Delete Persistent Volumes") && i=$((i + 1))
@ -2107,17 +2163,17 @@ function mainMenu() {
# show error
function showError() {
whiptail --title "ERROR | ${PROGRAM_NAME} v${_V}" --msgbox "${1}" 12 112
whiptail --title "ERROR | ${PROGRAM_NAME} v${_V}" --msgbox "${1}" "${2:-12}" 112
}
# show info
function showInfo() {
whiptail --title "INFO | ${PROGRAM_NAME} v${_V}" --infobox "${1}" 12 112
whiptail --title "INFO | ${PROGRAM_NAME} v${_V}" --infobox "${1}" "${2:-12}" 112
}
# show notice
function showNotice() {
whiptail --title "NOTICE | ${PROGRAM_NAME} v${_V}" --msgbox "${1}" 12 112
whiptail --title "NOTICE | ${PROGRAM_NAME} v${_V}" --msgbox "${1}" "${2:-12}" 112
}
# show link
@ -2139,7 +2195,7 @@ function showImportantPaths() {
CONFIG: ${VDM_SRC_PATH}
Then we have some key environment variable files that hold very useful and important information.
Since we do not store any passwords or other important details in the docker-deploy.yml files
Since we do not store any passwords or other important details in the octojoom.yml files
they are stored in these environment variable files and its permissions are (600) for security.
JOOMLA: ${VDM_REPO_PATH}/joomla/.env
@ -2198,6 +2254,7 @@ function hasDirectories() {
function getRandomPass() {
# simple basic random
# shellcheck disable=SC2046
# shellcheck disable=SC2005
echo $(tr -dc 'A-HJ-NP-Za-km-z2-9' </dev/urandom | dd bs="${1:-128}" count=1 status=none)
}
@ -2296,38 +2353,6 @@ function getPassword() {
echo "${PASSWORD}"
}
# get and set the access token
function getAccessToken() {
# we try getting the token twice
local t=0
local new_token=false
# check that we have an access token, els ask for it
while [ ${#VDM_ACCESS_TOKEN} -le 30 ]; do
# this is a new token
new_token=true
# get the value
VDM_ACCESS_TOKEN=$(getInput "Enter access token for updates.\n[You can get an access token from https://git.vdm.dev/user/settings/applications]" \
'' 'Access Token')
# keep asking if empty
if [ ${#VDM_ACCESS_TOKEN} -le 30 ]; then
showError "Updates can only be done if you have an access token."
# increment our try
t=$((t + 1))
# when the user for the second time does not supply the correct value we return
if [ $t -eq 2 ]; then
return 12
fi
fi
done
# make the token available
export VDM_ACCESS_TOKEN
# store the token for next time
$new_token && setEnvVariable "VDM_ACCESS_TOKEN=\"${VDM_ACCESS_TOKEN}\"" &&
showNotice "The token has been stored in the environment variable file (${VDM_SRC_PATH}/.env)."
# we have success
return 0
}
# get the target branch to use in update
function getTargetBranch() {
# now make the selection
@ -2340,6 +2365,48 @@ function getTargetBranch() {
echo "${answer:-master}"
}
# get the target repository to use in update
function getImageSource() {
# we set some local stuff
local image
local image_source
local images_source
# menu for dynamic addition
local menu_options=()
# our counter
local i=2
# set the base images source
menu_options+=("joomla" "Joomla official image" "OFF")
menu_options+=("llewellyn/joomla" "Octoleo Joomla image" "OFF")
# get existing source
if [ -f "${VDM_SRC_PATH}/.images-source" ] && readarray -t images_source <"${VDM_SRC_PATH}/.images-source"; then
# build the menus
if [ "${#images_source[@]}" -gt 0 ]; then
# loop source images
for image in "${images_source[@]}"; do
# the image name (get before first comma)
image_name="${image%%,*}"
# the image description (get after last comma)
image_desc="${image##*,}"
# make sure we have a value, and it is not the defaults already set
if [ "${#image_name}" -ge 1 ] && [ "${#image_desc}" -ge 1 ] &&
[ "${image_name}" != 'joomla' ] && [ "${image_name}" != 'llewellyn/joomla' ]; then
# load the source name and description
menu_options+=("${image_name}" "${image_desc}" "OFF")
# increment our counter
i=$((i + 1))
fi
done
fi
fi
# now make the selection
image_source=$(whiptail --title "Select image source repository" --radiolist --nocancel --notags \
"You can select the source of your Joomla! image." 10 80 $i \
"${menu_options[@]}" 3>&1 1>&2 2>&3)
# return the answer (default joomla)
echo "${image_source:-joomla}"
}
# get a list of domains locally set
function getListDomains() {
# get the separator
@ -2354,9 +2421,10 @@ function getListDomains() {
# build the menu
for domain in "${domains[@]}"; do
# load the back menu
menu_options+=("${domain}")
[ "${#domain}" -ge 1 ] && menu_options+=("${domain}")
done
# we show a list of options including the option to add another
# shellcheck disable=SC2005
echo "$(printf "${separator}%s" "${menu_options[@]}")"
fi
fi
@ -2373,52 +2441,66 @@ function getMultiDomain() {
local i=0
# always add the main domain or (default) first
# so we should always have a selection
setMultiDomain "${VDM_DOMAIN:-${USER:-joomla}.vdm}"
saveMultiDomain "${VDM_DOMAIN}"
# now clear the main domain (in case we use getDomain)
unset VDM_DOMAIN
# get existing domains
if [ -f "${VDM_SRC_PATH}/.domains" ] && readarray -t domains <"${VDM_SRC_PATH}/.domains"; then
# build the menu
if [ "${#domains[@]}" -gt 0 ]; then
# loop domains
for domain in "${domains[@]}"; do
# load the back menu
menu_options+=("${domain}" "${domain}" "OFF")
# load the domain if it has a length
[ "${#domain}" -ge 1 ] && menu_options+=("${domain}" "${domain}" "OFF")
# increment our counter
i=$((i + 1))
[ "${#domain}" -ge 1 ] && i=$((i + 1))
done
# make sure we have domains
if [ "${#menu_options[@]}" -gt 0 ]; then
# we show a list of options including the option to add another
domain_name=$(whiptail --title "Select a Domain" --radiolist --nocancel --notags \
"Select a domain, or none to add another." 30 80 $i \
"${menu_options[@]}" 3>&1 1>&2 2>&3)
fi
fi
fi
# check if we have a selection
if [ "${domain_name:-none}" = 'none' ]; then
# we must let them enter the new domain name
domain_name=$(getDomain "Enter a domain name" "Enter a Domain Name")
getDomain 'Enter a domain name' 'Enter a Domain Name'
else
# set the new main domain
VDM_DOMAIN="${domain_name}"
# update the main domain
export VDM_DOMAIN
fi
# add for next time
setMultiDomain "${domain_name:-${USER:-joomla}.vdm}"
# update the main domain
echo "${domain_name:-${USER:-joomla}.vdm}"
saveMultiDomain "${VDM_DOMAIN}"
}
# set the VDM domain value
function getDomain() {
# set some locals
local message="Enter main domain name"
local title="Enter Main Domain"
local tld="${VDM_CONTAINER_TYPE:-vdm}"
# get the arg passed if any
message="${1:-$message}"
title="${2:-$title}"
# get the VDM Domain value if not already set
while [ ${#VDM_DOMAIN} -le 1 ] || [[ "${VDM_DOMAIN}" != *.* ]]; do
# get the value
VDM_DOMAIN=$(getInput "${1:-Enter main domain name.}\n[must have at least one dot]" \
"${3:-${USER:-joomla}.vdm}" "${2:-Enter Main Domain}")
VDM_DOMAIN=$(getInput "${message}\n[must have at least one dot]" \
"${USER:-octoleo}.${tld,,}" "${title}")
# keep asking if empty or does exist
if [ ${#VDM_DOMAIN} -le 1 ]; then
showError "${4:-You must enter a domain name!}"
showError "You must enter a domain name!"
elif [[ "${VDM_DOMAIN}" != *.* ]]; then
showError "${5:-You must enter a domain name with at least one dot!}"
showError "You must enter a domain name with at least one dot"
fi
done
# return what we found
echo "${VDM_DOMAIN}"
# update the main domain
export VDM_DOMAIN
}
# set the main domain
@ -2426,13 +2508,24 @@ function getMainDomain() {
# we first check if we have a main domain passed as command argument
if $VDM_ARG_DOMAIN; then
# if domain passed by arg we just return it
VDM_DOMAIN=$(getDomain "Enter a domain name" "Enter a Domain Name")
getDomain 'Enter a domain name' 'Enter a Domain Name'
else
# update the main domain with a selection
VDM_DOMAIN=$(getMultiDomain)
getMultiDomain
fi
# make sure it is available
export VDM_DOMAIN
}
# set the container user
function setContainerUser() {
# we first get the container user ID
VDM_PUID=$(getInput "Enter user ID for the ${VDM_CONTAINER_TYPE^} container.\n[add only a number]" \
"${1:-1000}" 'Enter Container User ID')
# we get the container user-group ID
VDM_PGID=$(getInput "Enter user-group ID for the ${VDM_CONTAINER_TYPE^} container.\n[add only a number]" \
"${1:-1000}" 'Enter Container User Group ID')
# make available
export VDM_PUID
export VDM_PGID
}
# set the domain
@ -2450,11 +2543,9 @@ function setDomain() {
# set the main domain
function setMainDomain() {
# set the main domain if not set
VDM_DOMAIN=$(getDomain)
getDomain
# add this value if not set variable
setEnvVariable "VDM_DOMAIN=\"${VDM_DOMAIN}\""
# make sure it is available
export VDM_DOMAIN
}
# set the sub domain
@ -2464,10 +2555,10 @@ function setSubDomain() {
while [ ${#VDM_SUBDOMAIN} -le 1 ] || [[ "${VDM_SUBDOMAIN}" =~ [^a-zA-Z] ]] ||
[ -d "${VDM_REPO_PATH}/${3:-$VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN}.${VDM_DOMAIN}" ] ||
[ -d "${VDM_REPO_PATH}/${3:-$VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN%db}.${VDM_DOMAIN}" ] ||
[ "${VDM_SUBDOMAIN}" = "${2:-}" ]; do
[ "${VDM_SUBDOMAIN}" = "${2}" ]; do
# get the value
VDM_SUBDOMAIN=$(getInput "Enter sub-domain used for this ${VDM_CONTAINER_TYPE^} container.\n[Text with no spaces that is only alphabetical]" \
"${1:-}" 'Enter Sub-Domain')
"${1}" 'Enter Sub-Domain')
# keep asking if empty or does exist
if [ ${#VDM_SUBDOMAIN} -ge 1 ] && [ -d "${VDM_REPO_PATH}/${3:-$VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN}.${VDM_DOMAIN}" ] ||
[ -d "${VDM_REPO_PATH}/${3:-$VDM_CONTAINER_TYPE}/available/${VDM_SUBDOMAIN%db}.${VDM_DOMAIN}" ]; then
@ -2500,12 +2591,9 @@ function setMultiDomains() {
# now clear the main domain each time
unset VDM_DOMAIN
# we must let them enter the new domain name
domain_name=$(getDomain "Enter a domain name" "Enter a Domain Name")
getDomain 'Enter a domain name' 'Enter a Domain Name'
# add for next time
setMultiDomain "${domain_name:-${USER:-joomla}.vdm}" || {
# return an error
return $?
}
saveMultiDomain "${VDM_DOMAIN}"
# get the list of domains
list_domains=$(getListDomains "\n")
# update the question
@ -2514,35 +2602,17 @@ function setMultiDomains() {
fi
}
# to set a global multiple domain file and values
function setMultiDomain() {
# check if the env file exist
if [ -f "${VDM_SRC_PATH}/.domains" ]; then
grep -q "${1}" "${VDM_SRC_PATH}/.domains" || echo "${1}" >>"${VDM_SRC_PATH}/.domains"
elif (whiptail --yesno "Can we create the ${VDM_SRC_PATH}/.domains file" --title "Multi Domain File" 8 112); then
# make sure the folder exist
mkdir -p "${VDM_SRC_PATH}"
# so we creat the file
echo "${1}" >"${VDM_SRC_PATH}/.domains"
# make sure the permissions are secured
chmod 600 "${VDM_SRC_PATH}/.domains"
else
showError "The ${VDM_SRC_PATH}/.domains file does not exist. So ${1} could not be added!"
# we return false
return 12
fi
# we return true
return 0
}
# set the multi domain switch
function setMultiDomainSwitch() {
# Allow multiple domains
if [ "${VDM_MULTI_DOMAIN:-not}" = 'not' ]; then
# explain the pros and cons...
showNotice "The down side to allowing multiple domains is that you will need to select a main domain each time you setup a new container. The advantage is that you can have multiple domains ;)"
showNotice "Next you should make the selection of using a single or multiple domain setup.\n\n\
With multiple domain setups you will need to select a main domain each time you setup a new container.\n\
With a single domain setup you setup the main domain once, and then only need setup the subdomains\n\
with each new container."
# check the security switch
if (whiptail --yesno "Would you like to allow for multiple domains?" --defaultno --title "Allow Multi Domains" 8 112); then
if (whiptail --yesno "Would you like to use a multiple domains setup?" --defaultno --title "Allow Multi Domains" 8 112); then
# we set the secure switch
VDM_MULTI_DOMAIN=true
else
@ -2615,7 +2685,7 @@ function setUpdateHostFile() {
function setSecureState() {
if [ "${VDM_SECURE:-not}" = 'not' ]; then
# check the security switch
if (whiptail --yesno "Would you like to use Letsencrypt auto setup for your containers [only for server with public static IP]" --defaultno --title "Letsencrypt" 8 112); then
if (whiptail --yesno "Would you like to use Letsencrypt auto setup for your containers [ONLY for server with public static IP]" --defaultno --title "Letsencrypt" 8 112); then
# we set the secure switch
VDM_SECURE=true
else
@ -2703,6 +2773,48 @@ function allowMultiDomains() {
return 12
}
# do we allow multiple domains
function allowEditHostFile() {
# check if we allow host file updates
setUpdateHostFile
# allow multi domain setup
if $VDM_UPDATE_HOST; then
# yes we do
return 0
fi
# now we don't
return 12
}
# to set a global multiple domain file and values
function saveMultiDomain() {
# set some locals
local domain_name
local src_path_domain
# set the domain and remove any whitespace
domain_name="$(echo -e "${1}" | tr -d '[:space:]')"
src_path_domain="${VDM_SRC_PATH}/.domains"
# check that we have a domain string
if [ ${#domain_name} -ge 1 ]; then
# check if the file exist
if [ -f "${src_path_domain}" ]; then
# check if its already set
if grep -L "${domain_name}" "${src_path_domain}"; then
echo "${domain_name}" >>"${src_path_domain}"
fi
else
# make sure the folder exist
mkdir -p "${VDM_SRC_PATH}"
# so we creat the file
echo "${domain_name}" >"${src_path_domain}"
# make sure the permissions are secured
chmod 600 "${src_path_domain}"
fi
fi
# we return true
return 0
}
# delete multiple domains
function deleteMultiDomains() {
# menu for dynamic addition
@ -2751,7 +2863,7 @@ function isFunc() {
# update the host file
function updateHostFile() {
# check if we should add to host file
if $VDM_UPDATE_HOST; then
if allowEditHostFile; then
# check if already in host file
if grep -q "${1:-$VDM_SUBDOMAIN}.${2:-$VDM_DOMAIN}" /etc/hosts; then
showNotice "${USER^}, ${1:-$VDM_SUBDOMAIN}.${2:-$VDM_DOMAIN} is already in the /etc/hosts file."
@ -2764,22 +2876,50 @@ function updateHostFile() {
fi
}
# the manually edit the host file
function editHostFile() {
# check if we should add to host file
if allowEditHostFile; then
# if this container is enabled ask if it should be redeployed
if (whiptail --yesno "To edit the host file we need sudo privileges.\n[Only continue if you know what your doing!]" --title "Give sudo Privileges" 15 112); then
# give little heads-up
showNotice "${USER^}, to save the changes you've made or to just close the file again press:\n\n[ctrl+x] with nano on ubuntu." 13
# lets open the file with nano for now
sudo "${EDITOR:-nano}" /etc/hosts
fi
fi
}
# the manually edit the config file
function editConfigFile() {
# check if the file exist
if [ -f "${VDM_SRC_PATH}/.env" ]; then
# give little warning for less command ready people
if (whiptail --yesno "Only continue if you know what your doing!\n\n\
${USER^}, to save the changes you've made or to just close the file again press:\n\n\
[ctrl+x] with nano on ubuntu." --title "Continue to edit ${PROGRAM_NAME} global config." 15 112); then
# all direct edit of the global config file
"${EDITOR:-nano}" "${VDM_SRC_PATH}/.env"
fi
fi
}
#####################################################################################################################VDM
######################################## CLI MENU ʕ•ᴥ•ʔ
# help message
function showHelp() {
cat <<EOF
Usage: ${0##*/:-} [OPTION...]
Usage: octojoom [OPTION...]
Options
======================================================
--type <type>
set type you would like to work with
example: ${0##*/:-} --type joomla
example: octojoom --type joomla
======================================================
--task <task>
set type of task you would like to perform
example: ${0##*/:-} --task setup
example: octojoom --task setup
======================================================
--container <container.domain.name>
Directly enabling or disabling a container with
@ -2787,74 +2927,74 @@ Usage: ${0##*/:-} [OPTION...]
The container must exist, which means it was
setup previously
Used without type and task Joomla-Enable is (default)
example: ${0##*/:-} --container "io.vdm.dev"
example: octojoom --container "io.vdm.dev"
======================================================
--update
to update your install
example: ${0##*/:-} --update
example: octojoom --update
======================================================
--access-token <token>
to update the program you will need an access token
from https://git.vdm.dev/user/settings/applications
example: docker-deploy --access-token xxxxxxxxxxx
example: octojoom --access-token xxxxxxxxxxx
======================================================
--uninstall
to uninstall this script
example: ${0##*/:-} --uninstall
example: octojoom --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"
example: octojoom -k="vdm"
example: octojoom --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"
example: octojoom -e="VDM"
example: octojoom --env-key="VDM"
======================================================
-d|--domain <domain.com>
set key website domain
!! must be domain.tld !!
example: ${0##*/:-} -d="joomla.org"
example: ${0##*/:-} --domain="joomla.org"
example: octojoom -d="joomla.org"
example: octojoom --domain="joomla.org"
======================================================
-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"
example: octojoom -s="jcb"
example: octojoom --sub-domain="jcb"
======================================================
AVAILABLE FOR JOOMLA CONTAINER
======================================================
-j|--joomla-version <version-tag>
see available tags here https://hub.docker.com/_/joomla
example: ${0##*/:-} -j=3.10
example: ${0##*/:-} --joomla-version=3.10
example: octojoom -j=3.10
example: octojoom --joomla-version=3.10
======================================================
AVAILABLE FOR OPENSSH CONTAINER
======================================================
-u|--username <username>
set username of the container
example: ${0##*/:-} -u="ubuntu"
example: ${0##*/:-} --username="ubuntu"
example: octojoom -u="ubuntu"
example: octojoom --username="ubuntu"
======================================================
--uid <id>
set container user id
example: ${0##*/:-} --uid=1000
example: octojoom --uid=1000
======================================================
--gid <id>
set container user group id
example: ${0##*/:-} --gid=1000
example: octojoom --gid=1000
======================================================
-p|--port <port>
set ssh port to use
!! do not use 22 !!
example: ${0##*/:-} -p=2239
example: ${0##*/:-} --port=2239
example: octojoom -p=2239
example: octojoom --port=2239
======================================================
--ssh-dir <dir>
set ssh directory name found in the .ssh dir
@ -2862,25 +3002,25 @@ Usage: ${0##*/:-} [OPTION...]
This directory has separate files for
each public key allowed to access
the container
example: ${0##*/:-} --ssh-dir="teamname"
example: octojoom --ssh-dir="teamname"
======================================================
--sudo
switch to add the container user to the
sudo group of the container
example: ${0##*/:-} --sudo
example: octojoom --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"
example: octojoom -t="Africa/Windhoek"
example: octojoom --time-zone="Africa/Windhoek"
======================================================
HELP ʕ•ᴥ•ʔ
======================================================
-h|--help
display this help menu
example: ${0##*/:-} -h
example: ${0##*/:-} --help
example: octojoom -h
example: octojoom --help
======================================================
${PROGRAM_NAME} v${_VERSION}
======================================================
@ -3201,7 +3341,7 @@ fi
#####################################################################################################################VDM
######################################## SETUP KEY PATHS
# the src folder path is where we store the script global env
VDM_SRC_PATH="/home/${USER}/.config/docker-deploy"
VDM_SRC_PATH="/home/${USER}/.config/octojoom"
# create the folder if not set
# shellcheck disable=SC2174
mkdir -p -m '700' "${VDM_SRC_PATH}"
@ -3210,8 +3350,6 @@ mkdir -p -m '700' "${VDM_SRC_PATH}"
[ -f "${VDM_SRC_PATH}/.env" ] && source "${VDM_SRC_PATH}/.env"
# get repo path where store the container deploy scripts
while [ ${#VDM_REPO_PATH} -le 1 ] || [ ! -d "${VDM_REPO_PATH}" ]; do
# we catch the token now.. so we don't need asking for it later
getAccessToken
# creat the path if it exist
if [ ${#VDM_REPO_PATH} -ge 1 ] && (whiptail --yesno "Can we create the ${VDM_REPO_PATH} repository folder" --title "Create the Path" 8 112); then
mkdir -p "${VDM_REPO_PATH}"