v_update_sys_vesta 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # info: update vesta after rpm update
  3. # options: version
  4. #
  5. # The function is runs as rpm update trigger. It pulls shell script from vesta
  6. # server and runs it.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. version=$1
  12. updates=''
  13. # Importing system enviroment
  14. source /etc/profile.d/vesta.sh
  15. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '1' "$#" 'version'
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Compare versions
  28. if [ "$version" != "$VERSION" ]; then
  29. # Downloading version tree
  30. upd_host="yum.vestacp.com"
  31. wget -O "/tmp/versions" http://$V_UPD_HOST/upd_scripts/version_tree.txt \
  32. >/dev/null 2>&1
  33. # Checking download result
  34. if [ "$?" -ne "0" ]; then
  35. echo "Error: version tree update failed"
  36. log_event 'debug' "$E_UPDATE $V_EVENT"
  37. exit $E_UPDATE
  38. fi
  39. # Deviding version
  40. v1=$(echo "$version" |cut -f 1 -d '.')
  41. v2=$(echo "$version" |cut -f 2 -d '.')
  42. v3=$(echo "$version" |cut -f 3 -d '.')
  43. V1=$(echo "$VERSION" |cut -f 1 -d '.')
  44. V2=$(echo "$VERSION" |cut -f 2 -d '.')
  45. V3=$(echo "$VERSION" |cut -f 3 -d '.')
  46. # Checking difference between versions
  47. # Too nested tests, sory about complexity
  48. if [ "$V1" -lt "$v1" ]; then
  49. for ver in $(seq $V1 $v1); do
  50. updates="$updates $(grep "^$ver." /tmp/versions|grep ":1$"|\
  51. cut -f 1 -d :)"
  52. done
  53. else
  54. if [ "$V2" -lt "$v2" ]; then
  55. for ver in $(seq $V2 $v2); do
  56. updates="$updates $(grep "^$v1.$ver." /tmp/versions |\
  57. grep ":1$"|cut -f 1 -d :)"
  58. done
  59. else
  60. V4=$((V3 + 1))
  61. for ver in $(seq $V4 $v3); do
  62. updates="$updates $(grep "^$v1.$v2.$ver" /tmp/versions |\
  63. grep ":1$"|cut -f 1 -d :)"
  64. done
  65. fi
  66. fi
  67. # Executing update scripts
  68. if [ ! -z "$updates" ]; then
  69. mkdir $V_BIN/updates >/dev/null 2>&1
  70. for update in $updates; do
  71. wget -O $V_BIN/updates/$update.sh \
  72. http://$V_UPD_HOST/upd_scripts/$update.sh >/dev/null 2>&1
  73. # Checking download result
  74. if [ "$?" -ne "0" ]; then
  75. echo "Error: version tree update failed"
  76. log_event 'debug' "$E_UPDATE $V_EVENT"
  77. exit $E_UPDATE
  78. fi
  79. bash $V_BIN/updates/$update.sh
  80. done
  81. rm -rf $V_BIN/updates
  82. fi
  83. # Updating config version
  84. sed -i "s/VERSION='$VERSION'/VERSION='$version'/g" $V_CONF/vesta.conf
  85. fi
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. # Logging
  90. log_event 'system' "$V_EVENT"
  91. exit