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
|
update_usage_postgresql()
{
echo >&2 " [-X]"
return 0 # backend-specific option(s) exist(s)
}
update_pgpass_postgresql()
{
PGPASS=$HOME/.pgpass
if [ -f ${PGPASS} ]; then
if=${PGPASS}
of=${PGPASS}.new
else
if=/dev/null
of=${PGPASS}
fi
if [ ! -f ${of} ]; then
touch ${of} || ABORT "${of}: cannot create"
chmod 0600 ${of} || ABORT "${of}: cannot change mode"
fi
$awk -F: 'BEGIN {
host="'$1'"
port='$2'
db="'$3'"
user="'$4'"
passwd="'$5'"
done = 0
}
{
if ($1 != host || $2 != port || $3 != db || $4 != user) {
print $0
} else {
printf "%s:%s:%s:%s:%s\n", host, port, db, user, passwd
done = 1
}
}
END {
if (!done)
printf "%s:%s:%s:%s:%s\n", host, port, db, user, passwd
}' ${if} >${of}
if [ X"$if" != X"/dev/null" ]; then
if cmp -s ${if} ${of}; then
rm -f ${PGPASS}.new
else
mv ${PGPASS} ${PGPASS}.bak
mv ${PGPASS}.new ${PGPASS}
fi
fi
}
update_postprocess_postgresql()
{
update_pgpass_postgresql localhost ${BACKEND_PORT} "${DB_NAME}" "${BACKEND_ADMIN_USER}" "${BACKEND_ADMIN_PASSWD}"
}
update_first_set_param_postgresql()
{
: ${BACKEND_PORT=`getvalue postgresql_server_port`}
: ${DB_NAME:=`getvalue postgresql_dbname`}
: ${BACKEND_USER:=`getvalue postgresql_user`}
: ${SUPPORT_XML_TYPE:=no}
unset PGHOST # force UNIX domain socket access
psql=${PGSQL_BINDIR}/psql
}
update_last_set_param_postgresql()
{
: ${BACKEND_ADMIN_PASSWD:=`cat ${BACKEND_DATA_DIR}/admin_password 2>/dev/null`}
}
update_sanity_postgresql()
{
rv=0
if [ X"$BACKEND_PORT" = X -o X"$DB_NAME" = X -o X"$BACKEND_USER" = X ]
then
echo "ERROR: postgresql backend is not configured" >&2
rv=1
fi
if [ X"$BACKEND_ADMIN_PASSWD" = X ]
then
echo "ERROR: password for postgresql administrator cannot be read. Use --prefix option or -l option to specify a data directory of the backend database." >&2
rv=1
fi
return $rv
}
update_postgresql()
{
if [ "`$psql -q -t -A -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME} -c '\dt Symlink' | wc -l`" -eq 0 ]; then
echo "${PROGNAME}: adding Symlink table"
(
sed -n '/CREATE TABLE Symlink/,/^)/p' $config_dir/gfarm.sql
cat <<__EOF__
GRANT SELECT, INSERT, UPDATE, DELETE ON Symlink TO $BACKEND_USER;
__EOF__
) |
$psql -q -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME}
fi
if [ "`$psql -q -t -A -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME} -c '\dt XAttr' | wc -l`" -eq 0 ]; then
echo "${PROGNAME}: adding XAttr table"
(
sed -n '/CREATE TABLE XAttr/,/^)/p' $config_dir/gfarm.sql
cat <<__EOF__
GRANT SELECT, INSERT, UPDATE, DELETE ON XAttr TO $BACKEND_USER;
__EOF__
) |
$psql -q -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME}
fi
if [ X"$SUPPORT_XML_TYPE" = Xyes -a \
"`$psql -q -t -A -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME} -c '\dt XmlAttr' | wc -l`" -eq 0 ]; then
echo "${PROGNAME}: adding XmlAttr table"
(
cat $config_dir/gfarm-xmlattr.sql
cat <<__EOF__
GRANT SELECT, INSERT, UPDATE, DELETE ON XmlAttr TO $BACKEND_USER;
__EOF__
) |
$psql -q -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME}
fi
if [ "`$psql -q -t -A -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME} -c '\dt QuotaUser' | wc -l`" -eq 0 ]; then
echo "${PROGNAME}: adding QuotaUser table"
(
sed -n '/CREATE TABLE QuotaUser/,/^)/p' $config_dir/gfarm.sql
cat <<__EOF__
GRANT SELECT, INSERT, UPDATE, DELETE ON QuotaUser TO $BACKEND_USER;
__EOF__
) |
$psql -q -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME}
fi
if [ "`$psql -q -t -A -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME} -c '\dt QuotaGroup' | wc -l`" -eq 0 ]; then
echo "${PROGNAME}: adding QuotaGroup table"
(
sed -n '/CREATE TABLE QuotaGroup/,/^)/p' $config_dir/gfarm.sql
cat <<__EOF__
GRANT SELECT, INSERT, UPDATE, DELETE ON QuotaGroup TO $BACKEND_USER;
__EOF__
) |
$psql -q -p ${BACKEND_PORT} -U ${BACKEND_ADMIN_USER} -d ${DB_NAME}
fi
}
update_access_db_postgresql()
{
OPTIONS="$*"
$psql -p $BACKEND_PORT $OPTIONS $DB_NAME $BACKEND_ADMIN_USER
}
|