Skip to content
Snippets Groups Projects
Commit 48fe2861 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'shellfixes' into 'master'

show info if there is no database container; speedup replacements

See merge request !12
parents 9fce1e5b 224c2d7f
No related branches found
No related tags found
1 merge request!12show info if there is no database container; speedup replacements
......@@ -17,6 +17,7 @@
# 2023-12-07 v1.10 <www.axel-hahn.de> simplyfy console command; add php linter
# 2024-07-01 v1.11 <www.axel-hahn.de> diff with colored output; suppress errors on port check
# 2024-07-19 v1.12 <axel.hahn@unibe.ch> apply shell fixes
# 2024-07-22 v1.13 <axel.hahn@unibe.ch> show info if there is no database container; speedup replacements
# ======================================================================
cd "$( dirname "$0" )" || exit 1
......@@ -33,7 +34,7 @@ _self=$( basename "$0" )
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo="docker-php-starterkit.git"
_version="1.12"
_version="1.13"
# ----------------------------------------------------------------------
# FUNCTIONS
......@@ -169,6 +170,23 @@ function _fix_no-db(){
fi
}
# helper functiion to generate replacements using sed
# it loops over all vars in the config file
# used in _generateFiles
function _getreplaces(){
# loop over vars to make the replacement
grep "^[a-zA-Z]" "$_self.cfg" | while read -r line
do
# echo replacement: $line
mykey=$( echo "$line" | cut -f 1 -d '=' )
myvalue="$( eval echo \"\$"$mykey"\" )"
# TODO: multiline values fail here in replacement with sed
echo -e "s#{{$mykey}}#${myvalue}#g"
done
}
# loop over all files in templates subdir make replacements and generate
# a target file.
# It skips if
......@@ -176,14 +194,14 @@ function _fix_no-db(){
# - target file has no updated lines
function _generateFiles(){
# re-read config vars
# shellcheck source=/dev/null
. "${_self}.cfg" || exit 1
params=$( _getreplaces | while read -r line; do echo -n "-e '$line' "; done )
local _tmpfile=/tmp/newfilecontent$$.tmp
h2 "generate files from templates..."
for mytpl in templates/*
time for mytpl in templates/*
do
# h3 $mytpl
local _doReplace=1
......@@ -207,19 +225,7 @@ function _generateFiles(){
local _md5; _md5=$( md5sum $_tmpfile | awk '{ print $1 }' )
sed -i "s#{{generator}}#GENERATED BY $_self - template: $mytpl - $_md5#g" $_tmpfile
# loop over vars to make the replacement
grep "^[a-zA-Z]" "$_self.cfg" | while read -r line
do
# echo replacement: $line
mykey=$( echo "$line" | cut -f 1 -d '=' )
myvalue="$( eval echo \"\$"$mykey"\" )"
if grep "{{$mykey}}" $_tmpfile >/dev/null; then
# TODO: multiline values fail here in replacement with sed
sed -i -e "s#{{$mykey}}#${myvalue}#g" $_tmpfile
fi
done
eval sed -i "$params" "$_tmpfile" || exit
_fix_no-db $_tmpfile
......@@ -229,12 +235,12 @@ function _generateFiles(){
mkdir -p "$( dirname ../"$target" )" || exit 2
mv "$_tmpfile" "../$target" || exit 2
echo OK
echo
else
rm -f $_tmpfile
echo "SKIP: $mytpl - Nothing to do."
fi
fi
echo
done
}
......@@ -265,12 +271,26 @@ function _removeGeneratedFiles(){
# show running containers
function _showContainers(){
local bLong=$1
local _out
h2 CONTAINERS
if [ -z "$bLong" ]; then
_out=$( if [ -z "$bLong" ]; then
docker-compose -p "$APP_NAME" ps
else
docker ps | grep "$APP_NAME"
fi)
if [ "$( wc -l <<< "$_out" )" -eq 1 ]; then
if [ "$DB_ADD" = "false" ]; then
echo "The web container is <$APP_NAME> is not running. This app has no database container."
else
echo "No container is running for <$APP_NAME>."
fi
else
echo "$_out"
if [ "$DB_ADD" = "false" ]; then
echo "INFO: This app has no database container."
fi
fi
}
......@@ -340,7 +360,7 @@ while true; do
if [ -z "$action" ]; then
echo
echo -e "\e[32m===== INITIALIZER FOR DOCKER APP [$APP_NAME] v$_version ===== \e[0m\n\r"
echo -e "\e[32m----===###| INITIALIZER FOR DOCKER v$_version | $APP_NAME |###===---\e[0m"
_showContainers
......
# What problem does it solve?
## What problem does it solve?
I have a few php based projects with or without a database.
......@@ -15,6 +15,6 @@ The init script:
* opens a console
* starts php lint
# What problems does it not solve?
## What problems does it not solve?
It is a script for a dual container and Apache + PHP and (optional) Mariadb only for a local LAMP dev environment. Nothing else.
## Requirements ##
## Requirements
It was tested on Linux only.
......
## How to use this template ##
## How to use this template
### Create a new project folder ###
### Create a new project folder
Copy downloaded and extracted folder to a new name:
......@@ -41,7 +41,7 @@ The initial file structure looks like this:
└── readme.md
```
### Edit variables and files ###
### Edit variables and files
* edit ```./docker/init.sh.cfg``` ... and edit
* ```APP_NAME=my_new_app```
......@@ -53,7 +53,7 @@ The initial file structure looks like this:
* edit php settings in ```./docker/templates/extra-php.ini```
* edit mysql settings in ```./docker/templates/my.cnf```
### First start ###
### First start
* start init script in the docker folder: ```./docker/init.sh```
* use `g` to remove git data of the starterkit
......@@ -61,13 +61,13 @@ The initial file structure looks like this:
* use `t` to generate config files from templates with the settings from ./docker/init.sh.cfg
* use `u` to bring up the container (OR run ```docker-compose up -d``` )
### Edit files ###
### Edit files
* If the container was started you can ...
* open in your browser http://localhost:8001 to access ```./public_html/```
* edit files with the IDE of your choice
### Remarks ###
### Remarks
You can start ./docker/init.sh with a single letter in the interactive menu too, i.e. ```./docker/init.sh u``` to bring up the docker instance.
......
docs/images/main_menu.png

189 KiB | W: | H:

docs/images/main_menu.png

325 KiB | W: | H:

docs/images/main_menu.png
docs/images/main_menu.png
docs/images/main_menu.png
docs/images/main_menu.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment