diff --git a/docker/init.sh b/docker/init.sh index 994a4d09a47ce1ac5609deed9b5edf23b68791e4..961b4d96595629c909f1ad7e9c2eb7276b555bad 100755 --- a/docker/init.sh +++ b/docker/init.sh @@ -4,16 +4,17 @@ # DOCKER PHP DEV ENVIRONMENT :: INIT # # ---------------------------------------------------------------------- -# 2021-11-nn v1.0 <axel.hahn@iml.unibe.ch> -# 2022-07-19 v1.1 <axel.hahn@iml.unibe.ch> support multiple dirs for setfacl -# 2022-11-16 v1.2 <www.axel-hahn.de> use docker-compose -p "$APP_NAME" -# 2022-12-18 v1.3 <www.axel-hahn.de> add -p "$APP_NAME" in other docker commands -# 2022-12-20 v1.4 <axel.hahn@unibe.ch> replace fgrep with grep -F -# 2023-03-06 v1.5 <www.axel-hahn.de> up with and without --build -# 2023-08-17 v1.6 <www.axel-hahn.de> menu selection with single key (without return) -# 2023-11-10 v1.7 <axel.hahn@unibe.ch> replace docker-compose with "docker compose" -# 2023-11-13 v1.8 <axel.hahn@unibe.ch> UNDO "docker compose"; update infos -# 2023-11-15 v1.9 <axel.hahn@unibe.ch> add help; execute multiple actions by params; new menu item: open app +# 2021-11-nn v1.0 <axel.hahn@iml.unibe.ch> +# 2022-07-19 v1.1 <axel.hahn@iml.unibe.ch> support multiple dirs for setfacl +# 2022-11-16 v1.2 <www.axel-hahn.de> use docker-compose -p "$APP_NAME" +# 2022-12-18 v1.3 <www.axel-hahn.de> add -p "$APP_NAME" in other docker commands +# 2022-12-20 v1.4 <axel.hahn@unibe.ch> replace fgrep with grep -F +# 2023-03-06 v1.5 <www.axel-hahn.de> up with and without --build +# 2023-08-17 v1.6 <www.axel-hahn.de> menu selection with single key (without return) +# 2023-11-10 v1.7 <axel.hahn@unibe.ch> replace docker-compose with "docker compose" +# 2023-11-13 v1.8 <axel.hahn@unibe.ch> UNDO "docker compose"; update infos +# 2023-11-15 v1.9 <axel.hahn@unibe.ch> add help; execute multiple actions by params; new menu item: open app +# 2023-12-07 v1.10 <www.axel-hahn.de> simplyfy console command; add php linter # ====================================================================== cd $( dirname $0 ) @@ -22,7 +23,7 @@ cd $( dirname $0 ) # git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git selfgitrepo="docker-php-starterkit.git" -_version="1.9" +_version="1.10" # ---------------------------------------------------------------------- # FUNCTIONS @@ -56,6 +57,7 @@ function showMenu(){ echo " $( _key m ) - more infos" echo " $( _key o ) - open app [${APP_NAME}] $frontendurl" echo " $( _key c ) - console (bash)" + echo " $( _key p ) - console check with php linter" echo echo " $( _key q ) - quit" } @@ -92,6 +94,7 @@ EXAMPLES: $_self starts interactive mode $_self u bring up docker container(s) and stay in interactive mode $_self i q set write permissions and quit + $_self p q start php linter and exit EOH } @@ -304,7 +307,8 @@ function _key(){ # helper: wait for a return key function _wait(){ - echo -n "... press RETURN > "; read -r -t 15 + local _wait=15 + echo -n "... press RETURN ... or wait $_wait sec > "; read -r -t $_wait } # ---------------------------------------------------------------------- @@ -378,10 +382,40 @@ while true; do ;; c) h2 "Console" - docker ps - echo -n "id or name >" - read dockerid - test -z "$dockerid" || docker exec -it $dockerid /bin/bash + _containers=$( docker-compose -p "$APP_NAME" ps | sed -n "2,\$p" | awk '{ print $1}' ) + if [ "$DB_ADD" = "false" ]; then + dockerid=$_containers + else + echo "Select a container:" + echo "$_containers" | sed "s#^# #g" + echo -n "id or name >" + read dockerid + fi + test -z "$dockerid" || ( + echo + echo "> docker exec -it $dockerid /bin/bash (type 'exit' + Return when finished)" + docker exec -it $dockerid /bin/bash + ) + ;; + p) + h2 "PHP $APP_PHP_VERSION linter" + + dockerid="${APP_NAME}-server" + echo -n "Scanning ... " + _iFiles=$( docker exec -it $dockerid /bin/bash -c "find . -name '*.php' " | wc -l ) + + if [ $_iFiles -gt 0 ]; then + echo "found $_iFiles [*.php] files ... errors from PHP $APP_PHP_VERSION linter:" + time if echo $APP_PHP_VERSION | grep -E "([567]\.|8\.[012])" >/dev/null ; then + docker exec -it $dockerid /bin/bash -c "find . -name '*.php' -exec php -l {} \; | grep -v '^No syntax errors detected'" + else + docker exec -it $dockerid /bin/bash -c "php -l \$( find . -name '*.php' ) | grep -v '^No syntax errors detected' " + fi + echo + _wait + else + echo "Start your docker container first." + fi ;; o) h2 "Open app ..."