diff options
author | Francesco Riosa <vivo@gentoo.org> | 2006-10-04 10:58:21 +0000 |
---|---|---|
committer | Francesco Riosa <vivo@gentoo.org> | 2006-10-04 10:58:21 +0000 |
commit | 8392e3b373680407d338b02ee930139ed15b13e8 (patch) | |
tree | 1b4d67c901440fe28fdc575076dc0b288c9d4e13 /mail-filter/sqlgrey | |
parent | Add 6.2 profile, now that baselayout is present. (diff) | |
download | gentoo-2-8392e3b373680407d338b02ee930139ed15b13e8.tar.gz gentoo-2-8392e3b373680407d338b02ee930139ed15b13e8.tar.bz2 gentoo-2-8392e3b373680407d338b02ee930139ed15b13e8.zip |
Initial import. Ebuild submitted by Lionel Bouton <lionel-dev AT bouton.name>
(Portage version: 2.1.1)
Diffstat (limited to 'mail-filter/sqlgrey')
-rw-r--r-- | mail-filter/sqlgrey/ChangeLog | 11 | ||||
-rw-r--r-- | mail-filter/sqlgrey/Manifest | 24 | ||||
-rw-r--r-- | mail-filter/sqlgrey/metadata.xml | 10 | ||||
-rw-r--r-- | mail-filter/sqlgrey/sqlgrey-1.6.7.ebuild | 246 | ||||
-rw-r--r-- | mail-filter/sqlgrey/sqlgrey-1.7.4.ebuild | 246 |
5 files changed, 537 insertions, 0 deletions
diff --git a/mail-filter/sqlgrey/ChangeLog b/mail-filter/sqlgrey/ChangeLog new file mode 100644 index 000000000000..e81c979d72e4 --- /dev/null +++ b/mail-filter/sqlgrey/ChangeLog @@ -0,0 +1,11 @@ +# ChangeLog for mail-filter/sqlgrey +# Copyright 1999-2006 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/mail-filter/sqlgrey/ChangeLog,v 1.1 2006/10/04 10:58:21 vivo Exp $ + + 04 Oct 2006; Francesco Riosa <vivo@gentoo.org> ChangeLog: + Initial import. Ebuild submitted by Lionel Bouton <lionel-dev AT bouton.name> + to bug#71535. + The ebuild is good quality and already support "emerge --config" so it has + only cosmetic changes to the submitted one. + Thanks Lionel :-) + diff --git a/mail-filter/sqlgrey/Manifest b/mail-filter/sqlgrey/Manifest new file mode 100644 index 000000000000..fc366e87b694 --- /dev/null +++ b/mail-filter/sqlgrey/Manifest @@ -0,0 +1,24 @@ +DIST sqlgrey-1.6.7.tar.bz2 42633 RMD160 6c857177886a5b3ffd982c43e4a6f36575427d27 SHA1 d293fa0ae3b9d9bcc28158a5fba30c85c7aed55c SHA256 f67b76799af93617f09a16bd7d5141b607d9952067fbb669f25bc3aa17bd7df5 +DIST sqlgrey-1.7.4.tar.bz2 56832 RMD160 d4b2e1d1321770ce8341b10d131b71118a003a18 SHA1 7c1031e51fa46b5e92119f2cc513b7f85d40d9fb SHA256 c5d2bb0632c9b9379538cc0bf77d0eae348d942f7199a4704b93c646f8c3c843 +EBUILD sqlgrey-1.6.7.ebuild 8483 RMD160 56106972afbaa2266d7f95c53dadb027d98ede0f SHA1 8ae58b02ff61ab494412da4be4e27cc3173a7527 SHA256 0642b4c94c53b0a1e3e7578956f24c41c9cce60f3a4455cac7fd54e964a23328 +MD5 0e73d8726a41ebabefb78cc02b24f9ac sqlgrey-1.6.7.ebuild 8483 +RMD160 56106972afbaa2266d7f95c53dadb027d98ede0f sqlgrey-1.6.7.ebuild 8483 +SHA256 0642b4c94c53b0a1e3e7578956f24c41c9cce60f3a4455cac7fd54e964a23328 sqlgrey-1.6.7.ebuild 8483 +EBUILD sqlgrey-1.7.4.ebuild 8483 RMD160 56106972afbaa2266d7f95c53dadb027d98ede0f SHA1 8ae58b02ff61ab494412da4be4e27cc3173a7527 SHA256 0642b4c94c53b0a1e3e7578956f24c41c9cce60f3a4455cac7fd54e964a23328 +MD5 0e73d8726a41ebabefb78cc02b24f9ac sqlgrey-1.7.4.ebuild 8483 +RMD160 56106972afbaa2266d7f95c53dadb027d98ede0f sqlgrey-1.7.4.ebuild 8483 +SHA256 0642b4c94c53b0a1e3e7578956f24c41c9cce60f3a4455cac7fd54e964a23328 sqlgrey-1.7.4.ebuild 8483 +MISC ChangeLog 421 RMD160 4422440d03d38f3c6b5389d3ee8a8f6c7f7fb20f SHA1 82b925c5cd7a0877b5425297436f523195108062 SHA256 c4937b0d366418ec08f15155eacd8d71ddf27746d6d866542197ddc83cb2884c +MD5 30ffe37f608b1136a8108ed817df4f52 ChangeLog 421 +RMD160 4422440d03d38f3c6b5389d3ee8a8f6c7f7fb20f ChangeLog 421 +SHA256 c4937b0d366418ec08f15155eacd8d71ddf27746d6d866542197ddc83cb2884c ChangeLog 421 +MISC metadata.xml 328 RMD160 f15b94cd654f07e5be8b165912c0842cdcf92502 SHA1 bd1bbad4ab44fa278e28e960f12d63b2eb5a7526 SHA256 d1ce5241a8e79cd6513412357febb6f352bda7f161b9494135d12b0c6c7bc5b9 +MD5 89f7efa3dd66664b638a1eec05a77621 metadata.xml 328 +RMD160 f15b94cd654f07e5be8b165912c0842cdcf92502 metadata.xml 328 +SHA256 d1ce5241a8e79cd6513412357febb6f352bda7f161b9494135d12b0c6c7bc5b9 metadata.xml 328 +MD5 aa26afb32127c29e1a0d46faef7f890d files/digest-sqlgrey-1.6.7 241 +RMD160 4d27646e4a8118bd31219cf9797c673aca259e7c files/digest-sqlgrey-1.6.7 241 +SHA256 d6de1868a3ca7ec80a6aa1393df72c1729f4c9f2d0a367c15e950d3e161865ed files/digest-sqlgrey-1.6.7 241 +MD5 4a7a788d9853f156bad2121220c87973 files/digest-sqlgrey-1.7.4 241 +RMD160 95c47d44283af6c5231d80870c35d3771cfe7630 files/digest-sqlgrey-1.7.4 241 +SHA256 82651c60a286e629ef90a2104dbca343fcca93881145f5bd08186ddbccab76a1 files/digest-sqlgrey-1.7.4 241 diff --git a/mail-filter/sqlgrey/metadata.xml b/mail-filter/sqlgrey/metadata.xml new file mode 100644 index 000000000000..f048cd5b7bb5 --- /dev/null +++ b/mail-filter/sqlgrey/metadata.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> +<herd>net-mail</herd> +<maintainer> + <email>vivo@gentoo.org</email> +</maintainer> +<longdescription>SQLgrey is a postfix policy service implementing a grey-listing +policy.</longdescription> +</pkgmetadata> diff --git a/mail-filter/sqlgrey/sqlgrey-1.6.7.ebuild b/mail-filter/sqlgrey/sqlgrey-1.6.7.ebuild new file mode 100644 index 000000000000..141192c7bb7c --- /dev/null +++ b/mail-filter/sqlgrey/sqlgrey-1.6.7.ebuild @@ -0,0 +1,246 @@ +# Copyright 1999-2006 Gentoo Foundation# Distributed under the terms of the GNU General Public License v2 +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/mail-filter/sqlgrey/sqlgrey-1.6.7.ebuild,v 1.1 2006/10/04 10:58:21 vivo Exp $ + +inherit eutils + +DESCRIPTION="SQLgrey is a postfix policy service implementing a grey-listing policy" +SRC_URI="mirror://sourceforge/sqlgrey/${PN}-${PV}.tar.bz2" +HOMEPAGE="http://sqlgrey.sourceforge.net/" +LICENSE="GPL-2" +SLOT="0" +IUSE="mysql postgres sqlite" +RDEPEND="dev-lang/perl + dev-perl/DBI + dev-perl/net-server + || ( postgres? ( dev-perl/DBD-Pg ) + sqlite? ( dev-perl/DBD-SQLite ) + mysql? ( dev-perl/DBD-mysql ) + dev-perl/DBD-Pg + )" +DEPEND="$RDEPEND + sys-apps/sed" +KEYWORDS="~x86 ~amd64" + +pkg_setup() { + has_version dev-perl/IO-Multiplex || die "IO-Multiplex needed. Please emerge it or run g-cpan.pl IO::Multiplex" + enewgroup sqlgrey + enewuser sqlgrey -1 -1 /var/spool/sqlgrey sqlgrey +} + +src_install () { + make gentoo-install ROOTDIR=${D} + prepall + dodoc HOWTO FAQ README README.OPTINOUT README.PERF COPYING TODO Changelog + + # keeps SQLgrey data in /var/spool/sqlgrey + diropts -m0775 -o sqlgrey -g sqlgrey + dodir /var/spool/sqlgrey +} + +pkg_postinst() { + echo + einfo "To make use of greylisting, please update your postfix config." + einfo + einfo "Put something like this in /etc/postfix/main.cf:" + einfo " smtpd_recipient_restrictions =" + einfo " ..." + einfo " check_policy_service inet:127.0.0.1:2501" + einfo + einfo "Remember to restart Postfix after that change. Also remember" + einfo "to make the daemon start durig boot:" + einfo " rc-update add sqlgrey default" + einfo + echo + einfo "To setup SQLgrey to run out-of-the-box on your system, run:" + einfo "emerge --config ${PF}" + echo + ewarn "Read the documentation for more info (perldoc sqlgrey) or the" + ewarn "included howto /usr/share/doc/${PF}/HOWTO.gz" + echo + ebeep 2 + epause 5 +} + +pkg_config () { + + # SQLgrey configuration file + local SQLgrey_CONFIG="/etc/sqlgrey/sqlgrey.conf" + local SQLgrey_DB_USER_NAME="sqlgrey" + local SQLgrey_DB_NAME="sqlgrey" + + # Check if a password is set in sqlgrey.conf + local SQLgrey_CONF_PWD="" + if [ -f "${SQLgrey_CONFIG}" ]; then + if (grep -iq "^[\t ]*db_pass[\t ]*=[\t ]*.*$" ${SQLgrey_CONFIG}); then + # User already has a db_pass entry + SQLgrey_CONF_PWD="$(sed -n 's:^[\t ]*db_pass[\t ]*=[\t ]*\(.*\)[\t ]*:\1:gIp' ${SQLgrey_CONFIG})" + else + SQLgrey_CONF_PWD="" + fi + else + ewarn "SQLgrey configuration missing. Exiting now." + echo + exit 0 + fi + + # Check if we need SQLgrey to configure for this system or not + local SQLgrey_DB_HOST="localhost" + local SQLgrey_KEY_INPUT="l,r,x" + einfo "SQLgrey database backend configuration" + einfo " Please select where SQLgrey database will run:" + einfo " [l] Database backend runs on localhost" + einfo " [r] Database backend runs on remote host" + einfo " [x] Exit" + echo + einfo " Press one of the keys [${SQLgrey_KEY_INPUT}]: " + while true; do + read -n 1 -s SQLgrey_ACCESS_TYPE + case "${SQLgrey_ACCESS_TYPE}" in + "r" | "R" ) + SQLgrey_ACCESS_TYPE="r" + einfo " remote setup" + read -p " Please enter the remote hostname: " SQLgrey_DB_HOST + echo + break + ;; + "l" | "L" ) + SQLgrey_ACCESS_TYPE="l" + einfo " local setup" + echo + break + ;; + "x" | "X" ) + exit 0 + ;; + esac + done + + # Generate random password + if [[ "${SQLgrey_CONF_PWD}" == "" ]]; then + einfo "Generating random database user password..." + local SQLgrey_PWD_MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + local SQLgrey_DB_USER_PWD="" + while [ "${n:=1}" -le "16" ]; do + SQLgrey_DB_USER_PWD="${SQLgrey_DB_USER_PWD}${SQLgrey_PWD_MATRIX:$(($RANDOM%${#SQLgrey_PWD_MATRIX})):1}" + let n+=1 + done + else + einfo "Reusing current database user password..." + local SQLgrey_DB_USER_PWD="${SQLgrey_CONF_PWD}" + fi + echo + + # Configure the various database backends + local SQLgrey_KEY_INPUT="" + einfo "Creating SQLgrey database backend data and configuration" + einfo " Please select what kind of database you like to use:" + if use postgres || has_version dev-perl/DBD-Pg ; then + einfo " [p] PostgreSQL" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},p" + fi + if use mysql || has_version dev-perl/DBD-mysql ; then + einfo " [m] MySQL" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},m" + fi + if use sqlite || has_version dev-perl/DBD-SQLite ; then + einfo " [s] SQLite" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},s" + fi + einfo " [x] Exit" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},x" + echo + einfo " Press one of the keys [${SQLgrey_KEY_INPUT:1}]: " + while true; do + read -n 1 -s SQLgrey_DB_TYPE + case "${SQLgrey_DB_TYPE}" in + "p" | "P" ) + SQLgrey_DB_TYPE="p" + einfo " PostgreSQL database backend" + echo + break + ;; + "m" | "M" ) + SQLgrey_DB_TYPE="m" + einfo " MySQL database backend" + echo + break + ;; + "s" | "S" ) + SQLgrey_DB_TYPE="s" + einfo " SQLite database backend" + echo + break + ;; + "x" | "X" ) + exit 0 + ;; + esac + done + + # If we don't use SQLite, the password must not be set + if [[ ( "${SQLgrey_DB_TYPE}" != "s" ) && ( "${SQLgrey_CONF_PWD}" != "" ) ]]; then + 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" ) + exit 0 + ;; + 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}; 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" + fi +} diff --git a/mail-filter/sqlgrey/sqlgrey-1.7.4.ebuild b/mail-filter/sqlgrey/sqlgrey-1.7.4.ebuild new file mode 100644 index 000000000000..f33c10bd801d --- /dev/null +++ b/mail-filter/sqlgrey/sqlgrey-1.7.4.ebuild @@ -0,0 +1,246 @@ +# Copyright 1999-2006 Gentoo Foundation# Distributed under the terms of the GNU General Public License v2 +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/mail-filter/sqlgrey/sqlgrey-1.7.4.ebuild,v 1.1 2006/10/04 10:58:21 vivo Exp $ + +inherit eutils + +DESCRIPTION="SQLgrey is a postfix policy service implementing a grey-listing policy" +SRC_URI="mirror://sourceforge/sqlgrey/${PN}-${PV}.tar.bz2" +HOMEPAGE="http://sqlgrey.sourceforge.net/" +LICENSE="GPL-2" +SLOT="0" +IUSE="mysql postgres sqlite" +RDEPEND="dev-lang/perl + dev-perl/DBI + dev-perl/net-server + || ( postgres? ( dev-perl/DBD-Pg ) + sqlite? ( dev-perl/DBD-SQLite ) + mysql? ( dev-perl/DBD-mysql ) + dev-perl/DBD-Pg + )" +DEPEND="$RDEPEND + sys-apps/sed" +KEYWORDS="~x86 ~amd64" + +pkg_setup() { + has_version dev-perl/IO-Multiplex || die "IO-Multiplex needed. Please emerge it or run g-cpan.pl IO::Multiplex" + enewgroup sqlgrey + enewuser sqlgrey -1 -1 /var/spool/sqlgrey sqlgrey +} + +src_install () { + make gentoo-install ROOTDIR=${D} + prepall + dodoc HOWTO FAQ README README.OPTINOUT README.PERF COPYING TODO Changelog + + # keeps SQLgrey data in /var/spool/sqlgrey + diropts -m0775 -o sqlgrey -g sqlgrey + dodir /var/spool/sqlgrey +} + +pkg_postinst() { + echo + einfo "To make use of greylisting, please update your postfix config." + einfo + einfo "Put something like this in /etc/postfix/main.cf:" + einfo " smtpd_recipient_restrictions =" + einfo " ..." + einfo " check_policy_service inet:127.0.0.1:2501" + einfo + einfo "Remember to restart Postfix after that change. Also remember" + einfo "to make the daemon start durig boot:" + einfo " rc-update add sqlgrey default" + einfo + echo + einfo "To setup SQLgrey to run out-of-the-box on your system, run:" + einfo "emerge --config ${PF}" + echo + ewarn "Read the documentation for more info (perldoc sqlgrey) or the" + ewarn "included howto /usr/share/doc/${PF}/HOWTO.gz" + echo + ebeep 2 + epause 5 +} + +pkg_config () { + + # SQLgrey configuration file + local SQLgrey_CONFIG="/etc/sqlgrey/sqlgrey.conf" + local SQLgrey_DB_USER_NAME="sqlgrey" + local SQLgrey_DB_NAME="sqlgrey" + + # Check if a password is set in sqlgrey.conf + local SQLgrey_CONF_PWD="" + if [ -f "${SQLgrey_CONFIG}" ]; then + if (grep -iq "^[\t ]*db_pass[\t ]*=[\t ]*.*$" ${SQLgrey_CONFIG}); then + # User already has a db_pass entry + SQLgrey_CONF_PWD="$(sed -n 's:^[\t ]*db_pass[\t ]*=[\t ]*\(.*\)[\t ]*:\1:gIp' ${SQLgrey_CONFIG})" + else + SQLgrey_CONF_PWD="" + fi + else + ewarn "SQLgrey configuration missing. Exiting now." + echo + exit 0 + fi + + # Check if we need SQLgrey to configure for this system or not + local SQLgrey_DB_HOST="localhost" + local SQLgrey_KEY_INPUT="l,r,x" + einfo "SQLgrey database backend configuration" + einfo " Please select where SQLgrey database will run:" + einfo " [l] Database backend runs on localhost" + einfo " [r] Database backend runs on remote host" + einfo " [x] Exit" + echo + einfo " Press one of the keys [${SQLgrey_KEY_INPUT}]: " + while true; do + read -n 1 -s SQLgrey_ACCESS_TYPE + case "${SQLgrey_ACCESS_TYPE}" in + "r" | "R" ) + SQLgrey_ACCESS_TYPE="r" + einfo " remote setup" + read -p " Please enter the remote hostname: " SQLgrey_DB_HOST + echo + break + ;; + "l" | "L" ) + SQLgrey_ACCESS_TYPE="l" + einfo " local setup" + echo + break + ;; + "x" | "X" ) + exit 0 + ;; + esac + done + + # Generate random password + if [[ "${SQLgrey_CONF_PWD}" == "" ]]; then + einfo "Generating random database user password..." + local SQLgrey_PWD_MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + local SQLgrey_DB_USER_PWD="" + while [ "${n:=1}" -le "16" ]; do + SQLgrey_DB_USER_PWD="${SQLgrey_DB_USER_PWD}${SQLgrey_PWD_MATRIX:$(($RANDOM%${#SQLgrey_PWD_MATRIX})):1}" + let n+=1 + done + else + einfo "Reusing current database user password..." + local SQLgrey_DB_USER_PWD="${SQLgrey_CONF_PWD}" + fi + echo + + # Configure the various database backends + local SQLgrey_KEY_INPUT="" + einfo "Creating SQLgrey database backend data and configuration" + einfo " Please select what kind of database you like to use:" + if use postgres || has_version dev-perl/DBD-Pg ; then + einfo " [p] PostgreSQL" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},p" + fi + if use mysql || has_version dev-perl/DBD-mysql ; then + einfo " [m] MySQL" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},m" + fi + if use sqlite || has_version dev-perl/DBD-SQLite ; then + einfo " [s] SQLite" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},s" + fi + einfo " [x] Exit" + SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},x" + echo + einfo " Press one of the keys [${SQLgrey_KEY_INPUT:1}]: " + while true; do + read -n 1 -s SQLgrey_DB_TYPE + case "${SQLgrey_DB_TYPE}" in + "p" | "P" ) + SQLgrey_DB_TYPE="p" + einfo " PostgreSQL database backend" + echo + break + ;; + "m" | "M" ) + SQLgrey_DB_TYPE="m" + einfo " MySQL database backend" + echo + break + ;; + "s" | "S" ) + SQLgrey_DB_TYPE="s" + einfo " SQLite database backend" + echo + break + ;; + "x" | "X" ) + exit 0 + ;; + esac + done + + # If we don't use SQLite, the password must not be set + if [[ ( "${SQLgrey_DB_TYPE}" != "s" ) && ( "${SQLgrey_CONF_PWD}" != "" ) ]]; then + 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" ) + exit 0 + ;; + 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}; 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" + fi +} |