diff --git a/upgrade.sh b/upgrade.sh index c2590fb..14a36e8 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -19,17 +19,46 @@ wget -qO- $cacti_download_url | tar xzC /tmp/update/cacti echo "$(date +%F_%R) [Upgrade] Downloading Spine from $spine_download_url" wget -qO- /tmp/update $spine_download_url | tar xzC /tmp/update/spine/ -# cacti install -echo "$(date +%F_%R) [Upgrade] Installing new version of Cacti." -cp -Rf /tmp/update/cacti/*/* /cacti - -# fixing permissions -echo "$(date +%F_%R) [Restore] Setting cacti file permissions." -chown -R apache.apache /cacti/resource/ -chown -R apache.apache /cacti/cache/ -chown -R apache.apache /cacti/log/ -chown -R apache.apache /cacti/scripts/ -chown -R apache.apache /cacti/rra/ +# if not a remote poller, update cacti bits +if [ ${REMOTE_POLLER} != 1 ]; then + echo "$(date +%F_%R) [Upgrade] System not marked as remote poller, updating cacti." + + # cacti install + echo "$(date +%F_%R) [Upgrade] Installing new version of Cacti." + cp -Rf /tmp/update/cacti/*/* /cacti + + # fixing permissions + echo "$(date +%F_%R) [Restore] Setting cacti file permissions." + chown -R apache.apache /cacti/resource/ + chown -R apache.apache /cacti/cache/ + chown -R apache.apache /cacti/log/ + chown -R apache.apache /cacti/scripts/ + chown -R apache.apache /cacti/rra/ + + # copy templated config files, makes sed command easier + echo "$(date +%F_%R) [Upgrade] Copying config templates for Cacti." + cp -f /template_configs/config.php /cacti/include + + # cacti settings + echo "$(date +%F_%R) [Upgrade] Updating cacti settings." + sed -i -e "s/%DB_HOST%/${DB_HOST}/" \ + -e "s/%DB_PORT%/${DB_PORT}/" \ + -e "s/%DB_NAME%/${DB_NAME}/" \ + -e "s/%DB_USER%/${DB_USER}/" \ + -e "s/%DB_PASS%/${DB_PASS}/" \ + -e "s/%DB_PORT%/${DB_PORT}/" \ + -e "s/%RDB_HOST%/${RDB_HOST}/" \ + -e "s/%RDB_PORT%/${RDB_PORT}/" \ + -e "s/%RDB_NAME%/${RDB_NAME}/" \ + -e "s/%RDB_USER%/${RDB_USER}/" \ + -e "s/%RDB_PASS%/${RDB_PASS}/" \ + /cacti/include/config.php + + # attempt db upgrade via cli + echo "$(date +%F_%R) [Upgrade] Attempting to update database via CLI." + php /cacti/cli/upgrade_database.php + +fi # bootstrap, compile, and install spine echo "$(date +%F_%R) [Upgrade] Compile + Installing new version of Spine." @@ -40,12 +69,11 @@ cd /tmp/update/spine/* && \ chmod +s /spine/bin/spine # copy templated config files, makes sed command easier -echo "$(date +%F_%R) [Upgrade] Copying config templates for Spine and Cacti." -cp -f /template_configs/config.php /cacti/include +echo "$(date +%F_%R) [Upgrade] Copying config templates for Spine." cp -f /template_configs/spine.conf /spine/etc # cacti settings -echo "$(date +%F_%R) [Upgrade] Updating cacti/spine settings." +echo "$(date +%F_%R) [Upgrade] Updating spine settings." sed -i -e "s/%DB_HOST%/${DB_HOST}/" \ -e "s/%DB_PORT%/${DB_PORT}/" \ -e "s/%DB_NAME%/${DB_NAME}/" \ @@ -57,22 +85,8 @@ sed -i -e "s/%DB_HOST%/${DB_HOST}/" \ -e "s/%RDB_NAME%/${RDB_NAME}/" \ -e "s/%RDB_USER%/${RDB_USER}/" \ -e "s/%RDB_PASS%/${RDB_PASS}/" \ - /cacti/include/config.php \ /spine/etc/spine.conf -# remote poller tasks -if [ ${REMOTE_POLLER} = 1 ]; then - echo "$(date +%F_%R) [Upgrade - Remote Poller] This is slated to be a remote poller, updating cacti configs for these settings." - sed -i -e "s/#$rdatabase/$rdatabase/" \ - /cacti/include/config.php - echo "$(date +%F_%R) [Upgrade - Remote Poller] Updating permissions in cacti directory for remote poller template." - chown -R apache.apache /cacti -fi - -# attempt db upgrade via clu -echo "$(date +%F_%R) [Upgrade] Attempting to update database via CLI." -php /cacti/cli/upgrade_database.php - # cacti settings echo "$(date +%F_%R) [Upgrade] Cleaning temp files." rm -rf /tmp/update