mongodb-version-manager 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/bash
  2. # MongoDB Version Manager
  3. # Helps manage MongoDB server binaries for different versions (3-8)
  4. # This script provides utilities for adding and managing MongoDB server versions
  5. # Source settings
  6. source $SNAP/bin/wekan-read-settings
  7. # MongoDB version information
  8. declare -A MONGO_VERSIONS=(
  9. ["3"]="3.2.22"
  10. ["4"]="4.4.28"
  11. ["5"]="5.0.28"
  12. ["6"]="6.0.15"
  13. ["7"]="7.0.25"
  14. ["8"]="8.0.4"
  15. )
  16. # MongoDB binary paths
  17. declare -A MONGO_PATHS=(
  18. ["3"]="/snap/${SNAP_NAME}/current/migratemongo/bin"
  19. ["4"]="/snap/${SNAP_NAME}/current/mongodb4/bin"
  20. ["5"]="/snap/${SNAP_NAME}/current/mongodb5/bin"
  21. ["6"]="/snap/${SNAP_NAME}/current/mongodb6/bin"
  22. ["7"]="/snap/${SNAP_NAME}/current/bin"
  23. ["8"]="/snap/${SNAP_NAME}/current/mongodb8/bin"
  24. )
  25. # Check which MongoDB versions are available
  26. check_available_versions() {
  27. echo "=== Available MongoDB Server Versions ==="
  28. for version in "${!MONGO_VERSIONS[@]}"; do
  29. local path="${MONGO_PATHS[$version]}"
  30. if [ -f "$path/mongod" ]; then
  31. echo "✓ MongoDB $version.x (${MONGO_VERSIONS[$version]}) - Available at $path"
  32. else
  33. echo "✗ MongoDB $version.x (${MONGO_VERSIONS[$version]}) - Not available at $path"
  34. fi
  35. done
  36. echo ""
  37. }
  38. # Check which MongoDB Node.js drivers are available
  39. check_available_drivers() {
  40. echo "=== Available MongoDB Node.js Drivers ==="
  41. if [ -f "/home/wekan/repos/wekan/package.json" ]; then
  42. for version in "${!MONGO_VERSIONS[@]}"; do
  43. if grep -q "mongodb${version}legacy" "/home/wekan/repos/wekan/package.json"; then
  44. echo "✓ MongoDB $version.x Node.js driver - Available (mongodb${version}legacy)"
  45. else
  46. echo "✗ MongoDB $version.x Node.js driver - Not available"
  47. fi
  48. done
  49. else
  50. echo "package.json not found"
  51. fi
  52. echo ""
  53. }
  54. # Show current active MongoDB version
  55. show_active_version() {
  56. if [ -f "${SNAP_COMMON}/mongodb-active-version" ]; then
  57. local active_version=$(cat "${SNAP_COMMON}/mongodb-active-version")
  58. echo "=== Current Active MongoDB Version ==="
  59. echo "Active Version: MongoDB $active_version.x"
  60. echo "Version File: ${SNAP_COMMON}/mongodb-active-version"
  61. echo ""
  62. else
  63. echo "=== Current Active MongoDB Version ==="
  64. echo "No active version file found (will use default MongoDB 7.x)"
  65. echo ""
  66. fi
  67. }
  68. # Show version detection log
  69. show_detection_log() {
  70. if [ -f "${SNAP_COMMON}/mongodb-version-detection.log" ]; then
  71. echo "=== MongoDB Version Detection Log ==="
  72. tail -20 "${SNAP_COMMON}/mongodb-version-detection.log"
  73. echo ""
  74. else
  75. echo "=== MongoDB Version Detection Log ==="
  76. echo "No detection log found"
  77. echo ""
  78. fi
  79. }
  80. # Force version detection
  81. force_detection() {
  82. echo "=== Forcing MongoDB Version Detection ==="
  83. rm -f "${SNAP_COMMON}/mongodb-active-version"
  84. echo "Cleared cached version. Next MongoDB restart will detect version automatically."
  85. echo ""
  86. }
  87. # Show help
  88. show_help() {
  89. echo "MongoDB Version Manager"
  90. echo ""
  91. echo "Usage: $0 [command]"
  92. echo ""
  93. echo "Commands:"
  94. echo " versions - Show available MongoDB server versions"
  95. echo " drivers - Show available MongoDB Node.js drivers"
  96. echo " active - Show current active MongoDB version"
  97. echo " log - Show version detection log"
  98. echo " detect - Force version detection on next restart"
  99. echo " help - Show this help message"
  100. echo ""
  101. echo "Examples:"
  102. echo " $0 versions # Check which MongoDB versions are available"
  103. echo " $0 active # Show which version is currently active"
  104. echo " $0 detect # Force re-detection on next restart"
  105. echo ""
  106. }
  107. # Main command handling
  108. case "${1:-help}" in
  109. "versions")
  110. check_available_versions
  111. ;;
  112. "drivers")
  113. check_available_drivers
  114. ;;
  115. "active")
  116. show_active_version
  117. ;;
  118. "log")
  119. show_detection_log
  120. ;;
  121. "detect")
  122. force_detection
  123. ;;
  124. "help"|*)
  125. show_help
  126. ;;
  127. esac