Advertisement
Kaito_Vu

Untitled

Nov 2nd, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # script to upgrade a cacti instance to latest, if you want a specific version please update the following download links
  4. cacti_download_url=http://files.cacti.net/cacti/linux/cacti-1.2.24.tar.gz
  5. spine_download_url=http://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz
  6.  
  7. # create temp workspace
  8. echo "$(date +%F_%R) [Upgrade] Prepping workspace for restore."
  9. rm -rf /tmp/update
  10. mkdir /tmp/update
  11. mkdir /tmp/update/spine
  12. mkdir /tmp/update/cacti
  13.  
  14. # download and uncompress cacti
  15. echo "$(date +%F_%R) [Upgrade] Downloading Cacti from $cacti_download_url"
  16. wget -qO- $cacti_download_url | tar xzC /tmp/update/cacti
  17.  
  18. # download and uncompress spine
  19. echo "$(date +%F_%R) [Upgrade] Downloading Spine from $spine_download_url"
  20. wget -qO- /tmp/update $spine_download_url | tar xzC /tmp/update/spine/
  21.  
  22. # if not a remote poller, update cacti bits
  23. if [ ${REMOTE_POLLER} != 1 ]; then
  24. echo "$(date +%F_%R) [Upgrade] System not marked as remote poller, updating cacti."
  25.  
  26. # cacti install
  27. echo "$(date +%F_%R) [Upgrade] Installing new version of Cacti."
  28. cp -Rf /tmp/update/cacti/*/* /cacti
  29.  
  30. # fixing permissions
  31. echo "$(date +%F_%R) [Restore] Setting cacti file permissions."
  32. chown -R apache.apache /cacti/resource/
  33. chown -R apache.apache /cacti/cache/
  34. chown -R apache.apache /cacti/log/
  35. chown -R apache.apache /cacti/scripts/
  36. chown -R apache.apache /cacti/rra/
  37. touch /cacti/include/vendor/csrf/csrf-secret.php
  38. chmod 644 /cacti/include/vendor/csrf/csrf-secret.php
  39. chown apache.apache /cacti/include/vendor/csrf/csrf-secret.php
  40.  
  41. # copy templated config files, makes sed command easier
  42. echo "$(date +%F_%R) [Upgrade] Copying config templates for Cacti."
  43. cp -f /template_configs/config.php /cacti/include
  44.  
  45. # cacti settings
  46. echo "$(date +%F_%R) [Upgrade] Updating cacti settings."
  47. sed -i -e "s/%DB_HOST%/${DB_HOST}/" \
  48. -e "s/%DB_PORT%/${DB_PORT}/" \
  49. -e "s/%DB_NAME%/${DB_NAME}/" \
  50. -e "s/%DB_USER%/${DB_USER}/" \
  51. -e "s/%DB_PASS%/${DB_PASS}/" \
  52. -e "s/%DB_PORT%/${DB_PORT}/" \
  53. -e "s/%RDB_HOST%/${RDB_HOST}/" \
  54. -e "s/%RDB_PORT%/${RDB_PORT}/" \
  55. -e "s/%RDB_NAME%/${RDB_NAME}/" \
  56. -e "s/%RDB_USER%/${RDB_USER}/" \
  57. -e "s/%RDB_PASS%/${RDB_PASS}/" \
  58. -e "s/%CACTI_URL_PATH%/${CACTI_URL_PATH}/" \
  59. /cacti/include/config.php
  60.  
  61. # attempt db upgrade via cli
  62. echo "$(date +%F_%R) [Upgrade] Attempting to update database via CLI."
  63. php /cacti/cli/upgrade_database.php
  64.  
  65. fi
  66.  
  67. # bootstrap, compile, and install spine
  68. echo "$(date +%F_%R) [Upgrade] Compile + Installing new version of Spine."
  69. cd /tmp/update/spine/* && \
  70. ./bootstrap && \
  71. ./configure --prefix=/spine && make && make install && \
  72. chown root:root /spine/bin/spine && \
  73. chmod +s /spine/bin/spine
  74.  
  75. # copy templated config files, makes sed command easier
  76. echo "$(date +%F_%R) [Upgrade] Copying config templates for Spine."
  77. cp -f /template_configs/spine.conf /spine/etc
  78.  
  79. # cacti settings
  80. echo "$(date +%F_%R) [Upgrade] Updating spine settings."
  81. sed -i -e "s/%DB_HOST%/${DB_HOST}/" \
  82. -e "s/%DB_PORT%/${DB_PORT}/" \
  83. -e "s/%DB_NAME%/${DB_NAME}/" \
  84. -e "s/%DB_USER%/${DB_USER}/" \
  85. -e "s/%DB_PASS%/${DB_PASS}/" \
  86. -e "s/%DB_PORT%/${DB_PORT}/" \
  87. -e "s/%RDB_HOST%/${RDB_HOST}/" \
  88. -e "s/%RDB_PORT%/${RDB_PORT}/" \
  89. -e "s/%RDB_NAME%/${RDB_NAME}/" \
  90. -e "s/%RDB_USER%/${RDB_USER}/" \
  91. -e "s/%RDB_PASS%/${RDB_PASS}/" \
  92. /spine/etc/spine.conf
  93.  
  94. # cacti settings
  95. echo "$(date +%F_%R) [Upgrade] Cleaning temp files."
  96. rm -rf /tmp/update
  97.  
  98. # write note in cacti.log that a upgrade is complete
  99. echo "$(date +%F_%R) [Upgrade] Cacti upgrade complete!" >> /cacti/log/cacti.log
  100.  
  101. echo "$(date +%F_%R) [Upgrade] Upgrade complete, please log into cacti to finish."
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement