_helpline_en(){
echo "
  Attention!

  Automatic method
    Enable OpenSSL GOST support: ubconfig set security OPENSSL_ENGINE=GOST
    Disable OpenSSL GOST support: ubconfig set security OPENSSL_ENGINE=DEFAULT
    Disable OpenSSL management via UBConfig: ubconfig remove security OPENSSL_ENGINE 
  
  Manual method
    You have to insert that line into your /etc/ssl/openssl.cnf
    before any [section]:
      # ---------------------------
      # Set GOST Configuration
        openssl_conf=openssl_gost
      # ---------------------------
    The content of gost.cnf at the very end of the openssl.cnf
    Do not .include it.
    
  How to check
    List of supported methods:
      openssl dgst -list|grep gost
      openssl engine gost -c
      openssl ciphers|tr ':' '\n'|grep GOST
    Hashsum: openssl dgst -engine gost -md_gost12_256 testfile
    Keygen:  openssl genpkey -algorithm gost2012_256 -pkeyopt paramset:TCB -out ca.key

  TroubleShout
    1) export OPENSSLDIR=/etc/ssl
    2) https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/OpenSSL
"
}

_helpline_ru(){
echo "
  Внимание!

  Автоматический метод
  Включить поддержку OpenSSL GOST: ubconfig set security OPENSSL_ENGINE=GOST
  Отключить  поддержку OpenSSL GOST: ubconfig set security OPENSSL_ENGINE=DEFAULT
  Отключить управление OpenSSL через UBConfig: ubconfig remove security OPENSSL_ENGINE 
  
  Ручной метод
    Вы должны вставить эти строки в свой /etc/ssl/openssl.cnf
    перед любым [section]
      # ---------------------------
      # Set GOST Configuration
        openssl_conf=openssl_gost
      # ---------------------------
    Содержимое gost.cnf добавить в самый конц openssl.cnf
    Не использовать .include

  Как проверить
    Перечень поддерживаемых методов:
      openssl dgst -list|grep gost
      openssl engine gost -c
      openssl ciphers|tr ':' '\n'|grep GOST
    Hashsum: openssl dgst -engine gost -md_gost12_256 testfile
    Keygen:  openssl genpkey -algorithm gost2012_256 -pkeyopt paramset:TCB -out ca.key

  Устранение неполадок:
    1) export OPENSSLDIR=/etc/ssl
    2) https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/OpenSSL
"
}

## arg 1:  the new package version
pre_install() {
    true
}

## arg 1:  the new package version
post_install() {
    post_upgrade
}

## arg 1:  the new package version
## arg 2:  the old package version
pre_upgrade() {
    true
}

## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
  if ! grep -qs openssl_gost /etc/ssl/openssl.cnf; then
    [[ ${LANG} == "ru_RU.UTF-8" ]] && _helpline_ru || _helpline_en
  fi
  ENGINESDIR=$(openssl version -e | sed -En "/ENGINESDIR/{s/ENGINESDIR: \"(.*)\"/\1/p}") #"
  if [[ ${LANG} == "ru_RU.UTF-8" ]]; then
    echo "Проверьте после установки: ${ENGINESDIR} должен содержать файл 'gost.so'"
  else
    echo "Checks after installation: ${ENGINESDIR} should contains the file 'gost.so'"
  fi
}

## arg 1:  the old package version
pre_remove() {
    true
}

## arg 1:  the old package version
post_remove() {
  if grep -qs "openssl_gost" /etc/ssl/openssl.cnf; then
    if [[ ${LANG} == "ru_RU.UTF-8" ]]; then
      echo "Не забудьте изменить свой файл /etc/ssl/openssl.cnf"
      echo "или выполнить: ubconfig set security OPENSSL_ENGINE=DEFAULT"
    else
      echo "Do not forget to modify your /etc/ssl/openssl.cnf"
      echo "or excute: ubconfig set security OPENSSL_ENGINE=DEFAULT"
    fi
  fi
}
