Skip to content

Commit

Permalink
Migrate install, ci and docker to yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 14, 2019
1 parent 3675a67 commit 6a7c1b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions .php_cs
Expand Up @@ -9,6 +9,7 @@ return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@PhpCsFixer' => true,
'strict_param' => false,
'array_syntax' => ['syntax' => 'short'],
'single_line_comment_style' => [
'comment_types' => [], // don't fix comment style
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -80,10 +80,10 @@ before_script:
- if [ "$DB" = "pgsql" ]; then USER=postgres; fi

# create config file
- sed -i "s/'pdo_mysql'/'pdo_$DB'/" etc/config.yaml
- sed -i "s/'vz'/'$USER'/" etc/config.yaml
- sed -i "s/'demo'/'$PASSWORD'/" etc/config.yaml
- sed -i "s/'volkszaehler'/'$DATABASE'/" etc/config.yaml
- sed -i "s/driver: .*/driver: pdo_$DB/" etc/config.yaml
- sed -i "s/user: .*/user: $USER/" etc/config.yaml
- sed -i "s/password: .*/password: $PASSWORD/" etc/config.yaml
- sed -i "s/dbname: .*/dbname: $DATABASE/" etc/config.yaml
- cat etc/config.yaml

# create database
Expand Down
35 changes: 20 additions & 15 deletions bin/install.sh
Expand Up @@ -34,7 +34,7 @@ shopt -s nocasematch
# some configuration

# minimum php version required
php_ver_min=7.0
php_ver_min=7.1

# git url
vz_git=https://github.com/volkszaehler/volkszaehler.org
Expand Down Expand Up @@ -75,20 +75,21 @@ get_db_name() {
test -n "$db_name" && return
ask "mysql database?" volkszaehler
db_name="$REPLY"
sed -i \
-e "s|^\/*\(\$config\['db'\]\['dbname'\]\).*|\1 = '$db_name';|" \
sed -i '' \
-e "/db:/,/admin:/ s/\(\s*\)dbname:.*/\1dbname: $db_name/" \
"$config"
}

get_db_admin_pass() {
test -n "$db_admin_user" && return
ask "mysql admin to $db_name database?" vz-admin
db_admin_user="$REPLY"
ask "mysql admin password?" secure
ask "mysql admin password?"
db_admin_pass="$REPLY"
sed -i \
-e "s/^\/*\(\$config\['db'\]\['admin'\]\['password'\]\).*/\1 = '$db_admin_pass';/" \
-e "s/^\/*\(\$config\['db'\]\['admin'\]\['user'\]\).*/\1 = '$db_admin_user';/" \
# note: use sed ranges to limit to admin section
sed -i '' \
-e "/admin:/,/push:/ s/\(\s*\)user:.*/\1user: $db_admin_user/" \
-e "/admin:/,/push:/ s/\(\s*\)password:.*/\1password: $db_admin_pass/" \
"$config"
}

Expand All @@ -98,10 +99,10 @@ get_db_user_pass() {
db_user="$REPLY"
ask "mysql password?" demo
db_pass="$REPLY"
# we are using "|" as delimiter for sed to avoid escaped sequences
sed -i \
-e "s|^\(\$config\['db'\]\['user'\]\).*|\1 = '$db_user';|" \
-e "s|^\/*\(\$config\['db'\]\['password'\]\).*|\1 = '$db_pass';|" \
# note: use sed ranges to limit to db section
sed -i '' \
-e "/db:/,/admin:/ s/\(\s*\)user:.*/\1user: $db_user/" \
-e "/db:/,/admin:/ s/\(\s*\)password:.*/\1password: $db_pass/" \
"$config"
}

Expand Down Expand Up @@ -145,7 +146,7 @@ fi
echo
echo "volkszaehler setup..."

if [ -e './etc/volkszaehler.conf.template.php' ]; then
if [ -e './etc/config.dist.yaml' ]; then
vz_dir="."

ask "volkszaehler.org already exists in the current directory. Update git repository?" y
Expand Down Expand Up @@ -204,7 +205,7 @@ else

fi

config="$vz_dir/etc/volkszaehler.conf.php"
config="$vz_dir/etc/config.yaml"

###############################
echo
Expand All @@ -231,14 +232,18 @@ echo
echo "installing dependencies..."

pushd "$vz_dir"
"$COMPOSER" install --no-dev
if [ -e "composer.lock" ]; then
"$COMPOSER" update
else
"$COMPOSER" install --no-dev
fi
popd

###############################
echo
if [ ! -e "$config" ]; then
echo "volkszaehler.org is not configured yet. creating new config from sample config file."
cp "$vz_dir/etc/volkszaehler.conf.template.php" "$config"
cp "$vz_dir/etc/config.dist.yaml" "$config"
REPLY=y
else
ask "configure volkszaehler.org database access?" y
Expand Down
2 changes: 1 addition & 1 deletion etc/config.dist.yaml
Expand Up @@ -17,7 +17,7 @@ db:

# db admin credentials (used by doctrine cli and setup script)
admin:
username: vz_admin
user: vz_admin
password: admin_demo

# database optimizer - leave empty for automatic
Expand Down

0 comments on commit 6a7c1b6

Please sign in to comment.