Code: Select all
#!/bin/bash
# upgrade cacti 0.8.7b to 0.8.7g on debian lenny (GuruPlug)
# Dan Large, Awesomejar Consulting
# E-Mail : dlarge@awesomejar.com
# Date : 31-Jan-2011
if [ $LOGNAME != "root" ]; then
echo "Error: not running user root. Log out and back in as root before running this script."
exit 1
fi
cd /tmp
# backup the old cacti database
echo -n "Enter mysql root password: "
read -s mysqlpasswd
mysqldump -u root -p"$mysqlpasswd" -l --add-drop-table cacti > mysql.cacti
# backup the cacti directory
cd /usr/share
mv cacti cacti_old
# download and extract the 0.8.7g distribution
wget http://www.cacti.net/downloads/cacti-0.8.7g.tar.gz
tar xzvf cacti-0.8.7g.tar.gz
# rename the new cacti directory to match the old one and remove the tarball
mv cacti-0.8.7g cacti
rm cacti-0.8.7g.tar.gz
# edit include/config.php to specify the MySQL user, password and database for your Cacti configuration.
mv /usr/share/cacti/include/config.php /usr/share/cacti/include/config.in
sed "
s/database_username = \"cactiuser\"/database_username = \"cacti\"/
s/database_password = \"cactiuser\"/database_password = \"$mysqlpasswd\"/" /usr/share/cacti/include/config.in >/usr/share/cacti/include/config.php
rm /usr/share/cacti/include/config.in
# Copy the *.rrd files from the old Cacti directory
cp /var/lib/cacti/rra/* cacti/rra/
# Copy any relevant custom scripts from the old Cacti directory. Some script are updated between versions.
# Therefore, make sure you only over write if the scripts either don't exist or are newer than the distribution's.
cp -u cacti_old/site/scripts/* cacti/scripts/
# Copy any relevant custom resource XML files from the old Cacti directory. Some resource XML files are updated between versions.
# Therefore, make sure you only over write if the XML files either don't exist or are newer than the distribution's.
cp -u -R cacti_old/resource/* cacti/resource/
# Set the appropriate permissions on Cacti's directories for graph/log generation.
# You should execute these commands from inside Cacti's directory to change the permissions.
cd /usr/share/cacti/
chown -R www-data:www-data rra/ log/
# Modify the poller cron job
echo "MAILTO=root" > /etc/cron.d/cacti
echo "*/5 * * * * www-data php /usr/share/cacti/poller.php >/dev/null 2>/var/log/cacti/poller-error.log" >> /etc/cron.d/cacti
# Update the cacti config for Apache
mv /etc/cacti/apache.conf /etc/cacti/apache.in
sed 's/\/usr\/share\/cacti\/site/\/usr\/share\/cacti/' /etc/cacti/apache.in >/etc/cacti/apache.conf
rm /etc/cacti/apache.in
# Install added php packages detected by poller.php
apt-get install php5-gd php5-mcrypt -y
# Restart apache2
/etc/init.d/apache2 restart
echo
echo "Point your web browser to http://your-server/cacti/ to finish upgrade"
echo