1 | |
---|
2 | # Servico Banco de Dados (Postrgres) |
---|
3 | |
---|
4 | # Comum a todas as distros |
---|
5 | |
---|
6 | # Parametro 1: Destino (completo) de onde ficarao os dados do Postges (data) |
---|
7 | # Parametro 2: Nome do arquivo modelo de configuração do Postgres (postgres.conf) |
---|
8 | # Parametro 3: Nome do arquivo modelo de configuracao de acessos do Postgres (pg_hba.conf) |
---|
9 | # Parametro 4: Destino (completo) de onde ficarao os arquivos de configuracao do Postgres |
---|
10 | # Exemplo: bd /var/lib/pgsql/data |
---|
11 | bd () { |
---|
12 | DIR_PG=$1 |
---|
13 | PG_CONF=$2 |
---|
14 | PG_HBA=$3 |
---|
15 | DIR_CONF=$4 |
---|
16 | get_org |
---|
17 | get_pass |
---|
18 | |
---|
19 | rm -rf $DIR_PG* |
---|
20 | su - postgres -c "export LANG=pt_BR.ISO-8859-1; initdb -E latin1 -D $DIR_PG" |
---|
21 | #su - postgres -c "env LANG=LATIN1 initdb --locale=pt_BR.iso88591 --encoding=LATIN1 -D $DIR_PG" |
---|
22 | sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/LDAP_PWD/$LDAP_PWD/g" -e "s/ORG/$ORG/g" -e "s/DOMAIN/$DOMAIN/g" $ARQS/expresso.dump > /tmp/expresso.dump |
---|
23 | |
---|
24 | |
---|
25 | <<<<<<< .mine |
---|
26 | |
---|
27 | cp -f $PG_CONF $DIR_CONF/ |
---|
28 | cp -f $PG_HBA $DIR_CONF/ |
---|
29 | # service postgresql start |
---|
30 | ======= |
---|
31 | |
---|
32 | cp -f $PG_CONF $DIR_CONF/ |
---|
33 | cp -f $PG_HBA $DIR_CONF/ |
---|
34 | |
---|
35 | >>>>>>> .r5824 |
---|
36 | } |
---|
37 | |
---|
38 | <<<<<<< .mine |
---|
39 | bd_ubuntu1110 () { |
---|
40 | DIR_PG=$1 |
---|
41 | PG_CONF=$2 |
---|
42 | PG_HBA=$3 |
---|
43 | DIR_CONF=$4 |
---|
44 | get_org |
---|
45 | get_pass |
---|
46 | |
---|
47 | rm -rf $DIR_PG* |
---|
48 | su - postgres -c "env LANG=LATIN1 initdb --locale=pt_BR.iso88591 --encoding=LATIN1 -D $DIR_PG" |
---|
49 | sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/LDAP_PWD/$LDAP_PWD/g" -e "s/ORG/$ORG/g" -e "s/DOMAIN/$DOMAIN/g" $ARQS/expresso.dump > /tmp/expresso.dump |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | cp -f $PG_CONF $DIR_CONF/ |
---|
54 | cp -f $PG_HBA $DIR_CONF/ |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | # Cria a base de dados e importa os SQLs padroes |
---|
60 | ======= |
---|
61 | # Cria a base de dados e importa os SQLs padroes |
---|
62 | >>>>>>> .r5824 |
---|
63 | create_db () |
---|
64 | { |
---|
65 | su - postgres -c 'dropdb expresso' || { echo "Banco expresso não existia. [OK]"; } |
---|
66 | su - postgres -c 'createdb -E LATIN1 expresso' || { echo "Falha na criação do banco expresso."; exit 1; } |
---|
67 | su - postgres -c 'psql -f /tmp/expresso.dump expresso' |
---|
68 | } |
---|
69 | |
---|
70 | bd_debian () |
---|
71 | { |
---|
72 | DIR_PG="$1" |
---|
73 | PG_CONF="$2" |
---|
74 | PG_HBA="$3" |
---|
75 | DIR_CONF="$4" |
---|
76 | # Instala os pacotes do servico |
---|
77 | apt-get install -y postgresql postgresql-common postgresql-client postgresql-client-common |
---|
78 | /etc/init.d/postgresql stop |
---|
79 | # Gera um link do initdb, para padronizar com o Centos |
---|
80 | ln -sf /usr/lib/postgresql/8.4/bin/initdb /usr/bin/ |
---|
81 | # Faz backup da base do Postgres |
---|
82 | mv $DIR_PG $DIR_PG.`date +"%s"` |
---|
83 | mkdir -p $DIR_PG/main |
---|
84 | |
---|
85 | chown -R postgres:postgres $DIR_PG |
---|
86 | chmod -R 770 $DIR_PG |
---|
87 | |
---|
88 | <<<<<<< .mine |
---|
89 | bd $DIR_PG $PG_CONF $PG_HBA $DIR_CONF |
---|
90 | rm -f $DIR_PG/postgresql.conf |
---|
91 | rm -f $DIR_PG/pg_hba.conf |
---|
92 | ======= |
---|
93 | bd $DIR_PG $PG_CONF $PG_HBA $DIR_CONF |
---|
94 | rm -f $DIR_PG/postgresql.conf |
---|
95 | rm -f $DIR_PG/pg_hba.conf |
---|
96 | |
---|
97 | >>>>>>> .r5824 |
---|
98 | /etc/init.d/postgresql start |
---|
99 | |
---|
100 | # Inicializa a base de dados do Expresso |
---|
101 | create_db |
---|
102 | } |
---|
103 | |
---|
104 | bd_debian-squeeze () |
---|
105 | { |
---|
106 | DIR_PG="/var/lib/postgresql/8.4/main" |
---|
107 | DIR_CONF="/etc/postgresql/8.4/main" |
---|
108 | SQUEEZE=debian/squeeze/$DIR_CONF |
---|
109 | bd_debian $DIR_PG $SQUEEZE/postgresql.conf $SQUEEZE/pg_hba.conf $DIR_CONF |
---|
110 | } |
---|
111 | |
---|
112 | bd_ubuntu () |
---|
113 | { |
---|
114 | DIR_PG="$1" |
---|
115 | PG_CONF="$2" |
---|
116 | PG_HBA="$3" |
---|
117 | DIR_CONF="$4" |
---|
118 | # Instala os pacotes do servico |
---|
119 | apt-get install -y postgresql postgresql-common postgresql-client postgresql-client-common |
---|
120 | /etc/init.d/postgresql stop |
---|
121 | # Gera um link do initdb, para padronizar com o Centos |
---|
122 | ln -sf /usr/lib/postgresql/9.1/bin/initdb /usr/bin/ |
---|
123 | # Faz backup da base do Postgres |
---|
124 | mv $DIR_PG $DIR_PG.`date +"%s"` |
---|
125 | |
---|
126 | mkdir -p $DIR_PG/main |
---|
127 | chown -R postgres:postgres $DIR_PG |
---|
128 | chmod -R 770 $DIR_PG |
---|
129 | |
---|
130 | bd_ubuntu1110 $DIR_PG $PG_CONF $PG_HBA $DIR_CONF |
---|
131 | #rm -f $DIR_PG/postgresql.conf |
---|
132 | #rm -f $DIR_PG/pg_hba.conf |
---|
133 | /etc/init.d/postgresql start |
---|
134 | |
---|
135 | # Inicializa a base de dados do Expresso |
---|
136 | create_db |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | bd_ubuntu-11.10 () |
---|
141 | { |
---|
142 | DIR_PG="/var/lib/postgresql/9.1/main" |
---|
143 | DIR_CONF="/etc/postgresql/9.1/main" |
---|
144 | UBUNTU=ubuntu/11.10/$DIR_CONF |
---|
145 | bd_ubuntu $DIR_PG $UBUNTU/postgresql.conf $UBUNTU/pg_hba.conf $DIR_CONF |
---|
146 | } |
---|
147 | |
---|
148 | # Parametros: Iguais a funcao bd; |
---|
149 | bd_rhel () |
---|
150 | { |
---|
151 | DIR_PG="$1" |
---|
152 | PG_CONF="$2" |
---|
153 | PG_HBA="$3" |
---|
154 | DIR_CONF="$4" |
---|
155 | # Instala os pacotes do servico |
---|
156 | yum -y install postgresql postgresql-server |
---|
157 | service postgresql stop |
---|
158 | # Faz backup da base do Postgres |
---|
159 | mv $DIR_PG $DIR_PG.`date +"%s"` |
---|
160 | mkdir -p $DIR_PG/data |
---|
161 | chown -R postgres:postgres $DIR_PG |
---|
162 | |
---|
163 | bd $DIR_PG/data $PG_CONF $PG_HBA $DIR_CONF |
---|
164 | |
---|
165 | chown -R postgres:postgres $DIR_PG |
---|
166 | chmod 700 $DIR_PG |
---|
167 | |
---|
168 | service postgresql start |
---|
169 | chkconfig postgresql on |
---|
170 | |
---|
171 | # Inicializa a base de dados do Expresso |
---|
172 | create_db |
---|
173 | } |
---|
174 | |
---|
175 | bd_rhel6 () |
---|
176 | { |
---|
177 | DIR_PG="/var/lib/pgsql" |
---|
178 | DIR_CONF="$DIR_PG/data" |
---|
179 | RHEL6=rhel/6/var/lib/pgsql/data |
---|
180 | bd_rhel $DIR_PG $RHEL6/postgresql.conf $RHEL6/pg_hba.conf $DIR_CONF |
---|
181 | } |
---|
182 | |
---|