Adds option to set container user ID when needed in both Joomla and Openssh containers.

This commit is contained in:
Llewellyn van der Merwe 2021-12-26 16:26:36 +02:00
parent e4a4714b0a
commit a1f7c8fa39
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
1 changed files with 82 additions and 16 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# The most recent program version. # The most recent program version.
_VERSION="3.0.0" _VERSION="3.0.1"
_V="3.0" _V="3.0"
# The program full name # The program full name
@ -358,6 +358,16 @@ function joomla__TRuST__setup() {
} }
# add the projects path # add the projects path
setContainerEnvVariable "VDM_PROJECT_PATH=\"${VDM_PROJECT_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 # add this value if not set variable
[ ${#vdm_database_name} -ge 1 ] && setContainerEnvVariable "VDM_${VDM_ENV_KEY^^}_DB=\"${vdm_database_name}\"" [ ${#vdm_database_name} -ge 1 ] && setContainerEnvVariable "VDM_${VDM_ENV_KEY^^}_DB=\"${vdm_database_name}\""
# add this value if not set variable # add this value if not set variable
@ -416,6 +426,8 @@ function joomla__TRuST__setup() {
unset VDM_REMOVE_SECURE unset VDM_REMOVE_SECURE
unset VDM_ENTRY_POINT unset VDM_ENTRY_POINT
unset VDM_HTTP_SCHEME unset VDM_HTTP_SCHEME
unset VDM_PUID
unset VDM_PGID
# container lower # container lower
unset vdm_database_name unset vdm_database_name
unset vdm_database_user unset vdm_database_user
@ -427,6 +439,13 @@ function joomla__TRuST__setup() {
# return the Joomla Container setup yml # return the Joomla Container setup yml
function joomlaContainer() { 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 # we build the yml file
cat <<EOF cat <<EOF
version: '2' version: '2'
@ -448,7 +467,7 @@ services:
image: ${VDM_J_REPO}:${VDM_JV} image: ${VDM_J_REPO}:${VDM_JV}
container_name: joomla_${VDM_KEY} container_name: joomla_${VDM_KEY}
restart: unless-stopped restart: unless-stopped
environment: environment:${vdm_container_user}
- JOOMLA_DB_HOST=mariadb_${VDM_KEY}:3306 - JOOMLA_DB_HOST=mariadb_${VDM_KEY}:3306
- JOOMLA_DB_NAME=\${VDM_${VDM_ENV_KEY^^}_DB} - JOOMLA_DB_NAME=\${VDM_${VDM_ENV_KEY^^}_DB}
- JOOMLA_DB_USER=\${VDM_${VDM_ENV_KEY^^}_DB_USER} - JOOMLA_DB_USER=\${VDM_${VDM_ENV_KEY^^}_DB_USER}
@ -523,6 +542,8 @@ function openssh__TRuST__setup() {
showError "You must enter a username for the container" showError "You must enter a username for the container"
fi fi
done done
# be sure to set the container USER ID
setContainerUser 33
# get the key if not set # get the key if not set
setUniqueKey "Enter key used for container naming." setUniqueKey "Enter key used for container naming."
# get the env key if not set # get the env key if not set
@ -668,6 +689,8 @@ function openssh__TRuST__setup() {
# container # container
unset VDM_PORT unset VDM_PORT
unset VDM_USER_NAME unset VDM_USER_NAME
unset VDM_PUID
unset VDM_PGID
unset VDM_KEY unset VDM_KEY
unset VDM_ENV_KEY unset VDM_ENV_KEY
unset VDM_PUBLIC_KEY_GLOBAL_DIR unset VDM_PUBLIC_KEY_GLOBAL_DIR
@ -692,8 +715,8 @@ services:
restart: unless-stopped restart: unless-stopped
hostname: ${VDM_DOMAIN:-vdm.dev} hostname: ${VDM_DOMAIN:-vdm.dev}
environment: environment:
- PUID=${VDM_PUID:-33} - PUID=${VDM_PUID}
- PGID=${VDM_PGID:-33} - PGID=${VDM_PGID}
- TZ=${VDM_TZ:-Africa/Windhoek} - TZ=${VDM_TZ:-Africa/Windhoek}
- PUBLIC_KEY_DIR=/config/ssh_public_keys - PUBLIC_KEY_DIR=/config/ssh_public_keys
- SUDO_ACCESS=${VDM_SUDO_ACCESS:-false} - SUDO_ACCESS=${VDM_SUDO_ACCESS:-false}
@ -731,7 +754,7 @@ function joomla__TRuST__edit() {
# check if this docker-composer.yml exist # check if this docker-composer.yml exist
if [ -f "${vdm_edit_me}" ]; then if [ -f "${vdm_edit_me}" ]; then
# give little heads-up # 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 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 # lets open the file with nano for now
"${EDITOR:-nano}" "${vdm_edit_me}" "${EDITOR:-nano}" "${vdm_edit_me}"
# if this container is enabled ask if it should be redeployed # if this container is enabled ask if it should be redeployed
@ -767,7 +790,7 @@ function openssh__TRuST__edit() {
# check if this docker-composer.yml exist # check if this docker-composer.yml exist
if [ -f "${vdm_edit_me}" ]; then if [ -f "${vdm_edit_me}" ]; then
# give little heads-up # 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 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 # lets open the file with nano for now
"${EDITOR:-nano}" "${vdm_edit_me}" "${EDITOR:-nano}" "${vdm_edit_me}"
# if this container is enabled ask if it should be redeployed # if this container is enabled ask if it should be redeployed
@ -2344,14 +2367,44 @@ function getTargetBranch() {
# get the target repository to use in update # get the target repository to use in update
function getImageSource() { function getImageSource() {
# now make the selection # we set some local stuff
answer=$(whiptail --title "Select image repository" --radiolist --nocancel --notags \ local image
"You can select the source of your Joomla! image." 10 80 2 \ local image_source
"joomla" "Joomla official image" "OFF" \ local images_source
"llewellyn/joomla" "Octoleo Joomla image" "OFF" \ # menu for dynamic addition
3>&1 1>&2 2>&3) local menu_options=()
# return the answer (default joomla) # our counter
echo "${answer:-joomla}" 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 # get a list of domains locally set
@ -2462,6 +2515,19 @@ function getMainDomain() {
fi fi
} }
# 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 # set the domain
function setDomain() { function setDomain() {
# allow multi domain setup # allow multi domain setup
@ -2726,8 +2792,8 @@ function saveMultiDomain() {
local domain_name local domain_name
local src_path_domain local src_path_domain
# set the domain and remove any whitespace # set the domain and remove any whitespace
domain_name="$(echo -e "${1}" | tr -d '[:space:]')"; domain_name="$(echo -e "${1}" | tr -d '[:space:]')"
src_path_domain="${VDM_SRC_PATH}/.domains"; src_path_domain="${VDM_SRC_PATH}/.domains"
# check that we have a domain string # check that we have a domain string
if [ ${#domain_name} -ge 1 ]; then if [ ${#domain_name} -ge 1 ]; then
# check if the file exist # check if the file exist