ewarn "This configuration is only for new installations. You seem to"
ewarn "have already a modified sqlgrey.conf"
ewarn "Do you want to continue?"
SQLgrey_KEY_INPUT="y,n"
einfo " Press one of the keys [$SQLgrey_KEY_INPUT]: "
while true;do
read -n 1 -s SQLgrey_Ignore
case"$SQLgrey_Ignore" in
"y"|"Y")
break
;;
"n"|"N")
exit0
;;
esac
done
fi
## Per-RDBMS configuration ##
# POSTGRESQL
if[["${SQLgrey_DB_TYPE}"=="p"]];then
ewarn "If prompted for a password, please enter your PgSQL postgres password"
ewarn ""
einfo "Creating SQLgrey PostgreSQL database \"${SQLgrey_DB_NAME}\" and user \"${SQLgrey_DB_USER_NAME}\""
/usr/bin/psql -h ${SQLgrey_DB_HOST} -d template1 -U postgres -c "CREATE USER ${SQLgrey_DB_USER_NAME} WITH PASSWORD '${SQLgrey_DB_USER_PWD}' NOCREATEDB NOCREATEUSER; CREATE DATABASE ${SQLgrey_DB_NAME}; GRANT ALL PRIVILEGES ON DATABASE ${SQLgrey_DB_NAME} TO ${SQLgrey_DB_USER_NAME}; GRANT ALL PRIVILEGES ON SCHEMA public TO ${SQLgrey_DB_USER_NAME}; UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE usename='${SQLgrey_DB_USER_NAME}') WHERE datname='${SQLgrey_DB_NAME}';"
einfo "Changing SQLgrey configuration in sqlgrey.conf"
sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1Pg:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_user[ \t]*= \).*:\1${SQLgrey_DB_USER_NAME}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_pass[ \t]*= \).*:\1${SQLgrey_DB_USER_PWD}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_host[ \t]*= \).*:\1${SQLgrey_DB_HOST}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI"${SQLgrey_CONFIG}
elif[["${SQLgrey_DB_TYPE}"=="m"]];then
# MYSQL
ewarn "If prompted for a password, please enter your MySQL root password"
ewarn ""
einfo "Creating SQLgrey MySQL database \"${SQLgrey_DB_NAME}\" and user \"${SQLgrey_DB_USER_NAME}\""
echo -ne " "
/usr/bin/mysql -u root -h ${SQLgrey_DB_HOST} -p -e "CREATE DATABASE IF NOT EXISTS ${SQLgrey_DB_NAME} CHARACTER SET latin1; GRANT ALL ON ${SQLgrey_DB_NAME}.* TO ${SQLgrey_DB_USER_NAME}@${SQLgrey_DB_HOST} IDENTIFIED BY '${SQLgrey_DB_USER_PWD}';FLUSH PRIVILEGES;" -D mysql
echo
einfo "Changing SQLgrey configuration in sqlgrey.conf"
sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1mysql:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_user[ \t]*= \).*:\1${SQLgrey_DB_USER_NAME}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_pass[ \t]*= \).*:\1${SQLgrey_DB_USER_PWD}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_host[ \t]*= \).*:\1${SQLgrey_DB_HOST}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI"${SQLgrey_CONFIG}
elif[["${SQLgrey_DB_TYPE}"=="s"]];then
einfo "Changing SQLgrey configuration in sqlgrey.conf"
sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1SQLite:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_user[ \t]*=.*\)$:# \1:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_pass[ \t]*= .*\)$:# \1:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_host[ \t]*= .*\)$:# \1:gI"${SQLgrey_CONFIG}
sed -i "s:^[# ]*\(db_cleandelay[ \t]*= .*\)$:# \1:gI"${SQLgrey_CONFIG}
fi
echo
if[["${SQLgrey_DB_TYPE}" !="s"]];then
einfo "Note: the database password is stored in $SQLgrey_CONFIG"