Skip to content
Snippets Groups Projects

docker init script: added start of mysql in the database container

Merged Hahn Axel (hahn) requested to merge detect-rootless-docker into master
3 files
+ 35
3
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 28
3
@@ -27,6 +27,7 @@
@@ -27,6 +27,7 @@
# 2024-10-16 v1.20 <axel.hahn@unibe.ch> add db import and export
# 2024-10-16 v1.20 <axel.hahn@unibe.ch> add db import and export
# 2024-10-25 v1.21 <axel.hahn@unibe.ch> create missing subdir dbdumps
# 2024-10-25 v1.21 <axel.hahn@unibe.ch> create missing subdir dbdumps
# 2024-10-30 v1.22 <axel.hahn@unibe.ch> added: Open Mysql client in container
# 2024-10-30 v1.22 <axel.hahn@unibe.ch> added: Open Mysql client in container
 
# 2024-10-30 v1.23 <axel.hahn@unibe.ch> added: show menu hints why some menu items are visible
# ======================================================================
# ======================================================================
cd "$( dirname "$0" )" || exit 1
cd "$( dirname "$0" )" || exit 1
@@ -40,7 +41,7 @@ _self=$( basename "$0" )
@@ -40,7 +41,7 @@ _self=$( basename "$0" )
# shellcheck source=/dev/null
# shellcheck source=/dev/null
. "${_self}.cfg" || exit 1
. "${_self}.cfg" || exit 1
_version="1.22"
_version="1.23"
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo="docker-php-starterkit.git"
selfgitrepo="docker-php-starterkit.git"
@@ -67,6 +68,7 @@ DC_CONFIG_CHANGED=0
@@ -67,6 +68,7 @@ DC_CONFIG_CHANGED=0
DC_WEB_URL=""
DC_WEB_URL=""
DC_DUMP_DIR=dbdumps
DC_DUMP_DIR=dbdumps
 
DC_SHOW_MENUHINTS=0
isDockerRootless=0
isDockerRootless=0
ps -ef | grep dockerd-rootless | grep -q $USER && isDockerRootless=1
ps -ef | grep dockerd-rootless | grep -q $USER && isDockerRootless=1
@@ -142,6 +144,15 @@ function _key(){
@@ -142,6 +144,15 @@ function _key(){
echo -en "\e[4;7m ${1} \e[0m"
echo -en "\e[4;7m ${1} \e[0m"
}
}
 
# helper for menu: show hint text
 
# param int FLag _bAll (i true the txt will be hidden)
 
# param string message to show
 
function menuhint(){
 
local _bAll="$1"
 
shift 1
 
test $DC_SHOW_MENUHINTS -ne 0 && test "$_bAll" -eq "0" && ( echo -e "$fgBlue $*$fgReset" )
 
}
 
# show menu in interactive mode and list keys in help with param -h
# show menu in interactive mode and list keys in help with param -h
# param string optional: set to "all" to show all menu items
# param string optional: set to "all" to show all menu items
function showMenu(){
function showMenu(){
@@ -153,46 +164,60 @@ function showMenu(){
@@ -153,46 +164,60 @@ function showMenu(){
echo
echo
if [ $DC_REPO -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $DC_REPO -eq 1 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "Git data of starterkit were found"
echo "${_spacer}$( _key g ) - remove git data of starterkit"
echo "${_spacer}$( _key g ) - remove git data of starterkit"
echo
echo
fi
fi
if [ $isDockerRootless -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $isDockerRootless -eq 1 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "Beause rootless docker was found"
echo "${_spacer}$( _key i ) - init application: set permissions"
echo "${_spacer}$( _key i ) - init application: set permissions"
 
echo
fi
fi
if [ $DC_CONFIG_CHANGED -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $DC_CONFIG_CHANGED -eq 1 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "Config was changed"
echo "${_spacer}$( _key t ) - generate files from templates"
echo "${_spacer}$( _key t ) - generate files from templates"
 
echo
fi
fi
if [ $DC_CONFIG_CHANGED -eq 0 ] || [ $_bAll -eq 1 ]; then
if [ $DC_CONFIG_CHANGED -eq 0 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "Config is unchanged"
echo "${_spacer}$( _key T ) - remove generated files"
echo "${_spacer}$( _key T ) - remove generated files"
 
echo
fi
fi
echo
if [ $DC_WEB_UP -eq 0 ] || [ $DC_DB_UP -eq 0 ] || [ $_bAll -eq 1 ]; then
if [ $DC_WEB_UP -eq 0 ] || [ $DC_DB_UP -eq 0 ] || [ $_bAll -eq 1 ]; then
if [ $DC_CONFIG_CHANGED -eq 0 ] || [ $_bAll -eq 1 ]; then
if [ $DC_CONFIG_CHANGED -eq 0 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "A container is down and config is unchanged"
echo "${_spacer}$( _key u ) - startup containers docker-compose ... up -d"
echo "${_spacer}$( _key u ) - startup containers docker-compose ... up -d"
echo "${_spacer}$( _key U ) - startup containers docker-compose ... up -d --build"
echo "${_spacer}$( _key U ) - startup containers docker-compose ... up -d --build"
echo
echo
echo "${_spacer}$( _key r ) - remove containers docker-compose rm -f"
echo "${_spacer}$( _key r ) - remove containers docker-compose rm -f"
 
echo
fi
fi
fi
fi
if [ $DC_WEB_UP -eq 1 ] || [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $DC_WEB_UP -eq 1 ] || [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "${_spacer}A container is up"
echo "${_spacer}$( _key s ) - shutdown containers docker-compose stop"
echo "${_spacer}$( _key s ) - shutdown containers docker-compose stop"
echo
echo
echo "${_spacer}$( _key m ) - more infos"
echo "${_spacer}$( _key m ) - more infos"
echo "${_spacer}$( _key o ) - open app [${APP_NAME}] $DC_WEB_URL"
echo "${_spacer}$( _key o ) - open app [${APP_NAME}] $DC_WEB_URL"
echo "${_spacer}$( _key c ) - console (bash)"
echo "${_spacer}$( _key c ) - console (bash)"
 
echo
fi
fi
if [ $DC_WEB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $DC_WEB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
 
menuhint $_bAll "Web container is up"
echo "${_spacer}$( _key p ) - console check with php linter"
echo "${_spacer}$( _key p ) - console check with php linter"
 
echo
fi
fi
if [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
if [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
echo
echo
 
menuhint $_bAll "Database container is up"
echo "${_spacer}$( _key d ) - Dump container database"
echo "${_spacer}$( _key d ) - Dump container database"
echo "${_spacer}$( _key D ) - Import Dump into container database"
echo "${_spacer}$( _key D ) - Import Dump into container database"
echo "${_spacer}$( _key M ) - Open Mysql client in database container"
echo "${_spacer}$( _key M ) - Open Mysql client in database container"
 
echo
fi
fi
echo
menuhint $_bAll "Always available"
echo "${_spacer}$( _key q ) - quit"
echo "${_spacer}$( _key q ) - quit"
}
}
Loading