Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
docker-php-starterkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
docker-php-starterkit
Commits
c400722d
Commit
c400722d
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
hide unnecessary menu items (WIP)
parent
802bcb9e
No related branches found
No related tags found
1 merge request
!17
hide unnecessary menu items (WIP)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker/init.sh
+94
-58
94 additions, 58 deletions
docker/init.sh
with
94 additions
and
58 deletions
docker/init.sh
+
94
−
58
View file @
c400722d
...
...
@@ -20,6 +20,7 @@
# 2024-07-22 v1.13 <axel.hahn@unibe.ch> show info if there is no database container; speedup replacements
# 2024-07-22 v1.14 <axel.hahn@unibe.ch> show colored boxes with container status
# 2024-07-24 v1.15 <axel.hahn@unibe.ch> update menu output
# 2024-07-26 v1.16 <axel.hahn@unibe.ch> hide unnecessary menu items (WIP)
# ======================================================================
cd
"
$(
dirname
"
$0
"
)
"
||
exit
1
...
...
@@ -33,7 +34,7 @@ _self=$( basename "$0" )
# shellcheck source=/dev/null
.
"
${
_self
}
.cfg"
||
exit
1
_version
=
"1.1
5
"
_version
=
"1.1
6
"
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo
=
"docker-php-starterkit.git"
...
...
@@ -45,6 +46,15 @@ fgBrown="\e[33m"
fgBlue
=
"
\e
[34m"
fgReset
=
"
\e
[0m"
# ----- status varsiables
# running containers
DC_WEB_UP
=
0
DC_DB_UP
=
0
# repo of docker-php-starterkit is here?
DC_REPO
=
1
DC_CONFIG_CHANGED
=
0
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -64,26 +74,37 @@ function h3(){
# show help for param -h
function
showMenu
(){
cat
<<
EOM
_getStatus_repo
local
_spacer
=
" "
echo
if
[
$DC_REPO
-eq
1
]
;
then
echo
"
${
_spacer
}
$(
_key g
)
- remove git data of starterkit"
echo
fi
echo
"
${
_spacer
}
$(
_key i
)
- init application: set permissions"
echo
"
${
_spacer
}
$(
_key t
)
- generate files from templates"
echo
"
${
_spacer
}
$(
_key T
)
- remove generated files"
echo
""
if
[
$DC_WEB_UP
-eq
0
]
;
then
echo
"
${
_spacer
}
$(
_key u
)
- startup containers docker-compose ... up -d"
echo
"
${
_spacer
}
$(
_key U
)
- startup containers docker-compose ... up -d --build"
else
echo
"
${
_spacer
}
$(
_key s
)
- shutdown containers docker-compose stop"
echo
"
${
_spacer
}
$(
_key r
)
- remove containers docker-compose rm -f"
fi
echo
""
if
[
$DC_WEB_UP
-eq
1
]
;
then
echo
"
${
_spacer
}
$(
_key m
)
- more infos"
echo
"
${
_spacer
}
$(
_key o
)
- open app [
${
APP_NAME
}
]
$frontendurl
"
echo
"
${
_spacer
}
$(
_key c
)
- console (bash)"
echo
"
${
_spacer
}
$(
_key p
)
- console check with php linter"
echo
""
fi
echo
"
${
_spacer
}
$(
_key q
)
- quit"
$(
_key g
)
- remove git data of starterkit
$(
_key i
)
- init application: set permissions
$(
_key t
)
- generate files from templates
$(
_key T
)
- remove generated files
$(
_key u
)
- startup containers docker-compose ... up -d
$(
_key U
)
- startup containers docker-compose ... up -d --build
$(
_key s
)
- shutdown containers docker-compose stop
$(
_key r
)
- remove containers docker-compose rm -f
$(
_key m
)
- more infos
$(
_key o
)
- open app [
${
APP_NAME
}
]
$frontendurl
$(
_key c
)
- console (bash)
$(
_key p
)
- console check with php linter
$(
_key q
)
- quit
EOM
}
function
showHelp
(){
cat
<<
EOH
...
...
@@ -156,7 +177,7 @@ function _removeGitdata(){
h2
"Remove git data of starterkit"
echo
-n
"Current git remote url: "
git config
--get
remote.origin.url
if
git config
--get
remote.origin.url 2>/dev/null |
grep
$selfgitrepo
>
/dev/null
;
then
if
git config
--get
remote.origin.url 2>/dev/null |
grep
-q
$selfgitrepo
;
then
echo
echo
-n
"Delete local .git and .gitignore? [y/N] > "
read
-r
answer
...
...
@@ -278,9 +299,38 @@ function _removeGeneratedFiles(){
done
}
# get container status and set global variable DC_REPO
# DC_REPO = 0 nothing to do - repo was changed to project
# DC_REPO = 1 if repo is in selfgitrepo (must be deleted)
function
_getStatus_repo
(){
DC_REPO
=
0
git config
--get
remote.origin.url 2>/dev/null |
grep
-q
$selfgitrepo
&&
DC_REPO
=
1
}
# get container status and set global variables
# DC_WEB_UP - web container
# DC_DB_UP - database container
# 0 = down
# 1 = up
function
_getStatus_docker
(){
local
_out
_out
=
$(
docker-compose
-p
"
$APP_NAME
"
ps
)
DC_WEB_UP
=
0
DC_DB_UP
=
0
grep
-q
"
${
APP_NAME
}
-server"
<<<
"
$_out
"
&&
DC_WEB_UP
=
1
grep
-q
"
${
APP_NAME
}
-db"
<<<
"
$_out
"
&&
DC_DB_UP
=
1
}
# show running containers
function
_showContainers
(){
local
bLong
=
$1
_getStatus_docker
local
_out
local
sUp
=
".. UP"
...
...
@@ -288,56 +338,42 @@ function _showContainers(){
local
Status
=
local
StatusWeb
=
"
$sDown
"
local
StatusDb
=
""
local
StatusDb
=
"
$sDown
"
local
colWeb
=
local
colDb
=
colDb
=
"
$fgRed
"
colWeb
=
"
$fgRed
"
_out
=
$(
if
[
-z
"
$bLong
"
]
;
then
docker-compose
-p
"
$APP_NAME
"
ps
else
# docker ps | grep "$APP_NAME"
docker-compose
-p
"
$APP_NAME
"
ps
fi
)
h2 CONTAINERS
if
[
"
$(
wc
-l
<<<
"
$_out
"
)
"
-eq
1
]
;
then
if
[
"
$DB_ADD
"
=
"false"
]
;
then
colDb
=
"
$fgGray
"
Status
=
"The web container is not running. This app has no database container."
else
StatusDb
=
"down"
Status
=
"No container is running for <
$APP_NAME
>."
fi
else
grep
-q
"
${
APP_NAME
}
-server"
<<<
"
$_out
"
&&
colWeb
=
"
$fgGreen
"
grep
-q
"
${
APP_NAME
}
-server"
<<<
"
$_out
"
&&
StatusWeb
=
"
$sUp
"
grep
-q
"
${
APP_NAME
}
-db"
<<<
"
$_out
"
&&
colDb
=
"
$fgGreen
"
StatusDb
=
"
$sDown
"
grep
-q
"
${
APP_NAME
}
-db"
<<<
"
$_out
"
&&
StatusDb
=
"
$sUp
"
if
[
$DC_WEB_UP
-eq
1
]
;
then
colWeb
=
"
$fgGreen
"
StatusWeb
=
"
$sUp
"
fi
if
[
$DC_DB_UP
-eq
1
]
;
then
colDb
=
"
$fgGreen
"
StatusDb
=
"
$sUp
"
fi
if
[
"
$DB_ADD
"
=
"false"
]
;
then
colDb
=
"
$fgGray
"
StatusDb
=
""
Status
=
"INFO: This app has no database container."
fi
if
[
"
$DB_ADD
"
=
"false"
]
;
then
colDb
=
"
$fgGray
"
local
StatusDb
=
".. N/A"
Status
=
"This app has no database container."
fi
printf
"
$colWeb
__________________________
$colDb
__________________________
$fgReset
\n
"
printf
"
$colWeb
| %-22s |
$colDb
| %-22s |
$fgReset
\n
"
""
""
printf
"
$colWeb
| %-22s |
$colDb
| %-22s |
$fgReset
\n
"
"
${
APP_NAME
}
-web
${
StatusWeb
}
"
"
${
APP_NAME
}
-db
${
StatusDb
}
"
printf
"
$colWeb
| %-22s |
$colDb
| %-22s |
$fgReset
\n
"
" PHP
${
APP_PHP_VERSION
}
"
"
${
MYSQL_IMAGE
}
"
printf
"
$colWeb
| %-22s |
$colDb
| %-22s |
$fgReset
\n
"
" :
${
APP_PORT
}
"
" :
${
DB_PORT
}
"
printf
"
$colWeb
|__________________________|
$colDb
|__________________________|
$fgReset
\n
"
h2 CONTAINERS
printf
"
$colWeb
_____________________________
$colDb
_____________________________
$fgReset
\n
"
printf
"
$colWeb
| %-25s |
$colDb
| %-25s |
$fgReset
\n
"
""
""
printf
"
$colWeb
| %-25s |
$colDb
| %-25s |
$fgReset
\n
"
"
${
APP_NAME
}
-web
${
StatusWeb
}
"
"
${
APP_NAME
}
-db
${
StatusDb
}
"
printf
"
$colWeb
| %-25s |
$colDb
| %-25s |
$fgReset
\n
"
" PHP
${
APP_PHP_VERSION
}
"
"
${
MYSQL_IMAGE
}
"
printf
"
$colWeb
| %-25s |
$colDb
| %-25s |
$fgReset
\n
"
" :
${
APP_PORT
}
"
" :
${
DB_PORT
}
"
printf
"
$colWeb
|_____________________________|
$colDb
|_____________________________|
$fgReset
\n
"
echo
if
[
-n
"
$Status
"
]
;
then
echo
echo
"
$Status
"
echo
fi
echo
if
[
-n
"
$bLong
"
]
;
then
echo
"
$_out
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment