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
|
#! /bin/sh
# postinst script for cacti
#
# see: dh_installdeb(1)
set -e
generate_config()
{
cat > /etc/cacti/config.php <<EOF
<?
\$database_default = "${database}";
\$database_hostname = "${mysql_server}";
\$database_username = "${username}";
\$database_password = "${password}";
?>
EOF
}
create_user()
{
${mysqlcmd} -e "
CONNECT mysql;
GRANT ALL ON ${dbname}.* TO ${dbuser}@localhost IDENTIFIED BY '${dbpass}';
flush privileges;
"
}
get_config()
{
db_get cacti/mysql_server
mysql_server="$RET"
db_get cacti/database
database="$RET"
db_get cacti/root_mysql
root_mysql="$RET"
db_get cacti/root_password
root_passwd="$RET"
db_get cacti/username
username="$RET"
db_get cacti/password
password="$RET"
db_get cacti/webserver
webserver="$RET"
}
case "$1" in
configure)
# Source debconf library
. /usr/share/debconf/confmodule
db_version 2.0
get_config
mysqlpwd=""
if [ "$root_passwd" != 'none' ]; then
mysqlpwd="-p${root_passwd}"
fi
mysqlcmd="mysql -h ${mysql_server} -u${root_mysql} ${mysqlpwd}"
# create database if it does not already exists
dbname=${database}
dbserver=${mysql_server}
dbadmin=${root_mysql}
dbadmpass=${root_password}
if ${mysqlcmd} -B -e 'show databases' | grep -q "^${database}$"
then
echo "Database already exist!"
else
${mysqlcmd} -e "create database ${database}"
zcat /usr/share/doc/cacti/cacti.sql.gz | ${mysqlcmd} ${database}
if [ $? != 0 ]
then
exit 1
else
dbuser=${username}
dballow=${mysql_server}
dbname=${database}
dbpass=${password}
if [ "${dbuser}" != "${root_mysql}" ]
then
create_user
fi
fi
fi
# modify config file
generate_config
includefile=/etc/cacti/apache.conf
server=${webserver}
servers=${webserver}
. /usr/share/wwwconfig-common/apache-include_all.sh
[ "$status" = "uncomment" -o "$status" = "include" ] && restart="${webserver} ${restart}"
. /usr/share/wwwconfig-common/restart.sh
db_stop
touch /var/log/cacti/rrd.log
chown www-data.www-data /var/log/cacti/rrd.log
chmod 0640 /var/log/cacti/rrd.log
chown root.www-data /etc/cacti/config.php
chmod 0640 /etc/cacti/config.php
chown www-data.www-data /var/cache/cacti
restart="${webserver} ${restart}"
. /usr/share/wwwconfig-common/restart.sh
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
|