Instalando e configurando Postgres com Dialog

Publicado por Bruno L Damada 25/06/2007

[ Hits: 19.439 ]

Homepage: www.bdois.com

Download SCP.sh




Fiz para auxiliar no meu dia-a-dia.

Até uma galinha instala o postgres com ele. Basta colar um
milho no enter!

Veja o cod. antes de executar...

  



Esconder código-fonte

#######################################
# Script de configuracao do Postgres  #
# Dept. T.I. - MicroWork              #
# Desenvolvido por Bruno L. Damada    #
#######################################

dialog --yesno 'Deseja configurar o PostgreSQL ?' 0 0
if [ $? = 0 ]; then
# Editando pg_hba # Comentando conexoes default.
sed -i 's|local   all         all                               ident sameuser|\#local   all         all                               ident sameuser|g' pg_hba.conf
sed -i 's|host    all         all         127.0.0.1/32          ident sameuser|\#host    all         all         127.0.0.1/32          ident sameuser|g' pg_hba.conf
sed -i 's|host    all         all         ::1/128               ident sameuser|\#host    all         all         ::1/128               ident sameuser|g' pg_hba.conf
# Liberando conexoes.
echo "# Liberando conexoes" >> pg_hba.conf
echo "local   all   all                                 trust" >> pg_hba.conf
echo "host    all   all   127.0.0.1   255.255.255.255   trust" >> pg_hba.conf
echo "host    all   all   192.0.0.0   255.0.0.0         password" >> pg_hba.conf
echo "host    all   all   10.0.0.0    255.0.0.0         password" >> pg_hba.conf
# Liberar conexoes externas.
dialog --yesno 'Aceitar conexoes externas?' 0 0
if [ $? = 0 ]; then
        echo "host    all   all   200.0.0.0   255.0.0.0         md5" >> pg_hba.conf
        echo "host    all   all   201.0.0.0   255.0.0.0         md5" >> pg_hba.conf
else
        clear
fi
# Visualizando o pg_hba.conf.
dialog  --title 'Visualizando Arquivo'  --textbox ./pg_hba.conf  0 0
dialog  --msgbox 'Conexoes liberadas com sucesso.'   6 40
# Configurando postgresql.conf
sed -i 's|#listen_addresses|listen_addresses|g' postgresql.conf
sed -i 's|localhost|\'*'|g' postgresql.conf
sed -i 's|#port = 5432|port = 5432|g' postgresql.conf
sed -i 's|#work_mem = 1024|work_mem = 2048|g' postgresql.conf
sed -i 's|#fsync = on|fsync = on|g' postgresql.conf
sed -i 's|#statement_timeout = 0|statement_timeout = 3600000|g' postgresql.conf
sed -i 's|lc_messages|#lc_messages|g' postgresql.conf
echo "lc_messages = 'en_US.UTF-8'" >> postgresql.conf
echo "lc_messages = 'en_US.UTF-8'" >> postgresql.conf
# shared_buffers
echo "Memoria ram disponivel: " >> mm.tmp
i=$(free | grep "^Mem" | cut -b 5-)
echo $i | cut -d " " -f 1 >> mm.tmp
dialog --title 'Memoria ram!' --textbox ./mm.tmp  6 60
rm -rf mm.tmp
memor=$( dialog --stdout --title 'Memoria' --menu 'Escolha a conf mais indicada'   \
            0 0 0                   \
            2560 '200' \
            5120 '400'  \
            10240 '800'     \
            11520 '900'        \
            23040 '1800'               )
echo "substituindo shared_buffers 1000 por  $memor"
sed -i 's|shared_buffers = 1000|shared_buffers = '$memor'|g' postgresql.conf
# sysctl.conf
if [ $memor = 2560 ]; then
echo "kernel.shmmni = 18" >> /etc/sysctl.conf
echo "kernel.shmmax = 25165824" >> /etc/sysctl.conf
echo "kernel.shmall = 25165824" >> /etc/sysctl.conf

/sbin/sysctl -w kernel.shmmni=18
/sbin/sysctl -w kernel.shmmax=25165824
/sbin/sysctl -w kernel.shmall=25165824

else
clear
fi
###
if [ $memor = 5120 ]; then
echo "kernel.shmmni = 18" >> /etc/sysctl.conf
echo "kernel.shmmax = 50331648" >> /etc/sysctl.conf
echo "kernel.shmall = 50331648" >> /etc/sysctl.conf

/sbin/sysctl -w kernel.shmmni=18
/sbin/sysctl -w kernel.shmmax=50331648
/sbin/sysctl -w kernel.shmall=50331648

