install.bash 100 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 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556
#!/bin/bash

# > -----------------------------------------
# Run that script with bash even if the user use sh/dash or any sh like 
# interpreter. This way it correctly works with either: 
# "sh ./my_script.bash" or "bash ./my_script.bash" or "./my_script.bash"

if [ -z "$BASH_VERSION" ]
then
    exec bash "$0" "$@"
fi

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

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

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

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

# NOTE: Para versionamento usar "MAJOR.MINOR.REVISION.BUILDNUMBER"! 
# Usar a mesma versão contida no setup.py! By Questor
# http://programmers.stackexchange.com/questions/24987/what-exactly-is-the-build-number-in-major-minor-buildnumber-revision

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

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

read -d '' WARNINGS_F <<"EOF"
- This installer is compatible with RHEL, SUSE, Debian or distributions 
based on these.

- We RECOMMEND you...
    Install all the components (answer yes to everything) and use the default 
        values. Except contrary guidance!
    Check for previous installations! If there is previous 
        installations consider this variant in the process!
    Although this is not mandatory, do the installation process in an 
        exclusive machine for this.

- We NOTICE you...
    This installer assumes that the target distribution has a "standard 
    setup". This may include components such as firewall, SELinux 
    and others.

- We WARNING you...
    THIS INSTALLER AND RESULTING PRODUCTS COMES WITH ABSOLUTELY NO WARRANTY! 
    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
+55-61-3347-1949/+55-61-3340-6966 - http://brlight.org/ - Brasil-DF
Free software! Embrace that idea!/Software livre! Abrace essa idéia!
EOF

TUX=$(cat $SCRIPTDIR_V/tux.txt)
f_begin "$TITLE_F" "$VERSION_F" "$ABOUT_F$TUX" "$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=""

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

# > -----------------------------------------
# Checar se o usuário é root!

f_is_root

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

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

read -d '' INSTRUCT_F <<"EOF"
- TO CANCEL installation at any time use Ctrl+c!
EOF

f_instruct "$INSTRUCT_F"
INSTRUCT_F=""

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

# NOTE: A razão para a existência dessas variáveis é "abistrair" o
# funcionamento de "f_about_distro" que obtêm informações a partir de
# dados da própria distro e portanto sujeito a variações! By Questor
DISTRO_TYPE=""
DISTRO_NAME=""

# > -----------------------------------------
# Checar se a distro é compatível!

f_open_section
f_about_distro
f_div_section
echo "DISTRO INFORMATION:"
f_div_section
echo "NAME: .... ${F_ABOUT_DISTRO_R[0]}"
echo "VERSION: . ${F_ABOUT_DISTRO_R[1]}"
echo "BASED: ... ${F_ABOUT_DISTRO_R[2]}"
echo "ARCH: .... ${F_ABOUT_DISTRO_R[3]}"
f_div_section

if [[ "${F_ABOUT_DISTRO_R[2]}" == "Debian" ]] || [[ "${F_ABOUT_DISTRO_R[2]}" == "RedHat" ]] || 
    [[ "${F_ABOUT_DISTRO_R[2]}" == "Suse" ]] ; then
    if [[ "${F_ABOUT_DISTRO_R[2]}" == "Debian" ]] ; then
        DISTRO_TYPE="DEB"
        if [[ "${F_ABOUT_DISTRO_R[0]}" == "Ubuntu" ]] ; then
            DISTRO_NAME="Ubuntu"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "14.04" ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 14.04/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        elif [[ "${F_ABOUT_DISTRO_R[0]}" == "Debian GNU/Linux" ]] ; then
            DISTRO_NAME="Debian"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "8" ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 8/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        else
            f_div_section
            f_yes_no "Linux distro may be incompatible with this installer (expected: Ubuntu or Debian/obtained: ${F_ABOUT_DISTRO_R[0]})! Continue?"
            if [ ${YES_NO_R} -eq 0 ] ; then
                exit 0
            fi
        fi
    elif [[ "${F_ABOUT_DISTRO_R[2]}" == "RedHat" ]] ; then
        DISTRO_TYPE="RH"
        if [[ "${F_ABOUT_DISTRO_R[0]}" == "Red Hat Enterprise Linux Server" ]] ; then
            DISTRO_NAME="RedHat"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "7"* ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 7.X/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        elif [[ "${F_ABOUT_DISTRO_R[0]}" == "CentOS Linux" ]] ; then
            DISTRO_NAME="CentOS"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "7"* ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 7.X/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        else
            f_div_section
            f_yes_no "Linux distro may be incompatible with this installer (expected: CentOS or Red Hat Enterprise Linux Server/obtained: ${F_ABOUT_DISTRO_R[0]})! Continue?"
            if [ ${YES_NO_R} -eq 0 ] ; then
                exit 0
            fi
        fi
    elif [[ "${F_ABOUT_DISTRO_R[2]}" == "Suse" ]] ; then
        DISTRO_TYPE="SUSE"
        if [[ "${F_ABOUT_DISTRO_R[0]}" == "openSUSE" ]] ; then
            DISTRO_NAME="openSUSE"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "13."* ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 13.X/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        elif [[ "${F_ABOUT_DISTRO_R[0]}" == "SLES" ]] ; then
            DISTRO_NAME="SLES"
            if [[ "${F_ABOUT_DISTRO_R[1]}" != "12."* ]] ; then
                f_div_section
                f_yes_no "Linux version may be incompatible with this installer (expected: 12.X/obtained: ${F_ABOUT_DISTRO_R[1]})! Continue?"
                if [ ${YES_NO_R} -eq 0 ] ; then
                    exit 0
                fi
            fi
        else
            f_div_section
            f_yes_no "Linux distro may be incompatible with this installer (expected: openSUSE or SUSE Linux Enterprise Server/obtained: ${F_ABOUT_DISTRO_R[0]})! Continue?"
            if [ ${YES_NO_R} -eq 0 ] ; then
                exit 0
            fi
        fi
    fi

    if [[ "${F_ABOUT_DISTRO_R[3]}" != "x86_64" ]] ; then
        f_enter_to_cont "Linux architecture completely incompatible with this installer (expected: x86_64/obtained: ${F_ABOUT_DISTRO_R[3]})!"
        exit 0
    fi
else
    f_enter_to_cont "Linux distro completely incompatible with this installer (expected: Debian (or based) or RedHat (or based) or SUSE (or based)/obtained: ${F_ABOUT_DISTRO_R[2]})!"
    exit 0
fi
f_close_section

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

# > -----------------------------------------
# Dá ao usuário a possibilidade de usar o instalador no modo rápido. Bom para 
# conhecer/testar o sistema de forma simples sem preucupar-se com configurações!

# NOTE: É possível forçar o processo de instalação no modo rápido setando 
# "FAST_INST" com 1! By Questor
FAST_INST=0
if [ ${FAST_INST} -eq 0 ] ; then
    f_open_section
    f_div_section
    f_yes_no "Use fast install (use default values for most of the options)? 

NOTE: RECOMMENDED FOR THOSE who want to KNOW and TEST the LB system components 
quickly and easily. DO NOT USE FOR PRODUCTION ENVIRONMENT! If YES the 
installation of all LB system components MUST AND WILL BE LOCAL!

Use it?"
    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.bash)! Essa 
        # estratégia serve para mudarmos o comportamento do "ez_i.bash" 
        # de acordo com as circunstâncias! By Questor
        FAST_INST=1

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

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

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

if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    EZ_I_SKIP_ON_V=0
    f_open_section
    f_div_section
    f_yes_no "Disable SElinux (use \"y\" if you never did it)?"
    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=$FAST_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
fi

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

# > -----------------------------------------
# Atualizar a distro (repositório)!

EZ_I_SKIP_ON_V=$FAST_INST
f_open_section
if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    if [[ "$DISTRO_NAME" == "RedHat" ]] ; then
        RESOURCES_ARR_P=("Red Hat Enterprise Linux Server")
        f_chk_distro_status "$DISTRO_NAME" RESOURCES_ARR_P[@]
    fi
    f_div_section
    f_yes_no "Update your distro? (\"y\" highly recommended)"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        yum -y update
    fi
    f_pack_is_inst "git" "yum" "\"git\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install git
    fi
elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
    f_div_section
    f_yes_no "Update your distro? (\"y\" highly recommended)"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        apt-get -y update
    fi
    f_pack_is_inst "git" "apt-get" "\"git\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        apt-get -y install git
    fi
elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
    if [[ "$DISTRO_NAME" == "SLES" ]] ; then
        RESOURCES_ARR_P=("SUSE_Linux_Enterprise_Server_12_SP1_x86_64"
"SUSE_Linux_Enterprise_Software_Development_Kit_12_SP1_x86_64"
"Web_and_Scripting_Module_12_x86_64")
        f_chk_distro_status "SLES" RESOURCES_ARR_P[@]
    fi
    f_div_section
    f_yes_no "Update your distro? (\"y\" highly recommended)"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        zypper --non-interactive update
    fi
    f_pack_is_inst "git-core" "zypper" "\"git-core\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        zypper --non-interactive install git-core
    fi
fi
f_close_section

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

# > -----------------------------------------
# Instalar pacotes que são comuns a determinados componentes!

F_COM_PKS_INSTALLED=0
f_common_packs() {
    : 'Instalar pacotes que são comuns a determinados componentes.'

    if [ ${F_COM_PKS_INSTALLED} -eq 0 ] ; then
        if [[ "$DISTRO_TYPE" == "RH" ]] ; 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 "autoconf" "yum" "\"autoconf\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install autoconf
            fi
            f_pack_is_inst "automake" "yum" "\"automake\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install automake
            fi
            f_pack_is_inst "libtool" "yum" "\"libtool\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install libtool
            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
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_pack_is_inst "g++" "apt-get" "\"g++\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install g++
            fi
            f_pack_is_inst "autoconf" "apt-get" "\"autoconf\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install autoconf
            fi
            f_pack_is_inst "make" "apt-get" "\"make\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install make
            fi
            f_pack_is_inst "libtool" "apt-get" "\"libtool\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install libtool
            fi
            f_pack_is_inst "zlib1g-dev" "apt-get" "\"zlib1g-dev\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install zlib1g-dev
            fi
            f_pack_is_inst "libssl-dev" "apt-get" "\"libssl-dev\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install libssl-dev
            fi
            f_pack_is_inst "dh-exec" "apt-get" "\"dh-exec\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install dh-exec
            fi
            f_pack_is_inst "libpq-dev" "apt-get" "\"libpq-dev\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install libpq-dev
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_pack_is_inst "gcc-c++" "zypper" "\"gcc-c++\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install gcc-c++
            fi
            if [[ "$DISTRO_NAME" != "SLES" ]] ; then
                f_pack_is_inst "automake" "zypper" "\"automake\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    zypper --non-interactive install automake
                fi
                f_pack_is_inst "make" "zypper" "\"make\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    zypper --non-interactive install make
                fi
                f_pack_is_inst "libtool" "zypper" "\"libtool\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    zypper --non-interactive install libtool
                fi
                f_pack_is_inst "autoconf" "zypper" "\"autoconf\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    zypper --non-interactive install autoconf
                fi
            fi
            f_pack_is_inst "zlib-devel" "zypper" "\"zlib-devel\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install zlib-devel
            fi
            f_pack_is_inst "libopenssl-devel" "zypper" "\"libopenssl-devel\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install libopenssl-devel
            fi
            f_pack_is_inst "postgresql-devel" "zypper" "\"postgresql-devel\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install postgresql-devel
            fi
        fi
        F_COM_PKS_INSTALLED=1
    fi
}

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

