install.sh 27.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
#!/bin/bash

# NOTE: Evita problemas com caminhos relativos! By Questor
SCRIPTDIR_V="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $SCRIPTDIR_V/ez_i.sh

# > --------------------------------------------------------------------------
# INÍCIO!
# --------------------------------------

read -d '' TITLE_F <<"EOF"
LBG - LBGenerator Installer
EOF

read -d '' VERSION_F <<"EOF"
0.6.2.0
EOF

read -d '' ABOUT_F <<"EOF"
This script will install LBGenerator the LightBase data specification and model!

Have fun! =D
EOF

read -d '' WARNINGS_F <<"EOF"
- Installer designed for CentOS 6 AMD64/RHEL 6 AMD64!

- We RECOMMEND you...
    Install all the components (answer yes to everything). Except 
        contrary guidance!
    Check for previous installations! If there is previous 
        installations consider this variant in the process!
- We WARNING you...
    USE AT YOUR OWN RISK: WE ARE NOT RESPONSIBLE FOR ANY DAMAGE TO 
YOURSELF, HARDWARE, OR CO-WORKERS. EXCEPT IN CASES WHERE THERE ARE 
SIGNED CONTRACT THAT REGULATES THIS!
EOF

read -d '' COMPANY_F <<"EOF"
BR Light LTDA - LightBase Consulting in Public Software/LightBase Consultoria em Software Público
Free Software + Our Ideas = Best Solution!/Software Livre + Nossas Idéias = Melhor Solução!
+55-61-3347-1949 - http://www.LightBase.com.br - Brasil-DF
EOF

f_begin "$TITLE_F" "$VERSION_F" "$ABOUT_F" "$WARNINGS_F" "$COMPANY_F"
ABOUT_F=""
WARNINGS_F=""

# < --------------------------------------------------------------------------

# > --------------------------------------------------------------------------
# TERMOS E LICENÇA!
# --------------------------------------

read -d '' TERMS_LICEN_F <<"EOF"
BY USING THIS INSTALLER YOU ARE AGREEING TO THE TERMS OF USE OF ALL 
INVOLVED SOFTWARE!
EOF

f_terms_licen "$TERMS_LICEN_F"
TERMS_LICEN_F=""

# < --------------------------------------------------------------------------

# > --------------------------------------------------------------------------
# INTRUÇÕES!
# --------------------------------------

read -d '' INSTRUCT_F <<"EOF"
- To run this script YOU NEED to be root!

- TO CANCEL installation at any time use Ctrl+c!
EOF

f_instruct "$INSTRUCT_F"
INSTRUCT_F=""

# < --------------------------------------------------------------------------

# > -----------------------------------------
# Dá ao usuário mais avançado a possibilideade de usar o instalador 
# simplificado!

# NOTE: É possível forçar o processo de instalção simplificado setando 
# "SIMPLE_INST" com 1! By Questor
SIMPLE_INST=0
if [ ${SIMPLE_INST} -eq 0 ] ; then
    f_open_section
    f_yes_no "Use simple install (using a default value for most of the options)?"
    if [ ${YES_NO_R} -eq 1 ] ; then

        # NOTE: Essa variável serve apenas para "preservar" o valor 
        # setado pelo usuário sendo somente "leitura". A variável a 
        # ser usada nas regras deve ser "EZ_I_SKIP_ON_V" (ez_i.sh)! Essa 
        # estratégia serve para mudarmos o comportamento do "ez_i.sh" 
        # de acordo com as circunstâncias! By Questor
        SIMPLE_INST=1

        # NOTE: Essa variável é para consumo do "ez_i.sh", para que ele 
        # não execute algumas funções e simplifique o processo de 
        # instalação! By Questor
        EZ_I_SKIP_ON_V=1
    fi
    f_close_section
    sleep 1
fi

# < -----------------------------------------

# > -----------------------------------------
# Garantir o encodamento correto para evitar problemas de 
# compatibilidade!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Set terminal encode? (recommended for Windows terminal clients)
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    export LANG=pt_BR.utf8
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Desabilita o SElinux!

EZ_I_SKIP_ON_V=0
f_open_section
read -d '' TITLE_F <<"EOF"
Disable SElinux (use "y" if you never did it)?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${YES_NO_R} -eq 1 ] ; then
    setenforce 0

    # NOTE: As condições abaixo visam evitar que o arquivo seja 
    # desnecessariamente e erroneamente modificado! By Questor
    EZ_I_SKIP_ON_V=$SIMPLE_INST
    f_fl_cont_str "# SELINUX=enforcing" "/etc/sysconfig/selinux" "The file \"/etc/sysconfig/selinux\" probably has already been changed! Check it!"
    EZ_I_SKIP_ON_V=0
    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
        f_fl_cont_str "SELINUX=disabled" "/etc/sysconfig/selinux"
        if [ ${FL_CONT_STR_R} -eq 0 ] ; then
            f_ez_sed "SELINUX=enforcing" "# SELINUX=enforcing\nSELINUX=disabled" "/etc/sysconfig/selinux"
        fi
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instala os componentes de base usados pela especificação LightBase!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install base components?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_pack_is_inst "gcc-c++" "yum" "\"gcc-c++\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install gcc-c++
    fi
    f_pack_is_inst "zlib-devel" "yum" "\"zlib-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install zlib-devel
    fi
    f_pack_is_inst "openssl-devel" "yum" "\"openssl-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install openssl-devel
    fi
    f_pack_is_inst "postgresql-devel" "yum" "\"postgresql-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install postgresql-devel
    fi
    f_pack_is_inst "git" "yum" "\"git\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install git
    fi
fi
f_close_section

# < -----------------------------------------

BASE_INST_DIR_V="/usr/local/lb"
# > -----------------------------------------
# Criar o diretório base da instalação!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
QUESTION_F="Insert where the base installation directory (\"lb\") will be created (don't use \"/\" at the end). 
Use empty for \"/usr/local\"!"

f_get_usr_input "$QUESTION_F" 1
QUESTION_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ -z "$GET_USR_INPUT_R" ] ; then
    f_chk_by_path_hlp "$BASE_INST_DIR_V" "d" "\"$BASE_INST_DIR_V\" directory already created!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        mkdir -p "$BASE_INST_DIR_V"
    fi
else
    BASE_INST_DIR_V="$GET_USR_INPUT_R/lb"
    f_chk_by_path_hlp "$BASE_INST_DIR_V" "d" "\"$BASE_INST_DIR_V\" directory already created!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        mkdir -p "$BASE_INST_DIR_V"
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o python3.2!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install python3.2?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_by_path_hlp "$BASE_INST_DIR_V/py32" "d" "python3.2 already installed in \"$BASE_INST_DIR_V/py32\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        tar -zxvf Python-3.2.2.tar.gz
        cd ./Python-3.2.2
        eval "./configure --prefix=$BASE_INST_DIR_V/py32/ --with-threads --enable-shared LDFLAGS=-Wl,-rpath=$BASE_INST_DIR_V/py32/lib/"
        make && make install
        cd ..
        rm -rf ./Python-3.2.2
        f_enter_to_cont "python3.2 installed in \"$BASE_INST_DIR_V/py32\"!"
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o virtualenv-1.11.6 no python3.2!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install virtualenv-1.11.6 on python3.2?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_by_path_hlp "$BASE_INST_DIR_V/py32/bin/virtualenv-3.2" "f" "virtualenv-1.11.6 already installed in python3.2 (\"$BASE_INST_DIR_V/py32\")!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        tar -zxvf virtualenv-1.11.6.tar.gz
        cd virtualenv-1.11.6
        $BASE_INST_DIR_V/py32/bin/python3.2 setup.py install
        cd ..
        rm -rf virtualenv-1.11.6
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Criar o ambiente virtual (python3.2)!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
f_enter_to_cont "Create the virtual environment (python3.2)!"

f_chk_by_path_hlp "$BASE_INST_DIR_V/ve32" "d" "Virtual environment (python3.2) already created in \"$BASE_INST_DIR_V/ve32\"!"
if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
    cd "$BASE_INST_DIR_V"
    $BASE_INST_DIR_V/py32/bin/virtualenv-3.2 ve32
    mkdir "$BASE_INST_DIR_V/ve32/src"
    f_enter_to_cont "Virtual environment created in \"$BASE_INST_DIR_V/ve32\"!"
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o Apache (httpd)!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install Apache (httpd)?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_pack_is_inst "httpd-devel" "yum" "Apache (httpd) already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install httpd-devel httpd
        chkconfig httpd on
        chown -R apache /var/www
        chmod -R 755 /var/www
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Abrir o firewall para o Apache (httpd)!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Open firewall for Apache (httpd) (TCP 80)?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_iptables 80 "Port 80 is already open!" 0 "ACCEPT" "tcp" "NEW"
    if [ ${F_CHK_IPTABLES_R} -eq 1 ] ; then
        iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
        service iptables save
        service iptables restart
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o mod_wsgi-4.3.2!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install mod_wsgi-4.3.2?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps

    f_fl_cont_str "$BASE_INST_DIR_V/py32/lib" "/etc/ld.so.conf" "The file \"/etc/ld.so.conf\" probably has already been changed! Check it!"
    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
        f_ez_sed "include ld.so.conf.d/*.conf" "include ld.so.conf.d/*.conf\n$BASE_INST_DIR_V/py32/lib" "/etc/ld.so.conf"
    fi

    UP_MOD_WSGI=1
    f_chk_by_path_hlp "/usr/lib64/httpd/modules/mod_wsgi.so" "f" "mod_wsgi already installed in \"/usr/lib64/httpd/modules/mod_wsgi.so\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        if [ ${EZ_I_SKIP_ON_V} -eq 0 ] ; then
            TITLE_F="Update/reinstall mod_wsgi? (\"y\" recommended)"
            f_div_section
            f_yes_no "$TITLE_F"
            f_div_section
            TITLE_F=""
            UP_MOD_WSGI=$YES_NO_R
            if [ ${UP_MOD_WSGI} -eq 1 ] ; then
                rm -rf "/usr/lib64/httpd/modules/mod_wsgi.so"
            fi
        fi
    fi
    if [ ${UP_MOD_WSGI} -eq 1 ] ; then
        ldconfig
        tar -zxvf ./mod_wsgi-4.3.2.tar.gz
        cd ./mod_wsgi-4.3.2
        eval "./configure --with-python=$BASE_INST_DIR_V/py32/bin/python3.2"
        make && make install
        cd ..
        rm -rf ./mod_wsgi-4.3.2
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o ElasticSearch!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install ElasticSearch?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_pack_is_inst "elasticsearch.noarch" "yum" "ElasticSearch already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        f_pack_is_inst "java-1.7.0-openjdk" "yum" "java-1.7.0-openjdk already installed!"
        if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
            yum -y install java-1.7.0-openjdk
        fi
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        rpm -Uvh elasticsearch-1.1.1.noarch.rpm
        /sbin/chkconfig --add elasticsearch
        f_fl_cont_str "cluster.name: lb" "/etc/elasticsearch/elasticsearch.yml" "The file \"/etc/elasticsearch/elasticsearch.yml\" probably has already been changed! Check it!"
        if [ ${FL_CONT_STR_R} -eq 0 ] ; then
            f_ez_sed "# cluster.name: elasticsearch" "# cluster.name: elasticsearch\ncluster.name: lb" "/etc/elasticsearch/elasticsearch.yml"
        fi
        service elasticsearch start
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Abrir o firewall para o ElasticSearch!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Open firewall for ElasticSearch (TCP 9200)?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_iptables 9200 "Port 9200 is already open!" 0 "ACCEPT" "tcp" "NEW"
    if [ ${F_CHK_IPTABLES_R} -eq 1 ] ; then
        iptables -I INPUT 6 -p tcp -m state --state NEW -m tcp --dport 9200 -j ACCEPT
        service iptables save
        service iptables restart
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar o postgres 9.4!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install postgres 9.4?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps
    f_pack_is_inst "pgdg-centos94-9.4-1.noarch" "yum" "postgres 9.4 already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y localinstall pgdg-centos94-9.4-1.noarch.rpm
        yum -y install postgresql94-server
        service postgresql-9.4 initdb
        chkconfig postgresql-9.4 on
        service postgresql-9.4 start
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Configurar o postgres 9.4!

CONF_PG=0
EZ_I_SKIP_ON_V=0
f_open_section
TITLE_F="Configure postgres 9.4 (use \"y\" if you never did it)?"
f_yes_no "$TITLE_F"
TITLE_F=""
PG_USER_F="lbu"
PG_PWD_F="lbu"
PG_EXT_ACS_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then

    EZ_I_SKIP_ON_V=$SIMPLE_INST

    f_div_section

    QUESTION_F="Enter the postgres 9.4 user for lightbase (LBG). 
Use empty for \"$PG_USER_F\"!"

    f_get_usr_input "$QUESTION_F" 1
    QUESTION_F=""
    if [ -n "$GET_USR_INPUT_R" ] ; then
        PG_USER_F=$GET_USR_INPUT_R
    fi

    f_div_section

    QUESTION_F="Enter the postgres 9.4 password for \"$PG_USER_F\". 
Use empty for \"$PG_PWD_F\"!"

    f_get_usr_input "$QUESTION_F" 1
    QUESTION_F=""
    if [ -n "$GET_USR_INPUT_R" ] ; then
        PG_PWD_F=$GET_USR_INPUT_R
    fi

    f_div_section

    QUESTION_F="Enter one ip or ip range for external access.
e.g. \"172.20.143.89/32\" for a single host or \"172.20.143.0/24\" for a small network or \"10.6.0.0/16\" for a larger one!
Use empty for local access only!"

    f_get_usr_input "$QUESTION_F" 1
    QUESTION_F=""
    if [ -n "$GET_USR_INPUT_R" ] ; then
        PG_EXT_ACS_F=$GET_USR_INPUT_R
    fi
    EZ_I_SKIP_ON_V=0

    f_is_not_running "postgres" "ERROR! \"postgres\" service not running!"
    if [ ${F_IS_NOT_RUNNING_R} -eq 0 ] ; then
        cd /tmp
        f_get_stderr_stdout "sudo -u postgres psql -tAc \"SELECT * FROM pg_roles WHERE rolname='$PG_USER_F';\""
        if [[ $F_GET_STDOUT_R == *"$PG_USER_F|"* ]]; then
            # NOTE: 
            # rolname|
            # rolsuper|
            # rolinherit|
            # rolcreaterole|
            # rolcreatedb|
            # rolcatupdate|
            # rolcanlogin|
            # rolconnlimit|
            # rolpassword|
            # rolvaliduntil|
            # rolconfig|
            # oid
            # ! By Questor
            if [[ $F_GET_STDOUT_R != *"$PG_USER_F|t|t|t|t|t|t|f|-1|"* ]]; then
                f_div_section
                echo "The user \"$PG_USER_F\" already created, but something is apparently wrong with his roles. The expected roles are \"lbu|f|t|t|t|t|t|f|-1|...\"! DETAILS: \"$F_GET_STDOUT_R\"."
                f_div_section
                f_continue
            else
                EZ_I_SKIP_ON_V=$SIMPLE_INST
                f_enter_to_cont "The user \"$PG_USER_F\" already created and his roles are correct!"
                EZ_I_SKIP_ON_V=0
            fi
        else
            if [[ $F_GET_STDERR_R == "" ]]; then
                sudo -u postgres psql -c "CREATE USER $PG_USER_F INHERIT SUPERUSER CREATEROLE CREATEDB;"
                sudo -u postgres psql -c "ALTER USER $PG_USER_F PASSWORD '$PG_PWD_F';"
            else
                f_enter_to_cont "An error occurred when creating \"$PG_USER_F\" user permissions! ERROR: \"$F_GET_STDERR_R\"."
                f_error_exit
            fi
        fi
        cd - >/dev/null
    else
        f_error_exit
    fi

    EZ_I_SKIP_ON_V=$SIMPLE_INST
    if [ -n "$PG_EXT_ACS_F" ] ; then
        f_fl_cont_str "host    all             all             $PG_EXT_ACS_F            trust" "/var/lib/pgsql/9.4/data/pg_hba.conf" "The file \"/var/lib/pgsql/9.4/data/pg_hba.conf\" probably has already been changed for external access! Check it!"
        if [ ${FL_CONT_STR_R} -eq 0 ] ; then
            f_ez_sed "# IPv4 local connections:" "# IPv4 local connections:\nhost    all             all             $PG_EXT_ACS_F            trust" "/var/lib/pgsql/9.4/data/pg_hba.conf"
        fi
    fi

    f_fl_cont_str "host    all             all             127.0.0.1/32            trust" "/var/lib/pgsql/9.4/data/pg_hba.conf" "The file \"/var/lib/pgsql/9.4/data/pg_hba.conf\" probably has already been changed for local access! Check it!"
    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
        f_ez_sed "# IPv4 local connections:" "# IPv4 local connections:\nhost    all             all             127.0.0.1/32            trust" "/var/lib/pgsql/9.4/data/pg_hba.conf"
    fi

    f_fl_cont_str "listen_addresses = '*'" "/var/lib/pgsql/9.4/data/postgresql.conf" "The file \"/var/lib/pgsql/9.4/data/postgresql.conf\" probably has already been changed! Check it!"
    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
        f_ez_sed "# - Connection Settings -" "# - Connection Settings -\n\nlisten_addresses = '*'" "/var/lib/pgsql/9.4/data/postgresql.conf"
    fi

    service postgresql-9.4 restart
    f_enter_to_cont "The file \"/var/lib/pgsql/9.4/data/pg_hba.conf\" has settings for postgres 9.4! Check it for more details!"
    EZ_I_SKIP_ON_V=0
    CONF_PG=1
else
    f_enter_to_cont "The file \"/var/lib/pgsql/9.4/data/pg_hba.conf\" has settings for postgres 9.4! Check it!"
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Abrir o firewall para o postgres 9.4!

EZ_I_SKIP_ON_V=0
f_open_section
read -d '' TITLE_F <<"EOF"
Open firewall for postgres 9.4 (TCP 5432)?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_iptables 5432 "Port 5432 is already open!" 0 "ACCEPT" "tcp"
    if [ ${F_CHK_IPTABLES_R} -eq 1 ] ; then
        iptables -I INPUT 1 -m tcp -p tcp --dport 5432 -j ACCEPT
        service iptables save
        service iptables restart
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Criar as estruturas de dados básicas do LB no postgres 9.4!

CREATE_LB_DT=0
EZ_I_SKIP_ON_V=0
f_open_section
TITLE_F="Create the basic LightBase (LBG) data structures in postgres 9.4 (use \"y\" if you never did it)?"
f_yes_no "$TITLE_F"
TITLE_F=""
PG_DB_F="lb"
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then

    EZ_I_SKIP_ON_V=$SIMPLE_INST
    QUESTION_F="Enter the postgres 9.4 database name for LightBase (LBG). 
Use empty for \"$PG_DB_F\" (recommended)!"

    f_get_usr_input "$QUESTION_F" 1
    QUESTION_F=""
    if [ -n "$GET_USR_INPUT_R" ] ; then
        PG_DB_F=$GET_USR_INPUT_R
    fi
    EZ_I_SKIP_ON_V=0
    f_is_not_running "postgres" "ERROR! \"postgres\" service not running!"
    if [ ${F_IS_NOT_RUNNING_R} -eq 0 ] ; then
        cd /tmp
        f_get_stderr_stdout "sudo -u postgres psql -c \"CREATE DATABASE $PG_DB_F;\""
        if [[ $F_GET_STDERR_R != "" ]]; then
            if [[ $F_GET_STDERR_R == *" already exists"* ]]; then
                EZ_I_SKIP_ON_V=$SIMPLE_INST
                f_enter_to_cont "The database \"$PG_DB_F\" already created!"
                EZ_I_SKIP_ON_V=0
            else
                f_div_section
                echo "An error occurred when creating \"$PG_DB_F\" database! ERROR: \"$F_GET_STDERR_R\"."
                f_div_section
                f_error_exit
            fi
        else
            cd "$SCRIPTDIR_V"
            cp ./lbn-basic-dt-strt/lbn_basic_dt_strt.sql /tmp
            cd /tmp
            chmod 700 lbn_basic_dt_strt.sql
            chown postgres lbn_basic_dt_strt.sql
            chown :postgres lbn_basic_dt_strt.sql
            sudo -u postgres psql $PG_DB_F -f lbn_basic_dt_strt.sql
            rm -f lbn_basic_dt_strt.sql
        fi
    else
        f_error_exit
    fi
    CREATE_LB_DT=1
