From a1f7c8fa39819476b09d350d2418e3978e997eab Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sun, 26 Dec 2021 16:26:36 +0200 Subject: [PATCH] Adds option to set container user ID when needed in both Joomla and Openssh containers. --- src/octojoom | 98 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/src/octojoom b/src/octojoom index 937a935..f077e9a 100755 --- a/src/octojoom +++ b/src/octojoom @@ -1,7 +1,7 @@ #!/bin/bash # The most recent program version. -_VERSION="3.0.0" +_VERSION="3.0.1" _V="3.0" # The program full name @@ -358,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 @@ -416,6 +426,8 @@ function joomla__TRuST__setup() { 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 @@ -427,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 <&1 1>&2 2>&3) - # return the answer (default joomla) - echo "${answer:-joomla}" + # 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 @@ -2462,6 +2515,19 @@ function getMainDomain() { 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 function setDomain() { # allow multi domain setup @@ -2726,8 +2792,8 @@ function saveMultiDomain() { 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"; + 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