else
clear
fi
###
if [ $memor = 10240 ]; then
echo "kernel.shmmni = 18" >> /etc/sysctl.conf
echo "kernel.shmmax = 100663296" >> /etc/sysctl.conf
echo "kernel.shmall = 100663296" >> /etc/sysctl.conf

/sbin/sysctl -w kernel.shmmni=18
/sbin/sysctl -w kernel.shmmax=100663296
/sbin/sysctl -w kernel.shmall=100663296

else
clear
fi
###
if [ $memor = 11520 ]; then
echo "kernel.shmmni = 18" >> /etc/sysctl.conf
echo "kernel.shmmax = 113246208" >> /etc/sysctl.conf
echo "kernel.shmall = 113246208" >> /etc/sysctl.conf

/sbin/sysctl -w kernel.shmmni=18
/sbin/sysctl -w kernel.shmmax=113246208
/sbin/sysctl -w kernel.shmall=113246208

else
clear
fi
###
if [ $memor = 23040 ]; then
echo "kernel.shmmni = 18" >> /etc/sysctl.conf
echo "kernel.shmmax = 226492416" >> /etc/sysctl.conf
echo "kernel.shmall = 226492416" >> /etc/sysctl.conf

/sbin/sysctl -w kernel.shmmni=18
/sbin/sysctl -w kernel.shmmax=226492416
/sbin/sysctl -w kernel.shmall=226492416

else
clear
fi
clear
/etc/init.d/postgresql restart
clear

FIM=0
while [  $FIM = 0 ]; do

pas=$( dialog --stdout                                      \
   --title 'Senha postgres!'                         \
   --passwordbox 'Digite a senha do usuario postgres:'  \
   0 0 )

pass=$( dialog --stdout                                          \
   --title 'Senha postgres!'                         \
   --passwordbox 'Confirme a senha do usuario postgres:'  \
   0 0 )

if [ $pas = $pass ]; then
        psql -c "alter user postgres with password '$pass'" template1 postgres
        FIM=1
else
        dialog --title 'Senha'  --msgbox 'Senha incorreta. Digite novamente.'  \6 40
fi

done

psql template1 < /usr/share/pgsql/contrib/dblink.sql -Upostgres
/etc/init.d/postgresql restart
clear
NCB=0
while [  $NCB = 0 ]; do
dialog --yesno 'Criar um banco de dados ?' 0 0
if [ $? = 0 ]; then
        nomeban=$( dialog --stdout --inputbox 'Digite o nome do banco:' 0 0 )
        createdb -Upostgres -E latin1 $nomeban
else
NCB=1
clear
fi
done
dialog --yesno 'Deseja inserir os dados padroes no banco?' 0 0

if [ $? = 0 ]; then

ndb=$( dialog --stdout --inputbox 'Informe o nome do banco que recebera os dados:' 0 0 )

marca=$( dialog --stdout --title 'Bancos' --menu 'Escolha o banco de acordo com a marca.'   \
            0 0 0                   \
            1 'Honda' \
            2 'Yamaha'  \
            3 'Suzuki'     \
            4 'Sundown'        \
            5 'Traxx'  \
            6 'Smart' \
            7 'Fisco' )
echo "Numero da marca escolhida foi  $marca"

else
        clear
fi

if [ $marca = 1 ]; then
psql -Upostgres $ndb < ./insthonda.sql
else
clear
fi

if [ $marca = 2 ]; then
psql -Upostgres $ndb < instyam.sql
else
clear
fi

if [ $marca = 3 ]; then
psql -Upostgres $ndb < instsuzu.sql
else
clear
fi

if [ $marca = 4 ]; then
psql -Upostgres $ndb < instsun.sql
else
clear
fi

if [ $marca = 5 ]; then
psql -Upostgres $ndb < instraxx.sql
else
clear
fi

if [ $marca = 6 ]; then
psql -Upostgres $ndb < instsmart.sql
else
clear
fi

if [ $marca = 7 ]; then
psql -Upostgres $ndb < instfisco.sql
else
clear
fi
clear
dialog                                            \
   --title 'Microwork'                             \
   --msgbox 'Configuracao concluida.'  \
   6 40

else

dialog                                            \
   --title 'Microwork'                             \
   --msgbox 'Configuracao cancelada pelo usuario.'  \
   6 40


fi
clear

Scripts recomendados

Limpeza automática de pastas com contagem de arquivos

pwmanager - Gerenciador de senhas em shell script

Soma valores de uma lista (calculo notas, pontos, etc)

Agenda "completa" com interface do zenity

Script Simples para informações do Sistema


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts