install.sh 15.7 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
#!/bin/bash

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

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

read -d '' TITLE_F <<"EOF"
LBD - LBDoc Installer
EOF

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

read -d '' ABOUT_F <<"EOF"
This script will install LBD - LBDoc a LightBase aplication!

Have fun! =D
EOF

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

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

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

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

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

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

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

f_terms_licen "$TERMS_LICEN_F"
TERMS_LICEN_F=""

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

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

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

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

f_instruct "$INSTRUCT_F"
INSTRUCT_F=""

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# > -----------------------------------------
# Instalar arquivos de configuração do Apache (httpd) e fontes do LBD - LBDoc!

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

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

    f_chk_by_path_hlp "/var/www/html/docslightbase" "d" "\"LBD - LBDoc\" already installed in \"/var/www/html\"!"
    F_BAK_MD_R=1
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_ez_mv_bak "/var/www/html/docslightbase" "Backup old version and update? (\"y\" recommended)"
    fi
    if [ ${F_BAK_MD_R} -eq 1 ] ; then
        cd "$SCRIPTDIR_V"
        cd ./lbd-src
        tar -zxvf ./docslightbase.tar.gz
        mv ./docslightbase /var/www/html/
        rm -rf ./docslightbase
        chown -R apache /var/www/html
        chmod -R 755 /var/www/html
        LBG_URL="http://127.0.0.1/lbg"
        QUESTION_F="Enter lightbase URL. 
Use empty for \"$LBG_URL\"!"
        f_div_section
        f_get_usr_input "$QUESTION_F" 1
        f_div_section
        QUESTION_F=""
        if [ -n "$GET_USR_INPUT_R" ] ; then
            LBG_URL=$GET_USR_INPUT_R
        fi
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/portal/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/recebidos/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/manutencao/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/docspro/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/atosnotaspareceres/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/gsa/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/inativos/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/apps/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/expedidos/Web.config" 1
        f_ez_sed "<LBG_URL>" "$LBG_URL" "/var/www/html/docslightbase/auditoria/Web.config" 1
    fi

    f_chk_by_path_hlp "/etc/httpd/conf.d/expedidos.conf" "f" "\"LBD - LBDoc\" (Apache/httpd) configuration files already installed in \"/etc/httpd/conf.d\"!"
    F_BAK_MD_R=1
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_yes_no "Backup old version and update? (\"y\" recommended)"
        if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then
            SUFFIX=$(date +"-D%Y-%m-%d-T%H-%M-%S")
            NEW_FDL="/etc/httpd/conf.d/conf-bak$SUFFIX" 
            mkdir "$NEW_FDL"
            mv "/etc/httpd/conf.d/apps.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/atosnotaspareceres.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/auditoria.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/docslightbase.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/docspro.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/expedidos.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/GSA.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/inativos.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/manutencao.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/mod_mono.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/portal.conf" "$NEW_FDL/"
            mv "/etc/httpd/conf.d/recebidos.conf" "$NEW_FDL/"
        fi
        F_BAK_MD_R=${YES_NO_R}
    fi
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${F_BAK_MD_R} -eq 1 ] ; then
        cd "$SCRIPTDIR_V"
        cd ./other-srcs-n-apps
        tar -zxvf ./lbdoc-httpd-conf.tar.gz
        mv ./lbdoc-httpd-conf/* /etc/httpd/conf.d/
        rm -rf ./lbdoc-httpd-conf
        chown -R apache /etc/httpd/conf.d
        chmod -R 755 /etc/httpd/conf.d
    fi
fi
f_close_section

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

# > -----------------------------------------
#  Instalar a estrutura básica de dados do LBD - LBDoc!

PG_DB_F="lb"
EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section

f_yes_no "Install LBD - LBDoc (postgres 9.4) basic LightBase/LBG data structures?"

if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then

    QUESTION_F="Enter the postgres 9.4 database name for LightBase (LBG). 
Use empty for \"$PG_DB_F\" (default)!"
    f_get_usr_input "$QUESTION_F" 1
    QUESTION_F=""
    if [ -n "$GET_USR_INPUT_R" ] ; then
        PG_DB_F=$GET_USR_INPUT_R
    fi
    if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw "$PG_DB_F"; then
        if [[ `sudo -u postgres psql $PG_DB_F -tAc "SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'lb_doc_expedido');"` = 'f' ]] ; then
            cd "$SCRIPTDIR_V"
            cp ./lbd-basic-dt-strt/lbd-basic-dt-strt.pg /tmp
            cd /tmp
            chmod 700 lbd-basic-dt-strt.pg
            chown postgres lbd-basic-dt-strt.pg
            chown :postgres lbd-basic-dt-strt.pg
            sudo -u postgres psql $PG_DB_F -f lbd-basic-dt-strt.pg
            rm -f lbd-basic-dt-strt.pg
        else
            EZ_I_SKIP_ON_V=$SIMPLE_INST
            f_enter_to_cont "Basic \"LBD - LBDoc\" data structure already created in \"$PG_DB_F\" database!"
            EZ_I_SKIP_ON_V=0
        fi
    else
        EZ_I_SKIP_ON_V=$SIMPLE_INST
        f_enter_to_cont "The database \"$PG_DB_F\" does not exist!"
        EZ_I_SKIP_ON_V=0
    fi
else
    f_enter_to_cont "The file \"./lbd-basic-dt-strt/lbd-basic-dt-strt.sql\" has the LBD - LBDoc (postgres 9.4) basic LightBase/LBG data structures! Check it!"
fi
f_close_section

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

# > -----------------------------------------
# Instalar componentes do LBD - LBDoc/mono!

EZ_I_SKIP_ON_V=$SIMPLE_INST
f_open_section
read -d '' TITLE_F <<"EOF"
Install LBD - LBDoc/mono components?
EOF

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

    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps

    f_pack_is_inst "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 "glib2-devel" "yum" "\"glib2-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install glib2-devel
    fi
    f_pack_is_inst "libX11-devel" "yum" "\"libX11-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install libX11-devel
    fi
    f_pack_is_inst "freetype-devel" "yum" "\"freetype-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install freetype-devel
    fi
    f_pack_is_inst "fontconfig-devel" "yum" "\"fontconfig-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install fontconfig-devel
    fi
    f_pack_is_inst "libexif-devel" "yum" "\"libexif-devel\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install libexif-devel
    fi
    f_pack_is_inst "bison" "yum" "\"bison\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install bison
    fi
    f_pack_is_inst "gettext" "yum" "\"gettext\" already installed!"
    if [ ${F_PACK_IS_INST_R} -eq 0 ] ; then
        yum -y install gettext
    fi

    UP_MONO=1
    f_chk_by_path_hlp "/opt/mono" "d" "\"mono-2.10.2\" already installed in \"/opt/mono\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_div_section
        f_yes_no "Update/reinstall \"mono-2.10.2\"? (\"y\" recommended)"
        f_div_section
        UP_MONO=$YES_NO_R
    else
        f_enter_to_cont "Install \"mono-2.10.2\"!"
    fi
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${UP_MONO} -eq 1 ] ; then
        tar -xjf mono-2.10.2.tar.bz2
        cd ./mono-2.10.2
        ./configure  --prefix=/opt/mono --with-libgdiplus=/opt/mono
        make
        make install
        export PATH=$PATH:/opt/mono/bin
        export PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig
        cd ..
        rm -rf ./mono-2.10.2
    fi

    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps

    UP_XSP=1
    f_chk_by_path_hlp "/opt/mono/bin/xsp" "d" "\"xsp-2.10.2\" already installed in \"/opt/mono/bin/xsp\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_div_section
        f_yes_no "Update/reinstall \"xsp-2.10.2\"? (\"y\" recommended)"
        f_div_section
        UP_XSP=$YES_NO_R
    else
        f_enter_to_cont "Install \"xsp-2.10.2\"!"
    fi
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${UP_XSP} -eq 1 ] ; then
        tar -xjf xsp-2.10.2.tar.bz2
        cd ./xsp-2.10.2
        ./configure --prefix=/opt/mono
        make
        make install
        cd ..
        rm -rf ./xsp-2.10.2
    fi

    cd "$SCRIPTDIR_V"
    cd ./other-srcs-n-apps

    UP_XSP=1
    f_chk_by_path_hlp "/usr/lib64/httpd/modules/mod_mono.so" "f" "\"mod_mono-2.10\" already installed in \"/usr/lib64/httpd/modules\"!"
    if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then
        f_div_section
        f_yes_no "Update/reinstall \"mod_mono-2.10\"? (\"y\" recommended)"
        f_div_section
        UP_XSP=$YES_NO_R
    else
        f_enter_to_cont "Install \"mod_mono-2.10\"!"
    fi
    if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${UP_XSP} -eq 1 ] ; then
        tar -xjf mod_mono-2.10.tar.bz2
        cd ./mod_mono-2.10
        ./configure --prefix=/opt/mono --with-mono-prefix=/opt/mono
        make
        make install
        cd ..
        rm -rf ./mod_mono-2.10
    fi

    service httpd restart
fi
f_close_section

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

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

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

USEFUL_INFO_F="    To start/stop...
        service httpd start
        service httpd stop

    To access...
        http://<ip>/docslightbase/apps/

    Initial user...
        000.000.000-00/123456

    To configure httpd (Apache)...
        See \"/etc/httpd/conf.d\" folder!

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

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

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