else
    f_enter_to_cont "The file \"./lbn-basic-dt-strt/lbn_basic_dt_strt.sql\" has the basic LightBase (LBG) data structures! Check it!"
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar as dependências python da LIB - liblightbase!

EZ_I_SKIP_ON_V=$SIMPLE_INST
cd "$SCRIPTDIR_V"
sh py-packs-liblightbase.sh "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V"

# < -----------------------------------------

# > -----------------------------------------
# Instalar a LIB - liblightbase!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install the LIB - liblightbase?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_by_path_hlp "$BASE_INST_DIR_V/ve32/src/liblightbase" "d" "\"liblightbase\" already installed in \"$BASE_INST_DIR_V/ve32/src\"!"
    F_BAK_MD_R=1
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_ez_mv_bak "$BASE_INST_DIR_V/ve32/src/liblightbase" "Backup old version and update? (\"y\" recommended)"
    fi
    if [ ${F_BAK_MD_R} -eq 1 ] ; then
        cd "$SCRIPTDIR_V"
        tar -zxvf liblightbase.tar.gz
        mv "$SCRIPTDIR_V/liblightbase" "$BASE_INST_DIR_V/ve32/src/"
        cd "$BASE_INST_DIR_V/ve32/src/liblightbase"
        eval "$BASE_INST_DIR_V/ve32/bin/python3.2 setup.py install"
    fi
fi
f_close_section

# < -----------------------------------------

# > -----------------------------------------
# Instalar e configurar o LBG - LBGenerator!

EZ_I_SKIP_ON_V=$SIMPLE_INST
cd "$SCRIPTDIR_V"
sh py-packs-LBGenerator.sh "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V"

# < -----------------------------------------

# > -----------------------------------------
# Instalar o LBG - LBGenerator!

EZ_I_SKIP_ON_V=$SIMPLE_INST
APP_URL_F="lbg"
f_open_section
read -d '' TITLE_F <<"EOF"
Install the LBG - LBGenerator?
EOF

f_yes_no "$TITLE_F"
TITLE_F=""
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then

    f_chk_by_path_hlp "$BASE_INST_DIR_V/ve32/src/LBGenerator" "d" "\"LBGenerator\" already installed in \"$BASE_INST_DIR_V/ve32/src\"!"
    F_BAK_MD_R=1
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_ez_mv_bak "$BASE_INST_DIR_V/ve32/src/LBGenerator" "Backup old version and update? (\"y\" recommended)"
    fi
    if [ ${F_BAK_MD_R} -eq 1 ] ; then
        cd "$SCRIPTDIR_V"
        tar -zxvf LBGenerator.tar.gz
        mv "$SCRIPTDIR_V/LBGenerator" "$BASE_INST_DIR_V/ve32/src/"
        cd "$BASE_INST_DIR_V/ve32/src/LBGenerator"
        eval "$BASE_INST_DIR_V/ve32/bin/python3.2 setup.py install"

        f_enter_to_cont "Configure httpd (Apache) for LBG - LBGenerator!"

        # NOTE: To debug! By Questor
        # PG_USER_F="lbu"
        # PG_PWD_F="lbu"
        # PG_DB_F="lb"
        PG_CFG_F="postgresql://$PG_USER_F:$PG_PWD_F@127.0.0.1/$PG_DB_F"
        QUESTION_F="Enter the postgres 9.4 LBG configuration. 
