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
|
#!/bin/bash
FILE="bugzilla.cron.daily bugzilla.cron.tab"
function die ()
{
echo
echo "***"
echo "*** Fatal error: $*"
echo "***"
exit 1
}
if [ $1 = "install" ]; then
cd "${MY_INSTALLDIR}" || die "Cannot find install dir ${MY_INSTALLDIR}"
sed -e "s|/var/www/bugzilla|${MY_INSTALLDIR}|g;" -i ${FILE}
[[ -a localconfig ]] && die "The following does not work on previous installations, please run checksetup.pl in ${MY_INSTALLDIR}"
echo
echo "Finalizing the installation of bugzilla in ${MY_INSTALLDIR}"
echo
# config setting
echo "Details for the bugzilla database"
echo "(This scripts creates the database & user)"
echo
echo "If you want to use Postgres, please enter numeric IP"
echo "or the config script will hang"
echo -n "bugs db host [127.0.0.1]: "; read mybugshost
[[ -z "${mybugshost}" ]] && mybugshost="127.0.0.1"
echo -n "bugs db driver (mysql or pg) [mysql]: "; read mydriver
[[ -z "${mydriver}" ]] && mydriver="mysql"
if [[ ${mydriver} == "mysql" ]]; then
port="3306"
granter="root"
elif [[ ${mydriver} == "pg" ]]; then
port="5432"
granter="postgres"
else
die "Wrong db driver"
fi
echo -n "bugs db port [${port}]: "; read mybugsport
[[ -z "${mybugsport}" ]] && mybugsport="${port}"
echo -n "bugs db name [bugs]: "; read mybugsdb
[[ -z "${mybugsdb}" ]] && mybugsdb="bugs"
echo -n "bugs dbuser name [bugs]: "; read mybugsuser
[[ -z "${mybugsuser}" ]] && mybugsuser="bugs"
echo -n "bugs dbuser password: "; read mybugspwd
[[ -z "${mybugspwd}" ]] && die "Error: no dbuser password"
pw=${mybugspwd//\'/\\\'}
echo -n "your SMTP server [localhost]: "; read mysmtp
[[ -z "${mysmtp}" ]] && mysmtp="localhost"
# let's create a config file for checksetup.pl
echo "\$answer{'db_host'} = q[" > bz.cfg.pl
echo "\$db_host = '${mybugshost}';" >> bz.cfg.pl
echo "\$db_driver = '${mydriver}';" >> bz.cfg.pl
echo "\$db_port = ${mybugsport};" >> bz.cfg.pl
echo "\$db_name = '${mybugsdb}';" >> bz.cfg.pl
echo "\$db_user = '${mybugsuser}';" >> bz.cfg.pl
echo "];" >> bz.cfg.pl
echo "\$answer{'db_pass'} = q[\$db_pass = '${mybugspwd}';];" >> bz.cfg.pl
echo "\$answer{'SMTP_SERVER'} = q['${mysmtp}';];" >> bz.cfg.pl
if [[ ${mydriver} == "mysql" ]]; then
echo "\$answer{'db_sock'} = q[\$db_sock = '/var/run/mysqld/mysqld.sock';];" >> bz.cfg.pl
elif [[ ${mydriver} == "pg" ]]; then
echo "\$answer{'db_sock'} = q[\$db_sock = '/tmp/.s.PGSQL.${mybugsport}';];" >> bz.cfg.pl
else
die "Wrong db driver"
fi
# privileges
echo "Setting correct privileges for bugzilla connection"
echo -n "Please enter login info for user who has grant privileges on ${mybugshost} [${granter}]: "; read adminuser
[[ -z ${adminuser} ]] && adminuser="${granter}"
if [ "${mybugshost}" != "127.0.0.1" ]; then
echo -n "Client address for bugzilla (at db side) [$(hostname -f)]: "; read clientaddr
[[ -z ${clientaddr} ]] && clientaddr="$(hostname -f)"
fi
# this will be default for localhost
[[ -z ${clientaddr} ]] && clientaddr="${mybugshost}"
if [[ ${mydriver} == "mysql" ]]; then
# check the installed mysql version
type -p mysql &>/dev/null || die "mysql program not found ! Check your PATH (or did you emerge with --nodeps ?)"
mysql_version="`mysql -V | cut -d' ' -f6 | sed -e 's:,$::'`"
[[ -z ${mysql_version} ]] && die "mysql version check failed (got '${mysql_version}')"
extra_bugzie_privs=""
(( ${mysql_version:0:1} < 4 )) && extra_bugzie_privs=",LOCK TABLES,CREATE TEMPORARY TABLES"
# if $bugshost == localhost, don't specify -h argument, so local socket can be used.
host=${mybugshost/"127.0.0.1"}
/etc/init.d/mysql restart || die "Could not (re)start mysql!"
mysql -u "${adminuser}" "${host:+-h ${host}}" -p \
-P "${mybugsport}" \
-e "GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE,DROP,REFERENCES${extra_bugzie_privs} ON ${mybugsdb}.* TO '${mybugsuser}'@'${clientaddr}' IDENTIFIED BY '${pw}'; FLUSH PRIVILEGES;" \
|| die "Error initializing database. Please grant permissions manually. See http://www.bugzilla.org/docs/tip/html/configuration.html."
elif [[ ${mydriver} == "pg" ]]; then
# if $bugshost == localhost, don't specify -h argument, so local socket can be used.
host=${mybugshost/"127.0.0.1"}
/etc/init.d/postgresql restart || die "Could not (re)start postgresql!"
createdb -U "${adminuser}" ${host:+-h ${host}} -W \
-p "${mybugsport}" -O "${mybugsuser}" "${mybugsdb}" \
|| die "Error initializing database. Please grant permissions manually. See http://www.bugzilla.org/docs/tip/html/configuration.html."
else
die "Wrong db driver"
fi
echo "Setting the template for localconfig variables"
cd ${MY_INSTALLDIR} || die
chmod 755 ./checksetup.pl
./checksetup.pl bz.cfg.pl || exit 1
echo "Final step: setting all html templates and db tables"
./checksetup.pl || exit 1
echo -n "Do you want to set a crontab [y/N]" ; read cronyes
if [ "${cronyes}+" = "y+" ] ; then
/usr/bin/crontab -u apache ${MY_INSTALLDIR}/bugzilla.cron.tab
fi
else
[[ -z "${MY_INSTALLDIR}" ]] && die "${MY_INSTALLDIR} not found!"
rm -f "${FILES}" bz.cfg.pl
fi
|