# > -----------------------------------------
# Passa comando para serviços conforme a distro em execução!

f_svc_helper() {
    : 'Passa comando para serviços conforme a distro em execução.

    Args:
        SVC_HLP_NM_P (str): Nome do serviço.
        SVC_HLP_CMD_P (str): Comando para o serviço executar.
        SVC_HLP_IN_SILENCE (Optional[int]): 1 - Sem saída para o terminal; 
            0 - Com saída para o terminal. Padrão 0.
    '
    SVC_HLP_NM_P=$1
    SVC_HLP_CMD_P=$2
    SVC_HLP_IN_SILENCE=$3
    if [ -z "$SVC_HLP_IN_SILENCE" ] ; then
        SVC_HLP_IN_SILENCE=0
    fi
    SVC_HLP_SILENCE_CMD=""
    if [ ${SVC_HLP_IN_SILENCE} -eq 1 ] ; then
        SVC_HLP_SILENCE_CMD=" &>/dev/null"
    fi
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        eval "systemctl $SVC_HLP_CMD_P $SVC_HLP_NM_P.service$SVC_HLP_SILENCE_CMD"
    elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        eval "service $SVC_HLP_NM_P $SVC_HLP_CMD_P$SVC_HLP_SILENCE_CMD"
    elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        eval "service $SVC_HLP_NM_P $SVC_HLP_CMD_P$SVC_HLP_SILENCE_CMD"
    fi
}

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

# > -----------------------------------------
# Abrir o firewall para uma porta definida para um dado serviço

f_fire_hlp() {
    : 'Abrir o firewall para uma porta definida para um dado serviço.

    Args:
        FIRE_SVC_NM_P (str): Nome do serviço.
        FIRE_PORT_P (int): Porta a ser aberta.
    '

    FIRE_SVC_NM_P=$1
    FIRE_PORT_P=$2
    if [[ "$DISTRO_TYPE" == "RH" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            f_div_section
            f_yes_no "Open firewall for $FIRE_SVC_NM_P (TCP $FIRE_PORT_P)?"
            if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
                f_chk_iptables $FIRE_PORT_P "Port $FIRE_PORT_P is already open!" 0 "ACCEPT" "tcp" "NEW"
                if [ ${F_CHK_IPTABLES_R} -eq 1 ] ; then
                    firewall-cmd --zone=public --add-port=$FIRE_PORT_P/tcp --permanent
                    firewall-cmd --reload
                fi
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_div_section
            f_yes_no "Open firewall for $FIRE_SVC_NM_P (TCP $FIRE_PORT_P)?"
            if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
                f_chk_iptables $FIRE_PORT_P "Port $FIRE_PORT_P is already open!" 0 "ACCEPT" "tcp"
                if [ ${F_CHK_IPTABLES_R} -eq 1 ] ; then
                    SuSEfirewall2 open EXT TCP $FIRE_PORT_P
                    SuSEfirewall2 stop
                    SuSEfirewall2 start
                fi
            fi
        fi
    fi
}

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

# > --------------------------------------------------------------------------
# INSTALAÇÃO DO ElasticSearch!
# --------------------------------------

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

ES_INST=0
ES_NAME="Elasticsearch 1.7.5"
ES_SERV_CMD="/etc/init.d/elasticsearch"
EZ_I_SKIP_ON_V=$FAST_INST
f_open_section
f_div_section
f_yes_no "Install $ES_NAME?"
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_chk_by_path_hlp "/usr/local/elasticsearch" "d" "\"elasticsearch-1.7.5.tar.gz\" already installed in \"/usr/local/elasticsearch\"!"
    F_BAK_MD_R=1
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_ez_mv_bak "/usr/local/elasticsearch" "Backup old version and update/reinstall? (\"y\" recommended)"
        if [ ${F_BAK_MD_R} -eq 1 ] ; then
            $ES_SERV_CMD stop &>/dev/null
            cd "$F_BAK_PATH_R"
            cd ..
            tar -cvvzf "$F_BAK_NAME_R.tar.gz" "./$F_BAK_NAME_R"
            rm -rf "$F_BAK_PATH_R"
        fi
    fi
    if [ ${F_BAK_MD_R} -eq 1 ] ; then
        f_common_packs
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            f_pack_is_inst "java-1.8.0-openjdk" "yum" "\"java-1.8.0-openjdk\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install java-1.8.0-openjdk
            fi
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_pack_is_inst "openjdk-7-jdk" "apt-get" "\"openjdk-7-jdk\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install openjdk-7-jdk
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_pack_is_inst "java-1_7_0-openjdk" "zypper" "\"java-1_7_0-openjdk\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install java-1_7_0-openjdk
            fi
        fi
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        tar -zxvf elasticsearch-1.7.5.tar.gz
        mv elasticsearch-1.7.5 /usr/local/elasticsearch
        tar -zxvf elasticsearch-servicewrapper-master.tar.gz
        mv elasticsearch-servicewrapper-master/service /usr/local/elasticsearch/bin/
        rm -rf elasticsearch-servicewrapper-master
        /usr/local/elasticsearch/bin/service/elasticsearch install
        f_div_section

        # NOTE: [ref.: https://stackoverflow.com/questions/16432300/how-to-config-single-node-for-single-cluster-standalone-cluster-elasticsearch]! By Questor
        f_yes_no "Use $ES_NAME as single node (standalone server) (\"y\" highly recommended)?
* It will not be accessible to others servers (nodes) and will not discover others servers (nodes);
* This prevents erroneous and improper replication of your indexes."
        if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
            f_ez_sed "#http.jsonp.enable: true" "#http.jsonp.enable: true\n\n# It will not be accessible to others server (nodes) and will not discover\n# other server (nodes).\nnode.local: true" "/usr/local/elasticsearch/config/elasticsearch.yml"
        fi
        $ES_SERV_CMD start
        f_fire_hlp "elasticsearch" 9200
    fi
    ES_INST=1
fi
f_close_section

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

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

# > --------------------------------------------------------------------------
# INSTALAÇÃO DO POSTGRESQL!
# --------------------------------------

# > -----------------------------------------
# Configurar o postgresql!

CONF_PG=0
PG_USER_F="lbu"
PG_PWD_F="lbu"
f_conf_postgresql() {
    EZ_I_SKIP_ON_V=0
    f_div_section
    f_yes_no "Configure $PG_NAME (use \"y\" if you never did it)?"
    PG_EXT_ACS_F=""
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        PG_HBA_PATH="/var/lib/pgsql/9.4/data/pg_hba.conf"
        PG_CONF_PATH="/var/lib/pgsql/9.4/data/postgresql.conf"
    elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        if [[ "$DISTRO_NAME" == "Debian" ]] ; then
            PG_HBA_PATH="/etc/postgresql/9.4/main/pg_hba.conf"
            PG_CONF_PATH="/etc/postgresql/9.4/main/postgresql.conf"
        else
            PG_HBA_PATH="/etc/postgresql/9.3/main/pg_hba.conf"
            PG_CONF_PATH="/etc/postgresql/9.3/main/postgresql.conf"
        fi
    elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        PG_HBA_PATH="/var/lib/pgsql/data/pg_hba.conf"
        PG_CONF_PATH="/var/lib/pgsql/data/postgresql.conf"
    fi
    if [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        if [[ "$DISTRO_TYPE" == "DEB" ]] && [[ "$DISTRO_NAME" == "Debian" ]] ; then
            f_pack_is_inst "sudo" "apt-get" "\"sudo\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install sudo
            fi
        fi
        QUESTION_F="Enter the $PG_NAME user for LBG - LBGenerator. 
Use empty for \"$PG_USER_F\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            PG_USER_F=$GET_USR_INPUT_R
        fi
        QUESTION_F="Enter the $PG_NAME password for \"$PG_USER_F\". 
Use empty for \"$PG_PWD_F\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            PG_PWD_F=$GET_USR_INPUT_R
        fi
        QUESTION_F="Enter one ip or ip range for external access.
Use empty for local access only!
* 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!"
        f_div_section
        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
        QUESTION_F="Enter the maximum number of $PG_NAME connections (numbers only, integers only).
Use empty for $PG_CONNECTIONS connections (default)!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            PG_CONNECTIONS=$GET_USR_INPUT_R
        fi
        EZ_I_SKIP_ON_V=0
        f_svc_helper "$PG_SERV_NAME" "start" 1
        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=$FAST_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=$FAST_INST
        if [ -n "$PG_EXT_ACS_F" ] ; then
            f_fl_cont_str "host    all             all             $PG_EXT_ACS_F            trust" "$PG_HBA_PATH" "The file \"$PG_HBA_PATH\" probably has already been changed to enable 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" "$PG_HBA_PATH"
            fi
        fi
        f_fl_cont_str "host    all             all             127.0.0.1/32            trust" "$PG_HBA_PATH" "The file \"$PG_HBA_PATH\" probably has already been changed to enable 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" "$PG_HBA_PATH"
        fi
        f_fl_cont_str "listen_addresses = '*'" "$PG_CONF_PATH" "The file \"$PG_CONF_PATH\" probably has already been changed to set \"listen addresses\"! Check it!"
        if [ ${FL_CONT_STR_R} -eq 0 ] ; then
            f_ez_sed "# - Connection Settings -" "# - Connection Settings -\n\nlisten_addresses = '*'" "$PG_CONF_PATH"
        fi
        f_fl_cont_str "#max_connections = 100" "$PG_CONF_PATH" "The file \"$PG_CONF_PATH\" probably has already been changed to set \"maximum number connections\"! Check it!"
        if [ ${FL_CONT_STR_R} -eq 0 ] ; then
            f_ez_sed "max_connections = 100" "#max_connections = 100\nmax_connections = $PG_CONNECTIONS" "$PG_CONF_PATH"
        fi
        f_svc_helper "$PG_SERV_NAME" "restart"
        f_enter_to_cont "The files \"$PG_HBA_PATH\" and \"$PG_CONF_PATH\" has settings for $PG_NAME! Check it for more details!"
        EZ_I_SKIP_ON_V=0
        CONF_PG=1
    else
        f_enter_to_cont "The files \"$PG_HBA_PATH\" and \"$PG_CONF_PATH\" has settings for $PG_NAME! Check it for more details!"
    fi
}

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

# > -----------------------------------------
# Instalar o postgresql!

PG_INST=0
PG_NAME=""
PG_SERV_NAME=""
PG_PACK_NAME=""
PG_CONNECTIONS=100
if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    PG_NAME="PostgreSQL 9.4"
    PG_SERV_NAME="postgresql-9.4"
    if [[ "$DISTRO_NAME" == "RedHat" ]] ; then
        PG_PACK_NAME="pgdg-redhat94-9.4-3.noarch.rpm"
    else
        PG_PACK_NAME="pgdg-centos94-9.4-3.noarch.rpm"
    fi
elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
    if [[ "$DISTRO_NAME" == "Debian" ]] ; then
        PG_NAME="PostgreSQL 9.4"
        PG_SERV_NAME="postgresql"
        PG_PACK_NAME="postgresql-9.4"
    else
        PG_NAME="PostgreSQL 9.3"
        PG_SERV_NAME="postgresql"
        PG_PACK_NAME="postgresql-9.3"
    fi
elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
    if [[ "$DISTRO_NAME" == "SLES" ]] ; then
        PG_NAME="PostgreSQL 9.4"
        PG_SERV_NAME="postgresql"
        PG_PACK_NAME="postgresql94-server"
    else
        PG_NAME="PostgreSQL 9.3"
        PG_SERV_NAME="postgresql"
        PG_PACK_NAME="postgresql93-server"
    fi
fi
EZ_I_SKIP_ON_V=$FAST_INST
f_open_section
f_div_section
f_yes_no "Install $PG_NAME?"
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    f_common_packs
    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        f_pack_is_inst "postgresql94-server" "yum" "\"postgresql94-server\" already installed!"
        if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
            yum -y localinstall $PG_PACK_NAME
            yum -y install postgresql94-server
            /usr/pgsql-9.4/bin/postgresql94-setup initdb
            f_svc_helper "$PG_SERV_NAME" "enable"
        fi
    elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        f_pack_is_inst "$PG_PACK_NAME" "apt-get" "\"$PG_PACK_NAME\" already installed!"
        if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
            apt-get -y install $PG_PACK_NAME
            update-rc.d -f $PG_SERV_NAME remove
            update-rc.d $PG_SERV_NAME defaults
        fi
    elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        f_pack_is_inst "$PG_PACK_NAME" "zypper" "\"$PG_PACK_NAME\" already installed!"
        if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
            zypper --non-interactive install $PG_PACK_NAME
            chkconfig $PG_SERV_NAME on
        fi
    fi
    f_svc_helper "$PG_SERV_NAME" "start"
    f_conf_postgresql
    f_fire_hlp "$PG_NAME" 5432
    PG_INST=1
fi
f_close_section

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

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

CREATE_LB_DT=0
EZ_I_SKIP_ON_V=0
PG_DB_F="lb"
f_open_section
f_div_section
f_yes_no "Create the basic LBG - LBGenerator data structures in $PG_NAME (use \"y\" if you never did it)?"
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
    EZ_I_SKIP_ON_V=$FAST_INST
    QUESTION_F="Enter the $PG_NAME database name for LBG - LBGenerator. 
Use empty for \"$PG_DB_F\" (recommended)!"
    f_div_section
    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_R_HOLDER_0=""
        LINE_BREAKS_0=""
        EZ_I_SKIP_ON_V=$FAST_INST
        # NOTE: Define o "LC_COLLATE" e o "LC_CTYPE" para a database criada. 
        # Não é necessário, mas se u usuário quiser, tem a opção! By Questor
        LC_C_PG="$LANG"
        f_div_section
        f_get_usr_input "Enter the \"LC_COLLATE\"/\"LC_CTYPE\" for \"$PG_DB_F\" database (E.g. en_US.UTF-8, pt_BR.UTF-8...). 
Use empty for \"$LANG\" (system default)!" 1
        if [ -n "$GET_USR_INPUT_R" ] ; then
            LC_C_PG=$GET_USR_INPUT_R
        fi
        f_get_stderr_stdout "sudo -u postgres psql -c \"CREATE DATABASE $PG_DB_F WITH ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = '$LC_C_PG' LC_CTYPE = '$LC_C_PG' CONNECTION LIMIT = -1;\""
        F_GET_STDERR_R_HOLDER_0=$F_GET_STDERR_R_HOLDER_0$F_GET_STDERR_R
        f_get_stderr_stdout "sudo -u postgres psql -c \"ALTER DATABASE $PG_DB_F SET DateStyle = 'iso, dmy';\""
        if [[ $F_GET_STDERR_R_HOLDER_0 != "" ]]; then
            LINE_BREAKS_0="\n\n"
        fi
        F_GET_STDERR_R_HOLDER_0=$F_GET_STDERR_R_HOLDER_0$LINE_BREAKS_0$F_GET_STDERR_R
        if [[ $F_GET_STDERR_R_HOLDER_0 != "" ]]; then
            if [[ $F_GET_STDERR_R_HOLDER_0 == *" already exists"* ]]; then
                EZ_I_SKIP_ON_V=$FAST_INST
                f_enter_to_cont "The database \"$PG_DB_F\" already created!"
                EZ_I_SKIP_ON_V=0
            else
                EZ_I_SKIP_ON_V=0
                f_div_section
                echo "Error when creating \"$PG_DB_F\" database! ERROR: \"$F_GET_STDERR_R_HOLDER_0\"."
                f_div_section
                f_error_exit
            fi
        else
            cd "$SCRIPTDIR_V"
            cp ./lbn-basic-dt-strt/lb_basic_dt_strt.sql /tmp
            cd /tmp
            chmod 700 lb_basic_dt_strt.sql
            chown postgres lb_basic_dt_strt.sql
            chown :postgres lb_basic_dt_strt.sql
            sudo -u postgres psql $PG_DB_F -f lb_basic_dt_strt.sql
            rm -f lb_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/lb_basic_dt_strt.sql\" has the basic LBG - LBGenerator data structures! Check it!"
fi
f_close_section

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

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

# > --------------------------------------------------------------------------
# INSTALAÇÃO DO LBG - LBGenerator!
# --------------------------------------

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

f_create_base_dir() {
    f_chk_by_path_hlp "$BASE_INST_DIR_V" "d"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        mkdir -p "$BASE_INST_DIR_V"
    fi
}

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

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

f_inst_py32() {
    : 'Instala a Python3.2!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi

    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install python3.2?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        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
            f_common_packs
            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
        fi
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

f_inst_ve_py32() {
    : 'Instala o virtualenv-1.11.6 no python3.2!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install virtualenv-1.11.6 on python3.2?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        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
            f_common_packs
            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
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

f_create_ve32() {
    : 'Cria o ambiente virtual (python3.2)!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    criar. Padrão 0.
        VE_NAME (str): Nome do virtualenv a ser criado.
    '

    DONT_PROMPT_TO_INST=$1
    VE_NAME=$2
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    f_enter_to_cont "Create the virtual environment (python3.2)!"
    EZ_I_SKIP_ON_V=$FAST_INST
    f_chk_by_path_hlp "$BASE_INST_DIR_V/$VE_NAME" "d" "Virtual environment (python3.2) already created in \"$BASE_INST_DIR_V/$VE_NAME\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            f_pack_is_inst "python-setuptools" "yum" "\"python-setuptools\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install python-setuptools
            fi
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_pack_is_inst "python-setuptools" "apt-get" "\"python-setuptools\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install python-setuptools
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_pack_is_inst "python-setuptools" "zypper" "\"python-setuptools\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install python-setuptools
            fi
        fi
        f_common_packs
        cd "$BASE_INST_DIR_V"
        $BASE_INST_DIR_V/py32/bin/virtualenv-3.2 $VE_NAME
        mkdir "$BASE_INST_DIR_V/$VE_NAME/src"
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > -----------------------------------------
# Determine an appropriate amount of processes!

NPROCESSES=0
f_num_for_procs() {
    : 'Determine an appropriate amount of processes.'

    if (( NPROCESSES == 0 )) ; then
        f_get_stderr_stdout "nproc"
        if [[ $F_GET_STDERR_R == "" ]]; then

            # NOTE: Esse é o cálculo recomendado segundo algumas fontes. Eu 
            # preferi fazer pelo dobro da quantidade de "cores" obtidas! 
            # By Questor
            # (2 Workers * CPU Cores) + 1
            # ---------------------------
            # Para 1 core -> (2*1)+1 = 3
            # Para 2 cores -> (2*2)+1 = 5
            # Para 4 cores -> (2*4)+1 = 9
            NPROCESSES=$(( F_GET_STDOUT_R * 2 ))
            f_div_section
            f_get_usr_input "The recommended amount of processes to use on this server is \"$NPROCESSES\". 
Use empty for \"$NPROCESSES\" (recommended)!" 1
            if [ -n "$GET_USR_INPUT_R" ] ; then
                NPROCESSES=$GET_USR_INPUT_R
            fi
        else
            f_enter_to_cont "An error occurred when trying to determine an appropriate amount of processes to use on this server! ERROR: \"$F_GET_STDERR_R$F_GET_STDOUT_R\"."
            f_error_exit
        fi
    fi
}

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

# > -----------------------------------------
# Instalar o NGINX (nginx)!

NGINX_INST=0
f_inst_nginx() {
    : 'Instala o Nginx e seta uma porta diferente se esse for o caso!

    Args:
        NGINX_PORT (Optional[int]): Porta a ser configurada para o Nginx. 
    Padrão 8008.
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    NGINX_PORT=$1
    if [ -z "$NGINX_PORT" ] ; then
        NGINX_PORT=8008
    fi
    DONT_PROMPT_TO_INST=$2
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install NGINX as load balancer (\"y\" highly recommended)?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_common_packs
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            f_pack_is_inst "pcre-devel" "yum" "\"pcre-devel\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install pcre-devel
            fi
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_pack_is_inst "libpcre3-dev" "apt-get" "\"libpcre3-dev\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install libpcre3-dev
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_pack_is_inst "pcre-devel" "zypper" "\"pcre-devel\" already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install pcre-devel
            fi
        fi
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        UP_NGINX=1
        f_chk_by_path_hlp "/usr/sbin/nginx" "f" "\"NGINX\" already installed in \"/etc/nginx\"!"
        if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
            f_div_section
            f_yes_no "Update/reinstall \"NGINX\"? (\"y\" recommended)"
            UP_NGINX=$YES_NO_R
        fi
        if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${UP_NGINX} -eq 1 ] ; then
            tar -zxvf nginx-1.8.1.tar.gz
            cd ./nginx-1.8.1
            ./configure                              \
           --user=nginx                              \
           --group=nginx                             \
           --prefix=/etc/nginx                       \
           --sbin-path=/usr/sbin/nginx               \
           --conf-path=/etc/nginx/nginx.conf         \
           --pid-path=/var/run/nginx.pid             \
           --lock-path=/var/run/nginx.lock           \
           --error-log-path=/var/log/nginx/error.log \
           --http-log-path=/var/log/nginx/access.log \
           --with-http_gzip_static_module            \
           --with-http_stub_status_module            \
           --with-http_ssl_module                    \
           --with-pcre                               \
           --with-file-aio                           \
           --with-http_realip_module
            make -j 4 && make install
            cd ..
            if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                mkdir "$NGINX_CONF_PATH" &>/dev/null
                mkdir "$NGINX_CONF_PATH_E" &>/dev/null
            elif [[ "$DISTRO_TYPE" == "RH" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
                mkdir "$NGINX_CONF_PATH" &>/dev/null
            fi
            rm -rf ./nginx-1.8.1
        fi

        # NOTE: Criar o usuário "nginx" caso não exista! By Questor
        if [ -z "`grep nginx /etc/passwd`" ]; then
            useradd -M -s /sbin/nologin nginx
            groupadd nginx &>/dev/null
        fi
        f_ez_mv_bak "/etc/nginx/nginx.conf"
        if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
            EZ_I_SKIP_ON_V=1
        else
            EZ_I_SKIP_ON_V=$FAST_INST
        fi
        f_enter_to_cont "Backup of \"/etc/nginx/nginx.conf\" original file on \"$F_BAK_PATH_R\"!"
        EZ_I_SKIP_ON_V=$FAST_INST
        \cp "$SCRIPTDIR_V/other-srcs-n-apps/nginx.conf-dist" "/etc/nginx/nginx.conf"

        # NOTE: Determinar um número adequado de processos! By Questor
        f_procs_qtt 2

        f_ez_sed "<PROCESSES_QTT>" "$F_PROCS_QTT_R" "/etc/nginx/nginx.conf"
        f_ez_sed "<NGINX_PORT>" "$NGINX_PORT" "/etc/nginx/nginx.conf"
        if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_ez_sed "<SITES_ENABLED>" "\n    include /etc/nginx/sites-enabled/*;" "/etc/nginx/nginx.conf"
        else
            f_ez_sed "<SITES_ENABLED>" "" "/etc/nginx/nginx.conf"
        fi
        rm -rf "/etc/init.d/nginx"
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/nginx-RHEL-dist" "/etc/init.d/nginx"
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/nginx-DEB-dist" "/etc/init.d/nginx"
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/nginx-SLES-dist" "/etc/init.d/nginx"
        fi
        cd /etc/init.d/
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            chmod 755 nginx
            chkconfig --add nginx &>/dev/null
            chkconfig --level 345 nginx on
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then

            # TODO: A linha logo abaixo é realmente necessária? Rever p/ os outros instaladores tb! By Questor
            chmod 755 nginx
            chkconfig --add nginx &>/dev/null
            chkconfig --level 345 nginx on
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            update-rc.d -f nginx remove &>/dev/null
            chmod +x ./nginx
            update-rc.d nginx defaults
        fi
        f_svc_helper "nginx" "restart" 1
        NGINX_INST=1
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

HTTPD_SERV_NAME=""
HTTPD_USR=""
HTTPD_GRP=""
HTTPD_DEF_DOC_ROOT=""
APACHE_INST=0
if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    HTTPD_SERV_NAME="httpd"
    HTTPD_USR="apache"
    HTTPD_GRP="apache"
    HTTPD_DEF_DOC_ROOT="/var/www"
elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
    HTTPD_SERV_NAME="apache2"
    HTTPD_USR="www-data"
    HTTPD_GRP="www-data"
    HTTPD_DEF_DOC_ROOT="/var/www"
elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
    HTTPD_SERV_NAME="apache2"
    HTTPD_USR="wwwrun"
    HTTPD_GRP="www"
    HTTPD_DEF_DOC_ROOT="/srv/www"
fi

f_inst_apache() {
    : 'Instala o Apache e seta uma porta diferente se esse for o caso!

    Args:
        APACHE_PORT (Optional[int]): Porta a ser configurada para o Apache. 
    Padrão 80.
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    APACHE_PORT=$1
    if [ -z "$APACHE_PORT" ] ; then
        APACHE_PORT=80
    fi
    DONT_PROMPT_TO_INST=$2
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install Apache ($HTTPD_SERV_NAME)?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_common_packs
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            f_pack_is_inst "httpd-devel" "yum" "Apache ($HTTPD_SERV_NAME) already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                yum -y install httpd-devel httpd
                f_svc_helper "$HTTPD_SERV_NAME" "enable"
                if (( $APACHE_PORT != 80 )); then
                    f_fl_cont_str "# Listen 80" "$HTTPD_CONF_PATH_MAIN/httpd.conf" "The file \"$HTTPD_CONF_PATH_MAIN/httpd.conf\" probably has already been changed! Check it!"
                    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
                        f_ez_sed "Listen 80" "# Listen 80\nListen $APACHE_PORT" "$HTTPD_CONF_PATH_MAIN/httpd.conf"
                    fi
                fi
            fi
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_pack_is_inst "apache2-dev" "apt-get" "Apache ($HTTPD_SERV_NAME) already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                apt-get -y install apache2-dev apache2
                update-rc.d -f $HTTPD_SERV_NAME remove
                update-rc.d $HTTPD_SERV_NAME defaults
                if (( $APACHE_PORT != 80 )); then
                    f_fl_cont_str "# Listen 80" "$HTTPD_CONF_PATH_MAIN/ports.conf" "The file \"$HTTPD_CONF_PATH_MAIN/ports.conf\" probably has already been changed! Check it!"
                    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
                        f_ez_sed "Listen 80" "# Listen 80\nListen $APACHE_PORT" "$HTTPD_CONF_PATH_MAIN/ports.conf"
                    fi
                    f_fl_cont_str "# <VirtualHost *:80>" "$HTTPD_CONF_PATH/000-default.conf" "The file \"$HTTPD_CONF_PATH/000-default.conf\" probably has already been changed! Check it!"
                    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
                        f_ez_sed "<VirtualHost *:80>" "# <VirtualHost *:80>\n<VirtualHost *:$APACHE_PORT>" "$HTTPD_CONF_PATH/000-default.conf"
                        rm -f "$HTTPD_CONF_PATH_E/000-default.conf" &>/dev/null
                        ln -s "$HTTPD_CONF_PATH/000-default.conf" "$HTTPD_CONF_PATH_E/000-default.conf" &>/dev/null
                    fi
                fi
            fi
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_pack_is_inst "apache2-devel" "zypper" "Apache ($HTTPD_SERV_NAME) already installed!"
            if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                zypper --non-interactive install apache2-devel apache2
                chkconfig apache2 on
                if (( $APACHE_PORT != 80 )); then
                    f_fl_cont_str "# Listen 80" "$HTTPD_CONF_PATH_MAIN/listen.conf" "The file \"$HTTPD_CONF_PATH_MAIN/listen.conf\" probably has already been changed! Check it!"
                    if [ ${FL_CONT_STR_R} -eq 0 ] ; then
                        f_ez_sed "Listen 80" "# Listen 80\nListen $APACHE_PORT" "$HTTPD_CONF_PATH_MAIN/listen.conf" 0 0 1 0 1
                    fi
                fi
            fi
        fi
        eval "chown -R $HTTPD_USR $HTTPD_DEF_DOC_ROOT"
        eval "chown -R :$HTTPD_GRP $HTTPD_DEF_DOC_ROOT"
        eval "chmod -R 755 $HTTPD_DEF_DOC_ROOT"
        f_svc_helper "$HTTPD_SERV_NAME" "restart" 1
        APACHE_INST=1
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

MOD_WSGI_PATH=""
f_inst_mod_wsgi() {
    : 'Instala o mod_wsgi!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        MOD_WSGI_PATH="/usr/lib64/httpd/modules/mod_wsgi.so"
    elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        MOD_WSGI_PATH="/usr/lib/apache2/modules/mod_wsgi.so"
    elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        MOD_WSGI_PATH="/usr/lib64/apache2/mod_wsgi.so"
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install mod_wsgi-4.3.2?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_common_packs
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            REPLACE_REF="include ld.so.conf.d/*.conf"
        elif [[ "$DISTRO_TYPE" == "DEB" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            REPLACE_REF="include /etc/ld.so.conf.d/*.conf"
        fi
        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 "$REPLACE_REF" "$REPLACE_REF\n$BASE_INST_DIR_V/py32/lib" "/etc/ld.so.conf"
        fi
        UP_MOD_WSGI=1
        f_chk_by_path_hlp "$MOD_WSGI_PATH" "f" "mod_wsgi already installed in \"$MOD_WSGI_PATH\"!"
        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"
                TITLE_F=""
                UP_MOD_WSGI=$YES_NO_R
                if [ ${UP_MOD_WSGI} -eq 1 ] ; then
                    rm -rf "$MOD_WSGI_PATH"
                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
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

f_inst_lib_py_packs() {
    : 'Instala a liblightbase!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    cd "$SCRIPTDIR_V"
    bash py-packs-liblightbase.bash "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V"
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > -----------------------------------------
# Instalar as dependências python do uWSGI!

f_inst_uwsgi_py_packs() {
    : 'Instala as dependências do uwsgi!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    cd "$SCRIPTDIR_V"
    bash py-packs-uwsgi.bash "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V"
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

UWSGI_INST=0
# > -----------------------------------------
# Instalar e configurar o uWSGI!

f_inst_uwsgi() {
    : 'Instala o uWSGI!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install the uWSGI?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_inst_uwsgi_py_packs 1
        rm -f "/etc/init.d/uwsgi"
        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/uwsgi-RHEL-dist" "/etc/init.d/uwsgi"
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/uwsgi-SLES-dist" "/etc/init.d/uwsgi"
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/uwsgi-DEB-dist" "/etc/init.d/uwsgi"
        fi
        f_ez_sed "<UWSGI_VE32_PATH>" "$BASE_INST_DIR_V/uwsgi_ve32" "/etc/init.d/uwsgi" 1

        # NOTE: Criar o usuário "uwsgi" caso não exista! By Questor
        if [ -z "`grep uwsgi /etc/passwd`" ]; then
            useradd -M -s /sbin/nologin uwsgi
            groupadd uwsgi &>/dev/null
        fi
        cd /etc/init.d/

        # NOTE: Cria configurações e diretórios para que o uWSGI opere no modo 
        # "emperor"! By Questor
        mkdir -p "$BASE_INST_DIR_V/uwsgi_ve32/src/uWSGI/vassals"
        \cp "$SCRIPTDIR_V/other-srcs-n-apps/production.ini.uwsgi.srv-dist" "$BASE_INST_DIR_V/uwsgi_ve32/src/uWSGI/production.ini"
        f_ez_sed "<UWSGI_VE32_PATH>" "$BASE_INST_DIR_V/uwsgi_ve32" "$BASE_INST_DIR_V/uwsgi_ve32/src/uWSGI/production.ini"

        if [[ "$DISTRO_TYPE" == "RH" ]] ; then
            chmod 755 uwsgi
            chkconfig --add uwsgi &>/dev/null
            chkconfig --level 345 uwsgi on
        elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then

            # TODO: A linha logo abaixo é realmente necessária? Rever p/ os outros instaladores tb! By Questor
            chmod 755 uwsgi
            chkconfig --add uwsgi &>/dev/null
            chkconfig --level 345 uwsgi on
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            update-rc.d -f uwsgi remove &>/dev/null
            chmod +x ./uwsgi
            update-rc.d uwsgi defaults
        fi
        f_svc_helper "uwsgi" "restart" 1
        UWSGI_INST=1
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

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

f_inst_lib() {
    : 'Instala a liblightbase!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install the LIB - liblightbase?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_chk_by_path_hlp "$BASE_INST_DIR_V/lbg_ve32/src/liblightbase" "d" "\"liblightbase\" already installed in \"$BASE_INST_DIR_V/lbg_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/lbg_ve32/src/liblightbase" "Backup old version and update? (\"y\" recommended)"
        fi
        if [ ${F_BAK_MD_R} -eq 1 ] ; then
            f_inst_lib_py_packs 1
            cd "$SCRIPTDIR_V"
            tar -zxvf liblightbase.tar.gz
            mv "$SCRIPTDIR_V/liblightbase" "$BASE_INST_DIR_V/lbg_ve32/src/"
            cd "$BASE_INST_DIR_V/lbg_ve32/src/liblightbase"
            eval "$BASE_INST_DIR_V/lbg_ve32/bin/python3.2 setup.py install"
        fi
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > -----------------------------------------
# Instalar as dependências python do LBG - LBGenerator!

f_inst_lbg_py_packs() {
    : 'Instala as dependências do LBG - LBGenerator!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    cd "$SCRIPTDIR_V"
    bash py-packs-LBGenerator.bash "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V"
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > --------------------------------------------------------------------------
# Instalar o supervisor!
# -----------------------------------------

# > -----------------------------------------
# Instalar o virtualenv-1.11.6 no python2.X!

PYTHON_2_X=""
VE_2_X=""
f_inst_ve_py2X() {
    : 'Instala a virtualenv no Python2.X!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        PYTHON_2_X="2.7"
        VE_2_X="supervisor_ve27"
    elif [[ "$DISTRO_TYPE" == "DEB" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        PYTHON_2_X="2.7"
        VE_2_X="supervisor_ve27"
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install virtualenv-1.11.6 on python$PYTHON_2_X?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        if [[ "$DISTRO_TYPE" == "RH" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
            f_chk_by_path_hlp "/usr/bin/virtualenv-$PYTHON_2_X" "f" "virtualenv-1.11.6 already installed!"
        elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
            f_chk_by_path_hlp "/usr/local/bin/virtualenv-$PYTHON_2_X" "f" "virtualenv-1.11.6 already installed!"
        fi
        if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
            if [[ "$DISTRO_TYPE" == "RH" ]] ; then
                f_pack_is_inst "python-setuptools" "yum" "\"python-setuptools\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    yum -y install python-setuptools
                fi
            elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                f_pack_is_inst "python-setuptools" "apt-get" "\"python-setuptools\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    apt-get -y install python-setuptools
                fi
            elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
                # >>>>>>>>>>>>> * Para "zypper --non-interactive install python-setuptools", se o problema abaixo aparecer...

                # Problem: python-setuptools-5.4.1-2.1.4.noarch requires python, but this requirement cannot be provided
                #   uninstallable providers: python-2.7.8-1.1.x86_64[openSUSE-13.2-0]
                #                    python3-3.4.1-4.2.1.x86_64[openSUSE-13.2-0]
                #                    python-2.7.8-1.1.i586[repo-oss]
                #                    python3-3.4.1-4.2.1.i586[repo-oss]
                #                    python-2.7.8-1.1.x86_64[repo-oss]
                #                    python3-3.4.1-4.2.1.x86_64[repo-oss]
                #  Solution 1: deinstallation of patterns-openSUSE-minimal_base-conflicts-20141007-2.1.x86_64
                #  Solution 2: do not install python-setuptools-5.4.1-2.1.4.noarch
                #  Solution 3: do not install python-setuptools-5.4.1-2.1.4.noarch
                #  Solution 4: break python-setuptools-5.4.1-2.1.4.noarch by ignoring some of its dependencies

                # Choose from above solutions by number or cancel [1/2/3/4/c] (c): 

                # <<<<<<<<<<<<<

                # >>>>>>>>>>>>> * Usar 1 e y...

                # Choose from above solutions by number or cancel [1/2/3/4/c] (c): 1
                # Resolving dependencies...
                # Resolving package dependencies...

                # The following 4 NEW packages are going to be installed:
                #   libsqlite3-0 python python-setuptools python-xml 

                # The following package is going to be REMOVED:
                #   patterns-openSUSE-minimal_base-conflicts 

                # The following pattern is going to be REMOVED:
                #   minimal_base-conflicts 

                # 4 new packages to install, 1 to remove.
                # Overall download size: 1.1 MiB. Already cached: 0 B  After the operation, additional 4.2 MiB will be used.
                # Continue? [y/n/? shows all options] (y): 

                # <<<<<<<<<<<<<

                # f_pack_is_inst "python-setuptools" "zypper" "\"python-setuptools\" already installed!"
                # if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                #     zypper --non-interactive install python-setuptools
                #     zypper --non-interactive install python-devel
                # fi
                f_pack_is_inst "python-setuptools" "zypper" "\"python-setuptools\" already installed!"
                if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
                    f_get_stderr_stdout "zypper --non-interactive install python-setuptools"
                    if [[ $F_GET_STDERR_R$F_GET_STDOUT_R == *"Problem: python-setuptools-"* ]] && 
                        [[ $F_GET_STDERR_R$F_GET_STDOUT_R == *".noarch requires python, but this requirement cannot be provided"* ]] ; then
                        EZ_I_SKIP_ON_V=0
                        f_enter_to_cont "The package management \"zypper\" WILL ASK YOU FOR ADDITIONAL OPTIONS! 
We highly recommended you answer \"1\" and \"y\", respectively!"
                        EZ_I_SKIP_ON_V=$FAST_INST
                        zypper install python-setuptools
                        zypper --non-interactive install python-devel
                    else
                        echo "$F_GET_STDERR_R$F_GET_STDOUT_R"
                    fi
                fi
            fi
            f_common_packs
            cd "$SCRIPTDIR_V"
            cd ./other-srcs-n-apps
            tar -zxvf virtualenv-1.11.6.tar.gz
            cd virtualenv-1.11.6
            python$PYTHON_2_X setup.py install
            cd ..
            rm -rf virtualenv-1.11.6
        fi
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > -----------------------------------------
# Criar o ambiente virtual (python2.X)!

f_create_ve2X() {
    : 'Cria o ambiente virtual (python2.X)!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    criar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    f_enter_to_cont "Create the virtual environment (python$PYTHON_2_X)!"
    EZ_I_SKIP_ON_V=$FAST_INST
    f_chk_by_path_hlp "$BASE_INST_DIR_V/$VE_2_X" "d" "Virtual environment (python$PYTHON_2_X) already created in \"$BASE_INST_DIR_V/$VE_2_X\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 0 ] ; then
        f_common_packs
        cd "$BASE_INST_DIR_V"
        virtualenv-$PYTHON_2_X $VE_2_X
        mkdir "$BASE_INST_DIR_V/$VE_2_X/src"
    fi
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

# > -----------------------------------------
# Instalar as dependências python do supervisor!

f_inst_supervisor_py_packs() {
    : 'Instala as dependências do supervisor!

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi
    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
    fi
    cd "$SCRIPTDIR_V"
    bash py-packs-supervisor.bash "$EZ_I_SKIP_ON_V" "$BASE_INST_DIR_V" "$PYTHON_2_X" "$VE_2_X"
    EZ_I_SKIP_ON_V=$FAST_INST
}

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

SVISOR_PORT=9001
SVISOR_USER="lbu"
SVISOR_PWD="lbu"
SVISOR_INST=0
PROC_MAX_MEM_PERC=60

# > -----------------------------------------
# Instalar e configurar o supervisor!

f_inst_supervisor(){
    : 'Instalar e configurar o supervisor.

    Args:
        DONT_PROMPT_TO_INST (Optional[int]): Não questiona o usuário se deseja 
    instalar. Padrão 0.
    '

    DONT_PROMPT_TO_INST=$1
    if [ -z "$DONT_PROMPT_TO_INST" ] ; then
        DONT_PROMPT_TO_INST=0
    fi

    if [ ${DONT_PROMPT_TO_INST} -eq 1 ] || [ ${FAST_INST} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=1
    else
        EZ_I_SKIP_ON_V=$FAST_INST
        f_div_section
    fi
    f_yes_no "Install supervisor?"
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
        EZ_I_SKIP_ON_V=$FAST_INST
        f_inst_ve_py2X 1
        f_create_ve2X 1
        f_chk_by_path_hlp "$BASE_INST_DIR_V/$VE_2_X/src/supervisor" "d" "\"supervisor\" already installed in \"$BASE_INST_DIR_V/$VE_2_X/src/supervisor\"!"
        UP_SUPERVISOR=1
        if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
            f_div_section
            f_yes_no "Update/reinstall \"supervisor\"? (\"y\" recommended)"
            UP_SUPERVISOR=$YES_NO_R
        fi
        if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${UP_SUPERVISOR} -eq 1 ] ; then
            f_inst_supervisor_py_packs 1

            # NOTE: Configurar a aplicação supervisor! By Questor
            mkdir -p "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/apps" &>/dev/null

            f_ez_mv_bak "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf" "" 1 0 1
            f_ez_mv_bak "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/apps/lbg.conf" "" 1 0 1
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/supervisord.conf-dist" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf"
            \cp "$SCRIPTDIR_V/other-srcs-n-apps/lbg.conf-supervisord-dist" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/apps/lbg.conf"
            f_ez_sed "<LBG_VE32_PATH>" "$BASE_INST_DIR_V/lbg_ve32" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/apps/lbg.conf" 1

            # NOTE: Determinar um número adequado de processos! By Questor
            f_procs_qtt 2

            f_ez_sed "<NUM_OF_PROCS>" "$F_PROCS_QTT_R" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/apps/lbg.conf"
            QUESTION_F="Enter the port number for Supervisor service. 
Use empty for \"$SVISOR_PORT\" (recommended)!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                SVISOR_PORT=$GET_USR_INPUT_R
            fi
            f_ez_sed "<SVISOR_PORT>" "$SVISOR_PORT" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf"
            QUESTION_F="Enter the Supervisor user. 
Use empty for \"$SVISOR_USER\"!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                SVISOR_USER=$GET_USR_INPUT_R
            fi
            QUESTION_F="Enter the Supervisor password for \"$SVISOR_USER\". 
Use empty for \"$SVISOR_PWD\"!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                SVISOR_PWD=$GET_USR_INPUT_R
            fi
            f_ez_sed "<SVISOR_USER>" "$SVISOR_USER" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf"
            f_ez_sed "<SVISOR_PWD>" "$SVISOR_PWD" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf"
            f_ez_sed "<VE_2_X_PATH>" "$BASE_INST_DIR_V/$VE_2_X" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf" 1

            # NOTE: Calcula o máximo de memória que o LBG - LBGenerator pode usar do 
            # servidor! By Questor
            f_div_section
            f_get_usr_input "Enter the LBG - LBGenerator MAXIMUM PERCENT server RAM memory usage (numbers only, integers only). 
Use empty for \"$PROC_MAX_MEM_PERC\" (good for most cases)!
* Higher values will cause server instability, crash and other unexpected results;
* Lower values will cause LBG - LBGenerator service instability, crash and other unexpected results." 1
            if [ -n "$GET_USR_INPUT_R" ] ; then
                PROC_MAX_MEM_PERC=$GET_USR_INPUT_R
            fi
            f_srv_memory
            f_get_percent_from "$F_SRV_MEMORY_R" "$PROC_MAX_MEM_PERC"
            PROC_MAX_MEM=$F_GET_PERCENT_FROM_R
            f_ez_sed "<PROC_MAX_MEM>" "$PROC_MAX_MEM" "$BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf"
            rm -f "/etc/init.d/supervisord"
            if [[ "$DISTRO_TYPE" == "RH" ]] ; then
                \cp "$SCRIPTDIR_V/other-srcs-n-apps/supervisord-RHEL-dist" "/etc/init.d/supervisord"
            elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
                \cp "$SCRIPTDIR_V/other-srcs-n-apps/supervisord-SLES-dist" "/etc/init.d/supervisord"
            elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                \cp "$SCRIPTDIR_V/other-srcs-n-apps/supervisord-DEB-dist" "/etc/init.d/supervisord"
            fi
            f_ez_sed "<VE_2_X_PATH>" "$BASE_INST_DIR_V/$VE_2_X" "/etc/init.d/supervisord" 1

            # NOTE: Criar o usuário "supervisord" caso não exista! By Questor
            if [ -z "`grep supervisord /etc/passwd`" ]; then
                useradd -M -s /sbin/nologin supervisord
                groupadd supervisord &>/dev/null
            fi
            cd /etc/init.d/

            if [[ "$DISTRO_TYPE" == "RH" ]] ; then
                chmod 755 supervisord
                chkconfig --add supervisord &>/dev/null
                chkconfig --level 345 supervisord on
            elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then

                # TODO: A linha logo abaixo é realmente necessária? Rever p/ os outros instaladores tb! By Questor
                chmod 755 supervisord
                chkconfig --add supervisord &>/dev/null
                chkconfig --level 345 supervisord on
            elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                update-rc.d -f supervisord remove &>/dev/null
                chmod +x ./supervisord
                update-rc.d supervisord defaults
            fi
            f_svc_helper "supervisord" "restart"

            # NOTE: Abrir firewall p/ o supervisor! By Questor
            f_fire_hlp "supervisor" $SVISOR_PORT
            SVISOR_INST=1
            f_close_main_section
        fi
    fi
}

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

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

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

VAR_LOG_HTTPD=""
if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    VAR_LOG_HTTPD="/var/log/httpd"
elif [[ "$DISTRO_TYPE" == "DEB" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
    VAR_LOG_HTTPD="/var/log/apache2"
fi

ERROR_LOG_FL=""
if [[ "$DISTRO_TYPE" == "RH" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]]; then
    ERROR_LOG_FL="error_log"
elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
    ERROR_LOG_FL="error.log"
fi

LBG_INST=0
HTTPD_CONF_PATH=""
EZ_I_SKIP_ON_V=$FAST_INST
APP_ROOT_F="lbg"
HTTP_SRV_WSGI=""
HTTP_PORT_W=0
HTTP_PORT_A=0
NGINX_CONF_PATH=""
HTTPD_CONF_PATH_MAIN=""
HTTPD_CONF_PATH_E=""
f_open_main_section
f_div_section
f_yes_no "Install the LBG - LBGenerator?"
if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then

    # NOTE: As funções abaixo provêm recursos necessários ao 
    # LBG - LBGenerator! By Questor
    f_create_base_dir
    f_inst_py32 1
    f_inst_ve_py32 1
    f_create_ve32 1 "lbg_ve32"
    if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        NGINX_CONF_PATH="/etc/nginx/sites-available"
        NGINX_CONF_PATH_E="/etc/nginx/sites-enabled"
    else
        NGINX_CONF_PATH="/etc/nginx/conf.d"
    fi
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        HTTPD_CONF_PATH="/etc/httpd/conf.d"
        HTTPD_CONF_PATH_MAIN="/etc/httpd/conf"
    elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
        HTTPD_CONF_PATH="/etc/apache2/sites-available"
        HTTPD_CONF_PATH_E="/etc/apache2/sites-enabled"
        HTTPD_CONF_PATH_MAIN="/etc/apache2"
    elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
        HTTPD_CONF_PATH="/etc/apache2/conf.d"
        HTTPD_CONF_PATH_MAIN="/etc/apache2"
    fi
    OPT_ARR=("u" "NGINX and uWSGI" "p" "NGINX and pserver" "a" "Apache (httpd) and mod_wsgi")
    f_div_section
    f_get_usr_input_mult "Environment with (u) NGINX and uWSGI (highly recommended) or with (p) NGINX and pserver or with (a) Apache (httpd) and mod_wsgi? 
(use \"u\" or empty for NGINX and uWSGI)" OPT_ARR[@] 1
    HTTP_SRV_WSGI="$GET_USR_INPUT_MULT_R"
    if [ -z "$GET_USR_INPUT_MULT_R" ] || [ ${FAST_INST} -eq 1 ] ; then
        HTTP_SRV_WSGI="u"
    fi
    case "$HTTP_SRV_WSGI" in
        u)
            QUESTION_F="Enter the port number for NGINX service. 
Use empty for \"$HTTP_PORT_W\" (recommended)!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                HTTP_PORT_W=$GET_USR_INPUT_R
            fi
            f_inst_nginx $HTTP_PORT_W 1
            f_fire_hlp "NGINX" $HTTP_PORT_W
        ;;
        p)
            QUESTION_F="Enter the port number for NGINX service. 
Use empty for \"$HTTP_PORT_W\" (recommended)!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                HTTP_PORT_W=$GET_USR_INPUT_R
            fi

            f_inst_nginx $HTTP_PORT_W 1
            f_fire_hlp "NGINX" $HTTP_PORT_W
        ;;
        a)
            QUESTION_F="Enter the port number for Apache (httpd) service. 
Use empty for \"$HTTP_PORT_W\" (recommended)!"
            f_div_section
            f_get_usr_input "$QUESTION_F" 1
            QUESTION_F=""
            if [ -n "$GET_USR_INPUT_R" ] ; then
                HTTP_PORT_W=$GET_USR_INPUT_R
            fi
            f_inst_apache $HTTP_PORT_W 1
            f_inst_mod_wsgi 1

            # NOTE: Este pequeno ajuste é necessário para que o "python3.2" funcione 
            # no "CentOS 7"! By Questor
            if [[ "$DISTRO_TYPE" == "RH" ]] ; then
                f_fl_cont_str " g³" "/etc/mime.types"
                if [ ${FL_CONT_STR_R} -eq 1 ] ; then
                    f_ez_sed " g³" "" "/etc/mime.types"
                fi
            fi
            f_fire_hlp "Apache (httpd)" $HTTP_PORT_W
        ;;
    esac
    f_inst_lib 1
    f_inst_lbg_py_packs 1
    f_chk_by_path_hlp "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator" "d" "\"LBGenerator\" already installed in \"$BASE_INST_DIR_V/lbg_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/lbg_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/lbg_ve32/src/"
        cd "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator"
        eval "$BASE_INST_DIR_V/lbg_ve32/bin/python3.2 setup.py install"
        PG_CFG_F="postgresql://$PG_USER_F:$PG_PWD_F@127.0.0.1/$PG_DB_F"
        QUESTION_F="Enter the postgresql LBG - LBGenerator configuration. 
Use empty for \"$PG_CFG_F\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            PG_CFG_F=$GET_USR_INPUT_R
        fi
        QUESTION_F="Enter the port number for LBG - LBGenerator service. 
Use empty for \"$HTTP_PORT_A\" (recommended)!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            HTTP_PORT_A=$GET_USR_INPUT_R
        fi
        f_fire_hlp "LBG - LBGenerator" $HTTP_PORT_A
        QUESTION_F="Enter the LBG - LBGenerator base URL. 
Use empty for \"$APP_ROOT_F\" (will result in http://<machine_ip_or_name>:$HTTP_PORT_A/$APP_ROOT_F)!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            APP_ROOT_F=$GET_USR_INPUT_R
        fi
        SQLA_POOL_SIZE=0
        SQLA_POOL_SIZE_MAX_OVERFLOW=0
        f_get_percent_from "$PG_CONNECTIONS" "48"
        SQLA_POOL_SIZE=$F_GET_PERCENT_FROM_R
        SQLA_POOL_SIZE_MAX_OVERFLOW=$SQLA_POOL_SIZE

        # NOTE: Seta uma quantidade de threads adequada para o pool do 
        # sqlalchemy! By Questor
        f_div_section
        f_get_usr_input "Enter the LBG - LBGenerator SQLALCHEMY POOL SIZE (numbers only, integers only).
Use empty for \"$SQLA_POOL_SIZE\" (good for most cases)!
* Use at most 48% of the number of PostgreSQL connections;
* Decrease the value if you have other applications using PostgreSQL;
* Higher values will cause LBG - LBGenerator and PostgreSQL services instability, crash and other unexpected results." 1
        if [ -n "$GET_USR_INPUT_R" ] ; then
            SQLA_POOL_SIZE=$GET_USR_INPUT_R
            SQLA_POOL_SIZE_MAX_OVERFLOW=$SQLA_POOL_SIZE
        fi
        LBI_LBINDEX_URL="http://127.0.0.1:6543/"
        QUESTION_F="Enter the LBI - LBIndex http service URL. 
Use empty for \"$LBI_LBINDEX_URL\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            LBI_LBINDEX_URL=$GET_USR_INPUT_R
        fi
        ES_ESDEF_URL="http://127.0.0.1:9200"
        QUESTION_F="Enter the ES - ElasticSearch http service URL (don't use \"/\" at the end). 
Use empty for \"$ES_ESDEF_URL\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            ES_ESDEF_URL=$GET_USR_INPUT_R
        fi
        if [[ "$HTTP_SRV_WSGI" == "u" ]] ; then
            eval "cp -f \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini.uwsgi-dist\" \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini\""
            f_ez_sed "<SQLA_POOL_SIZE>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<SQLA_POOL_SIZE_MAX_OVERFLOW>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<LBI_LBINDEX_URL>" "$LBI_LBINDEX_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<ES_ESDEF_URL>" "$ES_ESDEF_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<SQLA_URL>" "$PG_CFG_F" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<LBG_VE32_PATH>" "$BASE_INST_DIR_V/lbg_ve32" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<APP_ROOT_F>" "$APP_ROOT_F" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_procs_qtt 4
            f_ez_sed "<UWSGI_PROCESSES>" "$F_PROCS_QTT_R" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            REQ_TIMEOUT=0
            f_srv_memory
            f_bytes_n_units "$F_SRV_MEMORY_R" "KB" "MB"
            F_SRV_MEMORY_R_IN_MB=$F_BYTES_N_UNITS_R
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "44"
            REQ_TIMEOUT=$F_GET_PERCENT_FROM_R
            TOO_LOW_REQ_TIMEOUT=" (good for most cases)!"
            if (( ${REQ_TIMEOUT} < 400 )) ; then
                TOO_LOW_REQ_TIMEOUT=".

* WARNING: THE INSTALLER HAS CALCULATED A TOO LOW TIMEOUT VALUE FOR THIS SERVER. TIMEOUTS BELOW 400 SECONDS ARE CONSIDERED TOO LOW. CONSIDER USING A SERVER WITH MORE RAM!
"
            fi

            # NOTE: Calcula um valor de timeout conforme a quantidade de
            # memória RAM! By Questor
            f_div_section
            f_get_usr_input "Enter the HTTP REQUEST TIMEOUT in seconds (numbers only, integers only).
Use empty for \"$REQ_TIMEOUT\"$TOO_LOW_REQ_TIMEOUT
* Use a numeric value equivalent at most 44% of your server RAM in MB;
* Decrease the value if you have other applications using your server;
* Higher values will cause LBG - LBGenerator and PostgreSQL services instability, crash and other unexpected results." 1
            if [ -n "$GET_USR_INPUT_R" ] ; then
                REQ_TIMEOUT=$GET_USR_INPUT_R
            fi
            f_ez_sed "<REQ_TIMEOUT>" "$REQ_TIMEOUT" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "150"
            UWSGI_POST_BUFFERING=$F_GET_PERCENT_FROM_R
            f_ez_sed "<UWSGI_POST_BUFFERING>" "$UWSGI_POST_BUFFERING" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "70"
            UWSGI_RELOAD_ON_AS=$F_GET_PERCENT_FROM_R
            f_ez_sed "<UWSGI_RELOAD_ON_AS>" "$UWSGI_RELOAD_ON_AS" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "65"
            UWSGI_RELOAD_ON_RSS=$F_GET_PERCENT_FROM_R
            f_ez_sed "<UWSGI_RELOAD_ON_RSS>" "$UWSGI_RELOAD_ON_RSS" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "85"
            UWSGI_EVIL_RELOAD_ON_AS=$F_GET_PERCENT_FROM_R
            f_ez_sed "<UWSGI_EVIL_RELOAD_ON_AS>" "$UWSGI_EVIL_RELOAD_ON_AS" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_get_percent_from "$F_SRV_MEMORY_R_IN_MB" "75"
            UWSGI_EVIL_RELOAD_ON_RSS=$F_GET_PERCENT_FROM_R
            f_ez_sed "<UWSGI_EVIL_RELOAD_ON_RSS>" "$UWSGI_EVIL_RELOAD_ON_RSS" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_chk_by_path_hlp "$NGINX_CONF_PATH/lbg.conf" "f" "\"lbg.conf\" already created in \"$NGINX_CONF_PATH/lbg.conf\"!"
            F_BAK_MD_R=1
            if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
                f_ez_mv_bak "$NGINX_CONF_PATH/lbg.conf" "Backup old version and update? (\"y\" recommended)"
            fi
            if [ ${F_BAK_MD_R} -eq 1 ] ; then
                \cp "$SCRIPTDIR_V/other-srcs-n-apps/lbg.conf-ngix-uwsgi-dist" "$NGINX_CONF_PATH/lbg.conf"
                f_ez_sed "<HTTP_PORT_A>" "$HTTP_PORT_A" "$NGINX_CONF_PATH/lbg.conf"
                f_ez_sed "<APP_ROOT_F>" "$APP_ROOT_F" "$NGINX_CONF_PATH/lbg.conf"
                f_ez_sed "<LBG_VE32_PATH>" "$BASE_INST_DIR_V/lbg_ve32" "$NGINX_CONF_PATH/lbg.conf"
                if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                    ln -s "$NGINX_CONF_PATH/lbg.conf" "$NGINX_CONF_PATH_E/lbg.conf" &>/dev/null
                fi
            fi

            # NOTE: Cria um "virtualenv" exclusivo para o "uWSGI"! By Questor
            f_create_ve32 1 "uwsgi_ve32"

            f_inst_uwsgi 1
            ln -nsf "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" "$BASE_INST_DIR_V/uwsgi_ve32/src/uWSGI/vassals/lbg.ini"
            f_svc_helper "nginx" "restart" 1

            # TODO: Por alguma razão que eu não consegui entender de jeito 
            # nenhum, o sistema só funciona corretamente se o "uwsgi" for 
            # reiniciado duas vêzes! Tá tosco no último =[ ... Mas, não 
            # consegui outra solução. Creio que a solução definitiva para o 
            # problema e ajustar os esquemas de inicialização dos serviços ao 
            # formato "systemctl", mas isso é bastante trabalhoso e vamos 
            # deixar isso para uma outra etapa! By Questor
            f_svc_helper "uwsgi" "restart" 1
            f_svc_helper "uwsgi" "restart" 1

        elif [[ "$HTTP_SRV_WSGI" == "p" ]] ; then

            # TODO: E para pserver para lbg e lba juntos? Como está sendo 
            # tratado? By Questor

            eval "cp -f \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini.pserver-dist\" \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini\""
            f_ez_sed "<SQLA_POOL_SIZE>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<SQLA_POOL_SIZE_MAX_OVERFLOW>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<LBI_LBINDEX_URL>" "$LBI_LBINDEX_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<ES_ESDEF_URL>" "$ES_ESDEF_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<SQLA_URL>" "$PG_CFG_F" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<APP_ROOT_F>" "$APP_ROOT_F" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_chk_by_path_hlp "$NGINX_CONF_PATH/lbg.conf" "f" "\"lbg.conf\" already created in \"$NGINX_CONF_PATH/lbg.conf\"!"
            F_BAK_MD_R=1
            if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
                f_ez_mv_bak "$NGINX_CONF_PATH/lbg.conf" "Backup old version and update? (\"y\" recommended)"
            fi
            if [ ${F_BAK_MD_R} -eq 1 ] ; then
                \cp "$SCRIPTDIR_V/other-srcs-n-apps/lbg.conf-ngix-pserve-dist" "$NGINX_CONF_PATH/lbg.conf"

                # NOTE: Determinar um número adequado de processos! By Questor
                f_procs_qtt 2

                UPSTREAM_LBG=""
                for (( i=0; i < F_PROCS_QTT_R; i++ )) ; do
                    UPSTREAM_LBG=$UPSTREAM_LBG"    server 127.0.0.1:500$i;\n"
                done
                f_ez_sed "<UPSTREAM_LBG>" "$UPSTREAM_LBG" "$NGINX_CONF_PATH/lbg.conf"
                f_ez_sed "<APP_ROOT_F>" "$APP_ROOT_F" "$NGINX_CONF_PATH/lbg.conf"
                f_ez_sed "<HTTP_PORT_A>" "$HTTP_PORT_A" "$NGINX_CONF_PATH/lbg.conf"
                if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                    ln -s "$NGINX_CONF_PATH/lbg.conf" "$NGINX_CONF_PATH_E/lbg.conf" &>/dev/null
                fi
            fi
            f_svc_helper "nginx" "restart" 1
            f_inst_supervisor 1
        elif [[ "$HTTP_SRV_WSGI" == "a" ]] ; then
            eval "cp -f \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/lbgenerator.wsgi-dist\" \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/lbgenerator.wsgi\""
            f_ez_sed "<LBG_VE32_PATH>" "$BASE_INST_DIR_V/lbg_ve32" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/lbgenerator.wsgi"
            eval "cp -f \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini.apache-dist\" \"$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini\""
            f_ez_sed "<SQLA_POOL_SIZE>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<SQLA_POOL_SIZE_MAX_OVERFLOW>" "$SQLA_POOL_SIZE" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_ez_sed "<LBI_LBINDEX_URL>" "$LBI_LBINDEX_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<ES_ESDEF_URL>" "$ES_ESDEF_URL" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini"
            f_ez_sed "<SQLA_URL>" "$PG_CFG_F" "$BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini" 1
            f_chk_by_path_hlp "$HTTPD_CONF_PATH/lbg.conf" "f" "\"lbg.conf\" already created in \"$HTTPD_CONF_PATH/lbg.conf\"!"
            F_BAK_MD_R=1
            if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
                f_ez_mv_bak "$HTTPD_CONF_PATH/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-apache-mod_wsgi-dist\" \"$HTTPD_CONF_PATH/lbg.conf\""
                f_ez_sed "<HTTP_PORT_A>" "$HTTP_PORT_A" "$HTTPD_CONF_PATH/lbg.conf"
                f_ez_sed "<MOD_WSGI_PATH>" "$MOD_WSGI_PATH" "$HTTPD_CONF_PATH/lbg.conf"
                f_ez_sed "<LBG_VE32_PATH>" "$BASE_INST_DIR_V/lbg_ve32" "$HTTPD_CONF_PATH/lbg.conf" 1
                f_ez_sed "<APP_ROOT_F>" "$APP_ROOT_F" "$HTTPD_CONF_PATH/lbg.conf" 1
                f_ez_sed "<VAR_LOG_HTTPD>" "$VAR_LOG_HTTPD" "$HTTPD_CONF_PATH/lbg.conf" 1
                f_ez_sed "<HTTPD_USR>" "$HTTPD_USR" "$HTTPD_CONF_PATH/lbg.conf" 1
                f_ez_sed "<HTTPD_GRP>" "$HTTPD_GRP" "$HTTPD_CONF_PATH/lbg.conf" 1
                if [[ "$DISTRO_TYPE" == "RH" ]] ; then
                    # f_ez_sed "<DIR_RULES>" "Order allow,deny\n    Allow from all" "$HTTPD_CONF_PATH/lbg.conf"
                    f_ez_sed "<DIR_RULES>" "AllowOverride None\n    Require all granted" "$HTTPD_CONF_PATH/lbg.conf"
                elif [[ "$DISTRO_TYPE" == "DEB" ]] || [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
                    f_ez_sed "<DIR_RULES>" "AllowOverride None\n    Require all granted" "$HTTPD_CONF_PATH/lbg.conf"
                fi
            fi
            if [[ "$DISTRO_TYPE" == "DEB" ]] ; then
                ln -s "$HTTPD_CONF_PATH/lbg.conf" "$HTTPD_CONF_PATH_E/lbg.conf" &>/dev/null
            fi
            eval "chown -R $HTTPD_USR $BASE_INST_DIR_V"
            eval "chown -R :$HTTPD_GRP $BASE_INST_DIR_V"
            eval "chmod -R 755 $BASE_INST_DIR_V"
            f_svc_helper "$HTTPD_SERV_NAME" "restart" 1
        fi

    fi
    LBG_INST=1
fi
f_close_main_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 o usuário seja 
# informado sobre quais foram as configurações de persistência setadas! 
# By Questor
PERSIST_CONFIG=""
if [ ${CONF_PG} -eq 1 ] || [ ${CREATE_LB_DT} -eq 1 ] ; then

    CREATE_LB_DT_VL=""
    if [ ${CREATE_LB_DT} -eq 1 ] ; then
        CREATE_LB_DT_VL="
        database .. $PG_DB_F"
    fi

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

    if [ -n "$CONF_PG_VL$CREATE_LB_DT_VL" ] ; then
        PERSIST_CONFIG="    LBG - LBGenerator $PG_NAME persistence config...$CREATE_LB_DT_VL$CONF_PG_VL"
    fi
fi

PG_SVC_INFO=""
if [ ${PG_INST} -eq 1 ] ; then
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        PG_SVC_INFO="    $PG_NAME

        To start/stop...
            systemctl start $PG_SERV_NAME.service
            systemctl stop $PG_SERV_NAME.service"
    else
        PG_SVC_INFO="    $PG_NAME

        To start/stop...
            service $PG_SERV_NAME start
            service $PG_SERV_NAME stop"
    fi
fi

ES_SVC_INFO=""
if [ ${ES_INST} -eq 1 ] ; then
    ES_SVC_INFO="    $ES_NAME

        To start/stop...
            $ES_SERV_CMD start
            $ES_SERV_CMD stop"
fi

UWSGI_SVC_INFO=""
if [ ${UWSGI_INST} -eq 1 ] ; then
    UWSGI_SVC_SYNTAX=""
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        UWSGI_SVC_SYNTAX="systemctl start uwsgi.service
            systemctl stop uwsgi.service"
    else
        UWSGI_SVC_SYNTAX="service uwsgi start
            service uwsgi stop"
    fi
    UWSGI_SVC_INFO="    uWSGI

        To start/stop...
            $UWSGI_SVC_SYNTAX

        To configure uWSGI...
            vi $BASE_INST_DIR_V/uwsgi_ve32/src/uWSGI/production.ini

        Log...
            less /var/log/uwsgi.log"
fi

SVISOR_SVC_INFO=""
if [ ${SVISOR_INST} -eq 1 ] ; then
    SVISOR_SVC_SYNTAX=""
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        SVISOR_SVC_SYNTAX="systemctl start supervisord.service
            systemctl stop supervisord.service"
    else
        SVISOR_SVC_SYNTAX="service supervisord start
            service supervisord stop"
    fi
    SVISOR_SVC_INFO="    Supervisor

        To start/stop...
            $SVISOR_SVC_SYNTAX

        To access...
            http://<machine_ip_or_name>:$SVISOR_PORT
            user ...... $SVISOR_USER
            password .. $SVISOR_PWD

        To configure Supervisor...
            vi $BASE_INST_DIR_V/$VE_2_X/src/supervisor/supervisord.conf

            NOTE: The LBG - LBGenerator is set to use a maximum of $PROC_MAX_MEM_PERC% of 
                  server memory. For more details see section 
                  \"[eventlistener:memmon]\" in supervisord.conf!

        python$PYTHON_2_X virtual environment path...
            $BASE_INST_DIR_V/$VE_2_X"
fi

APACHE_SVC_INFO=""
APACHE_SVC_INFO_DISTRO=""
if [[ "$DISTRO_TYPE" == "RH" ]] ; then
    APACHE_SVC_INFO_DISTRO="vi $HTTPD_CONF_PATH_MAIN/httpd.conf"
elif [[ "$DISTRO_TYPE" == "DEB" ]] ; then
    APACHE_SVC_INFO_DISTRO="vi $HTTPD_CONF_PATH_MAIN/ports.conf
            vi $HTTPD_CONF_PATH/000-default.conf"
elif [[ "$DISTRO_TYPE" == "SUSE" ]] ; then
    APACHE_SVC_INFO_DISTRO="vi $HTTPD_CONF_PATH_MAIN/listen.conf"
fi
if [ ${APACHE_INST} -eq 1 ] ; then
    APACHE_SVC_SYNTAX=""
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        APACHE_SVC_SYNTAX="systemctl start $HTTPD_SERV_NAME.service
            systemctl stop $HTTPD_SERV_NAME.service"
    else
        APACHE_SVC_SYNTAX="service $HTTPD_SERV_NAME start
            service $HTTPD_SERV_NAME stop"
    fi
    APACHE_SVC_INFO="    Apache ($HTTPD_SERV_NAME)

        To start/stop...
            $APACHE_SVC_SYNTAX

        To configure Apache ($HTTPD_SERV_NAME)...
            $APACHE_SVC_INFO_DISTRO

        To configure LBG on Apache ($HTTPD_SERV_NAME)...
            vi $HTTPD_CONF_PATH/lbg.conf

        Log...
            less $VAR_LOG_HTTPD/$ERROR_LOG_FL"
fi

NGINX_SVC_INFO=""
if [ ${NGINX_INST} -eq 1 ] ; then
    NGINX_SVC_SYNTAX=""
    if [[ "$DISTRO_TYPE" == "RH" ]] ; then
        NGINX_SVC_SYNTAX="systemctl start nginx.service
            systemctl stop nginx.service"
    else
        NGINX_SVC_SYNTAX="service nginx start
            service nginx stop"
    fi
    NGINX_SVC_INFO="    NGINX

        To start/stop...
            $NGINX_SVC_SYNTAX

        To configure NGINX...
            vi /etc/nginx/nginx.conf

        To configure LBG on NGINX...
            vi $NGINX_CONF_PATH/lbg.conf

        Log...
            less /var/log/nginx/error.log"
fi

LBG_SVC_INFO=""
if [ ${LBG_INST} -eq 1 ] ; then
    HTTP_URL_PORT=""
    if (( $HTTP_PORT_A != 80 )); then
        HTTP_URL_PORT=":$HTTP_PORT_A"
    fi
    LBG_LOG=""
    if [ ${APACHE_INST} -eq 1 ] ; then
        LBG_LOG="

        Log...
            less /var/log/httpd/lbg-error.log"
    elif [ ${NGINX_INST} -eq 1 ] ; then
        LBG_LOG="

        Log...
            less /var/log/lbg.log"
    fi
    LBG_SVC_INFO="    LBG

        To access...
            http://<machine_ip_or_name>$HTTP_URL_PORT/$APP_ROOT_F

        To configure LBG...
            vi $BASE_INST_DIR_V/lbg_ve32/src/LBGenerator/production.ini$LBG_LOG

        python3.2 path...
            $BASE_INST_DIR_V/py32

        python3.2 virtual environment path...
            $BASE_INST_DIR_V/lbg_ve32"
fi

if [ -n "$PG_SVC_INFO$ES_SVC_INFO$SVISOR_SVC_INFO$APACHE_SVC_INFO$NGINX_SVC_INFO$LBG_SVC_INFO" ] ; then

    # NOTE: First item! By Questor
    USEFUL_INFO_F="$PG_SVC_INFO"

    # TODO: Inserir a flag "-e" em todos "echos" de funcionalidades que 
    # "printam" mensagens para o usuário no "ez_i.bash"? By Questor

    # NOTE: There is no way to represent a literal (\n in case) for "echo"
    # without using the "-e" flag! By Questor
    USEFUL_INFO_NEW_LINES="

"

    if [ -n "$USEFUL_INFO_F" ] && [ -n "$PERSIST_CONFIG" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$PERSIST_CONFIG"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$ES_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$ES_SVC_INFO"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$SVISOR_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$SVISOR_SVC_INFO"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$UWSGI_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$UWSGI_SVC_INFO"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$APACHE_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$APACHE_SVC_INFO"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$NGINX_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$NGINX_SVC_INFO"
    if [ -n "$USEFUL_INFO_F" ] && [ -n "$LBG_SVC_INFO" ] ; then
        USEFUL_INFO_F="$USEFUL_INFO_F$USEFUL_INFO_NEW_LINES"
    fi
    USEFUL_INFO_F="$USEFUL_INFO_F$LBG_SVC_INFO"
else
    USEFUL_INFO_F="    Nothing was installed!"
fi

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

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