summaryrefslogtreecommitdiff
blob: f31f77e3d195a5335bea9cf048fb8a193f7a3405 (plain)
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
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-libs/nss-mysql/nss-mysql-0.43-r1.ebuild,v 1.9 2004/07/02 08:50:04 eradicator Exp $

DESCRIPTION="NSS MySQL Module"
HOMEPAGE="http://savannah.gnu.org/projects/${PN}"
SRC_URI="http://savannah.gnu.org/download/${PN}/${PN}.pkg/${PV}/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="x86 ~alpha ~amd64 hppa ~mips ~ppc sparc"
IUSE="static"

DEPEND="virtual/libc
	>=dev-db/mysql-3.23.51-r1"
RDEPEND="${DEPEND}
	app-arch/gzip
	sys-apps/sed
	!sys-libs/libnss-mysql"

src_compile() {
	use static && myconf="--enable-static"
	./configure ${myconf} \
		--host=${CHOST} \
		--prefix=/usr \
		--infodir=/usr/share/info \
		--sysconfdir=/etc/nss-mysql \
		--libdir=/lib \
		--mandir=/usr/share/man || die "./configure failed"
	emake || die
}

src_install () {
	make DESTDIR=${D} install || die
	dodoc AUTHORS COPYING ChangeLog INSTALL NEWS README SHADOW THANKS TODO UPGRADE sample.sql
	newdoc ${FILESDIR}/gentoo.sql.${PN}-0.40.gentoo gentoo.sql
}

pkg_postinst() {
	einfo "Execute ebuild /var/db/pkg/${CATEGORY}/${PF}/${PF}.ebuild config"
	einfo "to autosetup nss-mysql and the mysql tables."
	einfo "You should then edit your /etc/nsswitch.conf file to activate nss_mysql"
	einfo "and suit your intentions. Below is an partial example:"
	einfo
	einfo "passwd:	files mysql"
	einfo "shadow:	files mysql"
	einfo "group:	files mysql"
}

pkg_config() {
	local PASS=""
	local PAS2=""
	echo "In order to continue we'll need to know a MySQL username with enough"
	echo "privleges to create databases, mysql-users and grant privleges,"
	echo "typically a user named root."
	echo
	echo -n "MySQL-root-user [root]: "
	read USERNAME
	if [ -z "${USERNAME}" ]; then
		USERNAME="root"
	fi
	echo -n "Is it required to use a password in order to access mysql with ${USERNAME} [Y/n]: "
	read NEEDPASS
	POPT="-p"
	if [ "${NEEDPASS}" == "n" ]; then
		POPT=""
	fi
	cmd="${ROOT}/usr/bin/makepasswd --minchars=10 --maxchars=12 2>/dev/null"
	if [ -z "${PASS}" -a -x "${cmd/ *}" ]; then
		einfo "makepasswd found for password generation"
		PASS=`eval $cmd`
		PAS2=`eval $cmd`
	fi
	cmd="${ROOT}/usr/bin/passook 2>/dev/null"
	if [ -z "${PASS}" -a -x "${cmd/ *}" ]; then
		einfo "passook found for password generation"
		PASS=`eval $cmd`
		PAS2=`eval $cmd`
	fi
	cmd="${ROOT}/bin/dd if=/dev/random bs=32k count=1 2>/dev/null | md5sum | awk '{print \$1}'"
	if [ -z "${PASS}" -a -x "${cmd/ *}" ]; then
		einfo "Falling back to dd and m5sum..."
		PASS=`eval $cmd``eval $cmd`
		PAS2=`eval $cmd``eval $cmd`
	fi
	if [ -z "${PASS}" ]; then
		echo "";
		echo "Didn't manage to find a passwd-generator, please type a passwords of your choise";
		echo -n "Shadow-access-password (root-only): ";
		read PASS
		echo -n "Select-public-info-password: ";
		read PAS2
	else
		einfo "shadow access password: ${PASS}"
		einfo "public access password: ${PAS2}"
	fi
	if [ -z "${PAS2}" ]; then
		PAS2="${RANDOM}${RANDOM}${RANDOM}${RANDOM}"
	fi
	if [ -z "${PASS}" ]; then
		einfo "I will not accept that you leave that the shadow-access-password empty"
		die
	fi
	if [ ! -z "$POPT" ]; then
		einfo "Pass the mysql-users \"${USERNAME}\"s password to mysql:";
		echo -n "mysql> "
	fi
	( zcat /usr/share/doc/${PF}/gentoo.sql.gz | sed "s/'another_password'/'${PASS}'/g;s/'password'/'${PAS2}'/g" | mysql ${POPT} -u ${USERNAME} ) || die
	sed -e "s|shadow.db_password =.*|shadow.db_password = ${PASS};|" -i /etc/nss-mysql/nss-mysql-root.conf
	sed -e "s|users.db_password =.*|users.db_password = ${PAS2};|" -i /etc/nss-mysql/nss-mysql.conf
	chown -R 0:0 /etc/nss-mysql
	chmod 600 /etc/nss-mysql/nss-mysql-root.conf
	chmod 644 /etc/nss-mysql/nss-mysql.conf
	einfo "nss_mysql-configfiles and mysql-tables should now be setup"
	einfo "remember to activate nss-mysql in /etc/nsswitch.conf with someting simillar to:"
	einfo
	einfo "passwd:	files mysql"
	einfo "shadow:	files mysql"
	einfo "group:	files mysql"
	einfo
}