/[gentoo-x86]/mail-filter/sqlgrey/sqlgrey-1.7.6.ebuild
Gentoo

Contents of /mail-filter/sqlgrey/sqlgrey-1.7.6.ebuild

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Tue Jun 5 00:08:32 2012 UTC (2 years, 6 months ago) by zmedico
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +3 -3 lines
inherit user for enewgroup and enewuser

(Portage version: 2.2.0_alpha110/cvs/Linux i686)

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/mail-filter/sqlgrey/sqlgrey-1.7.6.ebuild,v 1.5 2011/06/21 16:11:13 eras Exp $
4
5 inherit eutils user
6
7 DESCRIPTION="SQLgrey is a postfix policy service implementing a grey-listing policy"
8 SRC_URI="mirror://sourceforge/sqlgrey/${P}.tar.bz2"
9 HOMEPAGE="http://sqlgrey.sourceforge.net/"
10 LICENSE="GPL-2"
11 SLOT="0"
12 IUSE="mysql postgres sqlite"
13 RDEPEND="dev-lang/perl
14 dev-perl/DBI
15 dev-perl/net-server
16 dev-perl/Date-Calc
17 virtual/mailx
18 postgres? ( dev-perl/DBD-Pg )
19 sqlite? ( dev-perl/DBD-SQLite )
20 mysql? ( dev-perl/DBD-mysql )
21 !postgres? ( !mysql? ( !sqlite? ( dev-perl/DBD-Pg ) ) )"
22 DEPEND="$RDEPEND
23 sys-apps/sed"
24 KEYWORDS="amd64 ~sparc x86"
25
26 pkg_setup() {
27 enewgroup sqlgrey
28 enewuser sqlgrey -1 -1 /var/spool/sqlgrey sqlgrey
29 }
30
31 src_unpack() {
32 unpack ${A}
33 epatch "${FILESDIR}/${P}-init.patch"
34 }
35
36 src_install () {
37
38 make gentoo-install ROOTDIR="${D}"
39 dodoc HOWTO FAQ README README.OPTINOUT README.PERF TODO Changelog
40
41 # keeps SQLgrey data in /var/spool/sqlgrey
42 diropts -m0775 -o sqlgrey -g sqlgrey
43 keepdir /var/spool/sqlgrey
44 }
45
46 pkg_postinst() {
47 echo
48 einfo "To make use of greylisting, please update your postfix config."
49 einfo
50 einfo "Put something like this in /etc/postfix/main.cf:"
51 einfo " smtpd_recipient_restrictions ="
52 einfo " ..."
53 einfo " check_policy_service inet:127.0.0.1:2501"
54 einfo
55 einfo "Remember to restart Postfix after that change. Also remember"
56 einfo "to make the daemon start durig boot:"
57 einfo " rc-update add sqlgrey default"
58 einfo
59 echo
60 einfo "To setup SQLgrey to run out-of-the-box on your system, run:"
61 einfo "emerge --config ${PN}"
62 echo
63 ewarn "Read the documentation for more info (perldoc sqlgrey) or the"
64 ewarn "included howto /usr/share/doc/${PF}/HOWTO.gz"
65 echo
66 ewarn "If you are using MySQL >= 4.1 use \"latin1\" as charset for"
67 ewarn "the SQLgrey db"
68 echo
69 ebeep 2
70 epause 5
71 }
72
73 pkg_config () {
74
75 # SQLgrey configuration file
76 local SQLgrey_CONFIG="/etc/sqlgrey/sqlgrey.conf"
77 local SQLgrey_DB_USER_NAME="sqlgrey"
78 local SQLgrey_DB_NAME="sqlgrey"
79
80 # Check if a password is set in sqlgrey.conf
81 local SQLgrey_CONF_PWD=""
82 if [ -f "${SQLgrey_CONFIG}" ]; then
83 if (grep -iq "^[\t ]*db_pass[\t ]*=[\t ]*.*$" ${SQLgrey_CONFIG}); then
84 # User already has a db_pass entry
85 SQLgrey_CONF_PWD="$(sed -n 's:^[\t ]*db_pass[\t ]*=[\t ]*\(.*\)[\t ]*:\1:gIp' ${SQLgrey_CONFIG})"
86 else
87 SQLgrey_CONF_PWD=""
88 fi
89 else
90 ewarn "SQLgrey configuration missing. Exiting now."
91 echo
92 exit 0
93 fi
94
95 # Check if we need SQLgrey to configure for this system or not
96 local SQLgrey_DB_HOST="localhost"
97 local SQLgrey_KEY_INPUT="l,r,x"
98 einfo "SQLgrey database backend configuration"
99 einfo " Please select where SQLgrey database will run:"
100 einfo " [l] Database backend runs on localhost"
101 einfo " [r] Database backend runs on remote host"
102 einfo " [x] Exit"
103 echo
104 einfo " Press one of the keys [${SQLgrey_KEY_INPUT}]: "
105 while true; do
106 read -n 1 -s SQLgrey_ACCESS_TYPE
107 case "${SQLgrey_ACCESS_TYPE}" in
108 "r" | "R" )
109 SQLgrey_ACCESS_TYPE="r"
110 einfo " remote setup"
111 read -p " Please enter the remote hostname: " SQLgrey_DB_HOST
112 echo
113 break
114 ;;
115 "l" | "L" )
116 SQLgrey_ACCESS_TYPE="l"
117 einfo " local setup"
118 echo
119 break
120 ;;
121 "x" | "X" )
122 exit 0
123 ;;
124 esac
125 done
126
127 # Generate random password
128 if [[ "${SQLgrey_CONF_PWD}" == "" ]]; then
129 einfo "Generating random database user password..."
130 local SQLgrey_PWD_MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
131 local SQLgrey_DB_USER_PWD=""
132 while [ "${n:=1}" -le "16" ]; do
133 SQLgrey_DB_USER_PWD="${SQLgrey_DB_USER_PWD}${SQLgrey_PWD_MATRIX:$(($RANDOM%${#SQLgrey_PWD_MATRIX})):1}"
134 let n+=1
135 done
136 else
137 einfo "Reusing current database user password..."
138 local SQLgrey_DB_USER_PWD="${SQLgrey_CONF_PWD}"
139 fi
140 echo
141
142 # Configure the various database backends
143 local SQLgrey_KEY_INPUT=""
144 einfo "Creating SQLgrey database backend data and configuration"
145 einfo " Please select what kind of database you like to use:"
146 if use postgres || has_version dev-perl/DBD-Pg ; then
147 einfo " [p] PostgreSQL"
148 SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},p"
149 fi
150 if use mysql || has_version dev-perl/DBD-mysql ; then
151 einfo " [m] MySQL"
152 SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},m"
153 fi
154 if use sqlite || has_version dev-perl/DBD-SQLite ; then
155 einfo " [s] SQLite"
156 SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},s"
157 fi
158 einfo " [x] Exit"
159 SQLgrey_KEY_INPUT="${SQLgrey_KEY_INPUT},x"
160 echo
161 einfo " Press one of the keys [${SQLgrey_KEY_INPUT:1}]: "
162 while true; do
163 read -n 1 -s SQLgrey_DB_TYPE
164 case "${SQLgrey_DB_TYPE}" in
165 "p" | "P" )
166 SQLgrey_DB_TYPE="p"
167 einfo " PostgreSQL database backend"
168 echo
169 break
170 ;;
171 "m" | "M" )
172 SQLgrey_DB_TYPE="m"
173 einfo " MySQL database backend"
174 echo
175 break
176 ;;
177 "s" | "S" )
178 SQLgrey_DB_TYPE="s"
179 einfo " SQLite database backend"
180 echo
181 break
182 ;;
183 "x" | "X" )
184 exit 0
185 ;;
186 esac
187 done
188
189 # If we don't use SQLite, the password must not be set
190 if [[ ( "${SQLgrey_DB_TYPE}" != "s" ) && ( "${SQLgrey_CONF_PWD}" != "" ) ]]; then
191 ewarn "This configuration is only for new installations. You seem to"
192 ewarn "have already a modified sqlgrey.conf"
193 ewarn "Do you want to continue?"
194 SQLgrey_KEY_INPUT="y,n"
195 einfo " Press one of the keys [$SQLgrey_KEY_INPUT]: "
196 while true; do
197 read -n 1 -s SQLgrey_Ignore
198 case "$SQLgrey_Ignore" in
199 "y"|"Y" )
200 break
201 ;;
202 "n"|"N" )
203 exit 0
204 ;;
205 esac
206 done
207 fi
208
209 ## Per-RDBMS configuration ##
210 # POSTGRESQL
211 if [[ "${SQLgrey_DB_TYPE}" == "p" ]] ; then
212
213 ewarn "If prompted for a password, please enter your PgSQL postgres password"
214 ewarn ""
215
216 einfo "Creating SQLgrey PostgreSQL database \"${SQLgrey_DB_NAME}\" and user \"${SQLgrey_DB_USER_NAME}\""
217 /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}';"
218
219 einfo "Changing SQLgrey configuration in sqlgrey.conf"
220 sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1Pg:gI" ${SQLgrey_CONFIG}
221 sed -i "s:^[# ]*\(db_user[ \t]*= \).*:\1${SQLgrey_DB_USER_NAME}:gI" ${SQLgrey_CONFIG}
222 sed -i "s:^[# ]*\(db_pass[ \t]*= \).*:\1${SQLgrey_DB_USER_PWD}:gI" ${SQLgrey_CONFIG}
223 sed -i "s:^[# ]*\(db_host[ \t]*= \).*:\1${SQLgrey_DB_HOST}:gI" ${SQLgrey_CONFIG}
224 sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI" ${SQLgrey_CONFIG}
225 elif [[ "${SQLgrey_DB_TYPE}" == "m" ]] ; then
226 # MYSQL
227 ewarn "If prompted for a password, please enter your MySQL root password"
228 ewarn ""
229
230 einfo "Creating SQLgrey MySQL database \"${SQLgrey_DB_NAME}\" and user \"${SQLgrey_DB_USER_NAME}\""
231 echo -ne " "
232 /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
233 echo
234
235 einfo "Changing SQLgrey configuration in sqlgrey.conf"
236 sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1mysql:gI" ${SQLgrey_CONFIG}
237 sed -i "s:^[# ]*\(db_user[ \t]*= \).*:\1${SQLgrey_DB_USER_NAME}:gI" ${SQLgrey_CONFIG}
238 sed -i "s:^[# ]*\(db_pass[ \t]*= \).*:\1${SQLgrey_DB_USER_PWD}:gI" ${SQLgrey_CONFIG}
239 sed -i "s:^[# ]*\(db_host[ \t]*= \).*:\1${SQLgrey_DB_HOST}:gI" ${SQLgrey_CONFIG}
240 sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI" ${SQLgrey_CONFIG}
241 elif [[ "${SQLgrey_DB_TYPE}" == "s" ]] ; then
242 einfo "Changing SQLgrey configuration in sqlgrey.conf"
243 sed -i "s:^[# ]*\(db_type[ \t]*= \).*:\1SQLite:gI" ${SQLgrey_CONFIG}
244 sed -i "s:^[# ]*\(db_name[ \t]*= \).*:\1${SQLgrey_DB_NAME}:gI" ${SQLgrey_CONFIG}
245 sed -i "s:^[# ]*\(db_user[ \t]*=.*\)$:# \1:gI" ${SQLgrey_CONFIG}
246 sed -i "s:^[# ]*\(db_pass[ \t]*= .*\)$:# \1:gI" ${SQLgrey_CONFIG}
247 sed -i "s:^[# ]*\(db_host[ \t]*= .*\)$:# \1:gI" ${SQLgrey_CONFIG}
248 sed -i "s:^[# ]*\(db_cleandelay[ \t]*= .*\)$:# \1:gI" ${SQLgrey_CONFIG}
249 fi
250 echo
251 if [[ "${SQLgrey_DB_TYPE}" != "s" ]]; then
252 einfo "Note: the database password is stored in $SQLgrey_CONFIG"
253 fi
254 }

  ViewVC Help
Powered by ViewVC 1.1.20