|
|
|
@ -2,12 +2,19 @@
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
sql() {
|
|
|
|
|
local user
|
|
|
|
|
user="$1"
|
|
|
|
|
shift
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U "$user" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# only allow the $WUBLOADER_USER to connect remotely rather than all users
|
|
|
|
|
sed -i "/host all all all/d" "$PGDATA/pg_hba.conf"
|
|
|
|
|
echo "host all $WUBLOADER_USER all md5" >> "$PGDATA/pg_hba.conf"
|
|
|
|
|
|
|
|
|
|
echo "Creating $WUBLOADER_USER"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOSQL
|
|
|
|
|
sql "$POSTGRES_USER" <<-EOSQL
|
|
|
|
|
|
|
|
|
|
CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD';
|
|
|
|
|
|
|
|
|
@ -18,7 +25,7 @@ if [ -n "$REPLICATION_USER" ]; then
|
|
|
|
|
echo "Creating $REPLICATION_USER"
|
|
|
|
|
# allow the $REPLICATION user to replicate remotely
|
|
|
|
|
echo "host replication $REPLICATION_USER all md5" >> "$PGDATA/pg_hba.conf"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOSQL
|
|
|
|
|
sql "$POSTGRES_USER" <<-EOSQL
|
|
|
|
|
|
|
|
|
|
CREATE USER $REPLICATION_USER LOGIN REPLICATION PASSWORD '$REPLICATION_PASSWORD';
|
|
|
|
|
|
|
|
|
@ -35,27 +42,27 @@ if [ -n "$REPLICATION_USER" ]; then
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Applying schema for $POSTGRES_DB"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $WUBLOADER_USER -d $POSTGRES_DB < /schema.sql
|
|
|
|
|
sql "$WUBLOADER_USER" -d "$POSTGRES_DB" < /schema.sql
|
|
|
|
|
|
|
|
|
|
if [ -a /mnt/wubloader/nodes.csv ]; then
|
|
|
|
|
echo "Loading nodes from nodes.csv"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOF
|
|
|
|
|
sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOF
|
|
|
|
|
COPY nodes FROM '/mnt/wubloader/nodes.csv' DELIMITER ',' CSV HEADER;
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -a /mnt/wubloader/editors.csv ]; then
|
|
|
|
|
echo "Loading editors from editors.csv"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOF
|
|
|
|
|
sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOF
|
|
|
|
|
COPY editors FROM '/mnt/wubloader/editors.csv' DELIMITER ',' CSV HEADER;
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -n "READONLY_USER" ]; then
|
|
|
|
|
if [ -n "$READONLY_USER" ]; then
|
|
|
|
|
echo "Creating $READONLY_USER"
|
|
|
|
|
# allow $READONLY_USER to connect remotely
|
|
|
|
|
echo "host all $READONLY_USER all md5" >> "$PGDATA/pg_hba.conf"
|
|
|
|
|
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOSQL
|
|
|
|
|
sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOSQL
|
|
|
|
|
|
|
|
|
|
CREATE USER $READONLY_USER WITH CONNECTION LIMIT 50 LOGIN PASSWORD '$READONLY_PASSWORD';
|
|
|
|
|
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $READONLY_USER;
|
|
|
|
@ -64,3 +71,14 @@ if [ -n "READONLY_USER" ]; then
|
|
|
|
|
|
|
|
|
|
EOSQL
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -n "$BUSCRIBE_USER" ]; then
|
|
|
|
|
echo "Creating $BUSCRIBE_USER"
|
|
|
|
|
echo "host all $BUSCRIBE_USER all md5" >> "$PGDATA/pg_hba.conf"
|
|
|
|
|
sql "$POSTGRES_USER" <<-EOSQL
|
|
|
|
|
CREATE USER $BUSCRIBE_USER LOGIN PASSWORD '$BUSCRIBE_PASSWORD';
|
|
|
|
|
EOSQL
|
|
|
|
|
|
|
|
|
|
echo "Applying schema for $BUSCRIBE_DB"
|
|
|
|
|
sql "$BUSCRIBE_USER" -d "$BUSCRIBE_DB" < /buscribe.sql
|
|
|
|
|
fi
|
|
|
|
|