diff --git a/profiles/templates/taiga/taiga/config.taiga b/profiles/templates/taiga/taiga/config.taiga deleted file mode 100644 index 33531c3..0000000 --- a/profiles/templates/taiga/taiga/config.taiga +++ /dev/null @@ -1,15 +0,0 @@ -# Calculate path=/var/calculate/config name=#-cut(1,.)-# chmod=600 chown=taiga:taiga comment=# grep(/var/calculate/config/#-cut(1,.)-#,PROTOCOL)== protected -PROTOCOL='http' -TAIGA_SITES_DOMAIN='taiga.example.org' -FROM_EMAIL='taiga@example.org' -SMTP_HOST='smtp.example.org' -SMTP_PORT=25 -SMTP_TLS='False' -SMTP_SSL='False' -SMTP_USER= -SMTP_PASSWORD= -NODE='12.22.12' -SECRET_KEY='#-rnd(pas,16)-#' -PGSQL_PASSWORD='#-rnd(pas,16)-#' -RABBITMQ_USER='taiga' -RABBITMQ_PASSWORD='#-rnd(pas,16)-#' diff --git a/profiles/templates/taiga/taiga/ini.env b/profiles/templates/taiga/taiga/ini.env new file mode 100644 index 0000000..7fd346d --- /dev/null +++ b/profiles/templates/taiga/taiga/ini.env @@ -0,0 +1,19 @@ +# Calculate path=/var/calculate chmod=600 chown=taiga:taiga comment=# grep(/var/calculate/ini.env,taiga)== protected append=before +[taiga] +protocol = http +taiga_sites_domain = taiga.example.org +from_email = taiga@example.org +smtp_host = smtp.example.org +smtp_port = 25 +smtp_tls = False +smtp_ssl = False +smtp_user = +smtp_password = +language = #-os_locale_language-# +timezone = #-os_clock_timezone-# +public_register = True +node = 12.22.12 +secret_key = #-rnd(pas,16)-# +pgsql_password = #-rnd(pas,16)-# +rabbitmq_user = taiga +rabbitmq_password = #-rnd(pas,16)-# diff --git a/profiles/templates/taiga/taiga/sh.cl-setup b/profiles/templates/taiga/taiga/sh.cl-setup new file mode 100644 index 0000000..2f865a8 --- /dev/null +++ b/profiles/templates/taiga/taiga/sh.cl-setup @@ -0,0 +1,10 @@ +# Calculate path=/var/calculate/bin name=#-cut(1,.)-# chmod=755 comment=# +#!/bin/bash +set -eo pipefail +export PATH="/lib/rc/bin:$PATH" + +su - taiga -c /var/calculate/bin/install-taiga + +/var/calculate/bin/setup-taiga + +/var/calculate/bin/setup-rabbit diff --git a/profiles/templates/taiga/taiga/sh.install-taiga b/profiles/templates/taiga/taiga/sh.install-taiga index 352af9a..b45f98b 100644 --- a/profiles/templates/taiga/taiga/sh.install-taiga +++ b/profiles/templates/taiga/taiga/sh.install-taiga @@ -9,14 +9,30 @@ then exec su - taiga -c /var/calculate/bin/install-taiga fi -source /var/calculate/config/taiga + +all= +while IFS= read -r line +do + if [[ $line == *"["* ]] + then + line=${line#*[} + line=${line%%]*} + sec=$line + continue + fi + com=${sec}_${line// =/=}; + com=${com//= /=}; + all="$com; $all" +done < /var/calculate/ini.env +eval $all + if [[ ! -e ~/.node-live ]] then - einfo Установка Node.js + einfo 'Установка Node.js' cd ~ - nodeenv --node=$NODE .node-${NODE%%.*} - ln -sfT .node-${NODE%%.*} .node-live + nodeenv --node=$taiga_node .node-${taiga_node%%.*} + ln -sfT .node-${taiga_node%%.*} .node-live fi source ~/.node-live/bin/activate diff --git a/profiles/templates/taiga/taiga/sh.setup-postgresql b/profiles/templates/taiga/taiga/sh.setup-postgresql index 9c21092..6964665 100644 --- a/profiles/templates/taiga/taiga/sh.setup-postgresql +++ b/profiles/templates/taiga/taiga/sh.setup-postgresql @@ -1,9 +1,23 @@ # Calculate path=/var/calculate/bin name=#-cut(1,.)-# chmod=755 comment=# #!/bin/bash - set -ueo pipefail export PATH="/lib/rc/bin:$PATH" -source /var/calculate/config/taiga + +all= +while IFS= read -r line +do + if [[ $line == *"["* ]] + then + line=${line#*[} + line=${line%%]*} + sec=$line + continue + fi + com=${sec}_${line// =/=}; + com=${com//= /=}; + all="$com; $all" +done < /var/calculate/ini.env +eval $all ebegin 'Проверка выполненной базовой настройки' if [[ ! -e /var/lib/postgresql/12 ]] @@ -23,7 +37,7 @@ eend ebegin 'Проверка наличия роли taiga' $(psql -U taiga -d taiga -c '\dt' 2&>/dev/null) || { - echo Пароль: $PGSQL_PASSWORD + echo Пароль: $taiga_pgsql_password createuser -U postgres -P taiga createdb -U postgres -O taiga taiga } diff --git a/profiles/templates/taiga/taiga/sh.setup-rabbit b/profiles/templates/taiga/taiga/sh.setup-rabbit index 91c6697..ae8448b 100644 --- a/profiles/templates/taiga/taiga/sh.setup-rabbit +++ b/profiles/templates/taiga/taiga/sh.setup-rabbit @@ -2,16 +2,31 @@ #!/bin/bash set -ueo pipefail export PATH="/lib/rc/bin:$PATH" -source /var/calculate/config/taiga + +all= +while IFS= read -r line +do + if [[ $line == *"["* ]] + then + line=${line#*[} + line=${line%%]*} + sec=$line + continue + fi + com=${sec}_${line// =/=}; + com=${com//= /=}; + all="$com; $all" +done < /var/calculate/ini.env +eval $all rabbit_configure(){ if [[ ! -e /var/lib/rabbitmq/mnesia ]] then /etc/init.d/rabbitmq start - rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD + rabbitmqctl add_user $taiga_rabbitmq_user $taiga_rabbitmq_password rabbitmqctl add_vhost taiga - rabbitmqctl set_permissions -p taiga $RABBITMQ_USER ".*" ".*" ".*" + rabbitmqctl set_permissions -p taiga $taiga_rabbitmq_user ".*" ".*" ".*" fi } diff --git a/profiles/templates/taiga/taiga/sh.setup-taiga b/profiles/templates/taiga/taiga/sh.setup-taiga index 2938ae1..728bd5b 100644 --- a/profiles/templates/taiga/taiga/sh.setup-taiga +++ b/profiles/templates/taiga/taiga/sh.setup-taiga @@ -3,52 +3,43 @@ export PATH="/lib/rc/bin:$PATH" set -ueo pipefail -source /var/calculate/config/taiga - -replace=( +regular(){ + replace=( "taiga-back/settings/config.py" "" - "('PASSWORD':).*" "\1 '${PGSQL_PASSWORD}'," - "^.*(SECRET_KEY =).*" "\1 \"${SECRET_KEY}\"" - "^.*(TAIGA_SITES_SCHEME =).*" "\1 \"${PROTOCOL}\"" - "^.*(TAIGA_SITES_DOMAIN =).*" "\1 \"${TAIGA_SITES_DOMAIN}\"" + "('PASSWORD':).*" "\1 '${taiga_pgsql_password}'," + "^.*(SECRET_KEY =).*" "\1 \"${taiga_secret_key}\"" + "^.*(TAIGA_SITES_SCHEME =).*" "\1 \"${taiga_protocol}\"" + "^.*(TAIGA_SITES_DOMAIN =).*" "\1 \"${taiga_taiga_sites_domain}\"" "^.*(MEDIA_ROOT =).*" "\1 '/var/calculate/www/taiga/taiga-back/media'" - "^.*(DEFAULT_FROM_EMAIL =).*" "\1 '${FROM_EMAIL}'" - "^.*(EMAIL_USE_TLS =).*" "\1 '${SMTP_TLS}'" - "^.*(EMAIL_USE_SSL =).*" "\1 '${SMTP_SSL}'" - "^.*(EMAIL_HOST =).*" "\1 '${SMTP_HOST}'" - "^.*(EMAIL_PORT =).*" "\1 ${SMTP_PORT}" - "^.*(EMAIL_HOST_USER =).*" "\1 '${SMTP_USER}'" - "^.*(EMAIL_HOST_PASSWORD =).*" "\1 '${SMTP_PASSWORD}'" - "(\"url\": \"amqp://).*(:5672/taiga\")" "\1${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@localhost\2" - "^.*(CELERY_BROKER_URL =).*" "\1 \"amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@localhost:5672/taiga\"" - "^.*(CELERY_TIMEZONE =).*" "\1 'Europe/Moscow'" + "^.*(DEFAULT_FROM_EMAIL =).*" "\1 '${taiga_from_email}'" + "^.*(EMAIL_USE_TLS =).*" "\1 '${taiga_smtp_tls}'" + "^.*(EMAIL_USE_SSL =).*" "\1 '${taiga_smtp_ssl}'" + "^.*(EMAIL_HOST =).*" "\1 '${taiga_smtp_host}'" + "^.*(EMAIL_PORT =).*" "\1 ${taiga_smtp_port}" + "^.*(EMAIL_HOST_USER =).*" "\1 '${taiga_smtp_user}'" + "^.*(EMAIL_HOST_PASSWORD =).*" "\1 '${taiga_smtp_password}'" + "(\"url\": \"amqp://).*(:5672/taiga\")" "\1${taiga_rabbitmq_user}:${taiga_rabbitmq_password}@localhost\2" + "^.*(CELERY_BROKER_URL =).*" "\1 \"amqp://${taiga_rabbitmq_user}:${taiga_rabbitmq_password}@localhost:5672/taiga\"" + "^.*(CELERY_TIMEZONE =).*" "\1 '${taiga_timezone}'" "^.*(ENABLE_TELEMETRY =).*" "\1 False" - "^.*(PUBLIC_REGISTER_ENABLED =).*" "\1 True" + "^.*(PUBLIC_REGISTER_ENABLED =).*" "\1 ${taiga_public_register}" "taiga-front-dist/dist/conf.json" "" - "(\"api\":).*" "\1 \"${PROTOCOL}://${TAIGA_SITES_DOMAIN}/api/v1/\"," - "(\"eventsUrl\":).*" "\1 \"wss://${TAIGA_SITES_DOMAIN}/events\"," - "(\"defaultLanguage\":).*" "\1 \"ru\"," + "(\"api\":).*" "\1 \"${taiga_protocol}://${taiga_taiga_sites_domain}/api/v1/\"," + "(\"eventsUrl\":).*" "\1 \"wss://${taiga_taiga_sites_domain}/events\"," + "(\"defaultLanguage\":).*" "\1 \"${taiga_language}\"," "(\"publicRegisterEnabled\":).*" "\1 true," - "(\"supportUrl\":).*" "\1 \"${PROTOCOL}://${TAIGA_SITES_DOMAIN}\"," + "(\"supportUrl\":).*" "\1 \"${taiga_protocol}://${taiga_taiga_sites_domain}\"," "(\"gravatar\":).*" "\1 false," "taiga-events/.env" "" - "^.*(RABBITMQ_URL=).*" "\1\"amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@localhost:5672/taiga\"" - "^.*(SECRET=).*" "\1\"${SECRET_KEY}\"" + "^.*(RABBITMQ_URL=).*" "\1\"amqp://${taiga_rabbitmq_user}:${taiga_rabbitmq_password}@localhost:5672/taiga\"" + "^.*(SECRET=).*" "\1\"${taiga_secret_key}\"" "taiga-protected/.env" "" - "^.*(SECRET_KEY=).*" "\1\"${SECRET_KEY}\"" -) - -homedir=/var/calculate/www/taiga -if [[ -d $homedir ]] -then - cd $homedir -else - eerror "Отсутствует директория $homedir!" - exit 1 -fi + "^.*(SECRET_KEY=).*" "\1\"${taiga_secret_key}\"" + ) +} check_conf(){ conf= @@ -142,11 +133,48 @@ show_conf(){ done } + +read_vars(){ + all= + while IFS= read -r line + do + if [[ $line == *"["* ]] + then + line=${line#*[} + line=${line%%]*} + sec=$line + continue + fi + com=${sec}_${line// =/=}; + com=${com//= /=}; + all="$com; $all" + done < /var/calculate/ini.env + eval $all +} + +check_homedir(){ + homedir=/var/calculate/www/taiga + if [[ -d $homedir ]] + then + cd $homedir + else + eerror "Отсутствует директория $homedir!" + exit 1 + fi +} + +read_vars + +regular + +check_homedir + ebegin 'Проверка настраиваемых переменных' `check_conf` || { if [[ $? == 1 ]] then - check_show + check_show # отобразим несоответствия + exit 1 fi exit } @@ -162,3 +190,4 @@ else einfo 'Настроенные параметры:' show_conf fi +