Use empty for \"$PG_CFG_F\"!"

        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        f_div_section
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            PG_CFG_F=$GET_USR_INPUT_R
        fi

        QUESTION_F="Enter lightbase URL. 
Use empty for \"$APP_URL_F\" (used like e.g. http://<ip_or_name>/$APP_URL_F)!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        f_div_section
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            APP_URL_F=$GET_USR_INPUT_R
        fi

        eval "cp -f \"$BASE_INST_DIR_V/ve32/src/LBGenerator/lbgenerator.wsgi-dist\" \"$BASE_INST_DIR_V/ve32/src/LBGenerator/lbgenerator.wsgi\""
        f_ez_sed "<VE32_PATH>" "$BASE_INST_DIR_V/ve32" "$BASE_INST_DIR_V/ve32/src/LBGenerator/lbgenerator.wsgi"

        eval "cp -f \"$BASE_INST_DIR_V/ve32/src/LBGenerator/production.ini-dist\" \"$BASE_INST_DIR_V/ve32/src/LBGenerator/production.ini\""
        f_ez_sed "<SQLALCHEMY_URL>" "$PG_CFG_F" "$BASE_INST_DIR_V/ve32/src/LBGenerator/production.ini" 1

        f_chk_by_path_hlp "/etc/httpd/conf.d/lbg.conf" "f" "\"lbg.conf\" already created in \"/etc/httpd/conf.d/lbg.conf\"!"
        F_BAK_MD_R=1
        if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
            f_ez_mv_bak "/etc/httpd/conf.d/lbg.conf" "Backup old version and update? (\"y\" recommended)"
        fi

        if [ ${F_BAK_MD_R} -eq 1 ] ; then
            eval "cp -f \"$SCRIPTDIR_V/other-srcs-n-apps/lbg.conf.dist\" \"/etc/httpd/conf.d/lbg.conf\""
            f_ez_sed "<VE32_PATH>" "$BASE_INST_DIR_V/ve32" "/etc/httpd/conf.d/lbg.conf" 1
            f_ez_sed "<LBG_URL>" "$APP_URL_F" "/etc/httpd/conf.d/lbg.conf" 1
        fi

        eval "chown -R apache $BASE_INST_DIR_V"
        eval "chmod -R 755 $BASE_INST_DIR_V"

        service httpd restart
    fi
fi
f_close_section

# < -----------------------------------------

# > --------------------------------------------------------------------------
# FINAL!
# --------------------------------------

EZ_I_SKIP_ON_V=0
read -d '' TITLE_F <<"EOF"
Installer finished! Thanks!
EOF

# NOTE: A lógica imediatamente abaixo serve para os casos onde o 
# usuário optou por instalação simplificada para que ele seja informado 
# sobre quais foram as configurações de persistência setadas! By Questor
PERSIST_CONFIG=""
if [ ${SIMPLE_INST} -eq 1 ] && ([ ${CONF_PG} -eq 1 ] || [ ${CREATE_LB_DT} -eq 1 ]); then

    if [ ${CONF_PG} -eq 1 ] ; then
        CONF_PG_VL="
        user ...... $PG_USER_F
        password .. $PG_PWD_F"
    fi
    if [ ${CREATE_LB_DT} -eq 1 ] ; then
        CREATE_LB_DT_VL="
        database .... $PG_DB_F"
    fi

    PERSIST_CONFIG="
    LightBase (LBG) postgres 9.4 persistence config...$CREATE_LB_DT_VL$CONF_PG_VL
"
fi

USEFUL_INFO_F="    To start/stop...
        service httpd start
        service httpd stop
$PERSIST_CONFIG
    To access...
        http://<ip>/$APP_URL_F

    To configure...
        vi $BASE_INST_DIR_V/ve32/src/LBGenerator/production.ini

    To configure httpd (Apache)...
        vi /etc/httpd/conf.d/lbg.conf

    Log...
        less /var/log/httpd/error_log"

f_end "$TITLE_F" "$USEFUL_INFO_F"
TITLE_F=""
USEFUL_INFO_F=""

# < --------------------------------------------------------------------------