v-update-sys-vesta 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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
  15. # Includes
  16. source $VESTA/conf/vesta.conf
  17. source $VESTA/func/main.sh
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Checking arg number
  22. check_args '1' "$#" 'version'
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Compare versions
  27. if [ "$version" != "$VERSION" ]; then
  28. # Downloading version tree
  29. upd_host="yum.vestacp.com"
  30. wget -O "/tmp/versions" http://$V_UPD_HOST/upd_scripts/version_tree.txt \
  31. &>/dev/null
  32. # Checking download result
  33. if [ "$?" -ne "0" ]; then
  34. echo "Error: version tree update failed"
  35. log_event "$E_UPDATE" "$EVENT"
  36. exit $E_UPDATE
  37. fi
  38. # Deviding version
  39. v1=$(echo "$version" |cut -f 1 -d '.')
  40. v2=$(echo "$version" |cut -f 2 -d '.')
  41. v3=$(echo "$version" |cut -f 3 -d '.')
  42. V1=$(echo "$VERSION" |cut -f 1 -d '.')
  43. V2=$(echo "$VERSION" |cut -f 2 -d '.')
  44. V3=$(echo "$VERSION" |cut -f 3 -d '.')
  45. # Checking difference between versions
  46. # Too nested tests, sory about complexity
  47. if [ "$V1" -lt "$v1" ]; then
  48. for ver in $(seq $V1 $v1); do
  49. updates="$updates $(grep "^$ver." /tmp/versions|grep ":1$"|\
  50. cut -f 1 -d :)"
  51. done
  52. else
  53. if [ "$V2" -lt "$v2" ]; then
  54. for ver in $(seq $V2 $v2); do
  55. updates="$updates $(grep "^$v1.$ver." /tmp/versions |\
  56. grep ":1$"|cut -f 1 -d :)"
  57. done
  58. else
  59. V4=$((V3 + 1))
  60. for ver in $(seq $V4 $v3); do
  61. updates="$updates $(grep "^$v1.$v2.$ver" /tmp/versions |\
  62. grep ":1$"|cut -f 1 -d :)"
  63. done
  64. fi
  65. fi
  66. # Executing update scripts
  67. if [ ! -z "$updates" ]; then
  68. mkdir $BIN/updates &>/dev/null
  69. for update in $updates; do
  70. wget -O $BIN/updates/$update.sh \
  71. http://$V_UPD_HOST/upd_scripts/$update.sh &>/dev/null
  72. # Checking download result
  73. if [ "$?" -ne "0" ]; then
  74. echo "Error: version tree update failed"
  75. log_event "$E_UPDATE" "$EVENT"
  76. exit $E_UPDATE
  77. fi
  78. bash $BIN/updates/$update.sh
  79. done
  80. rm -rf $BIN/updates
  81. fi
  82. # Updating config version
  83. sed -i "s/VERSION='$VERSION'/VERSION='$version'/g" $VESTA/conf/vesta.conf
  84. fi
  85. #----------------------------------------------------------#
  86. # Vesta #
  87. #----------------------------------------------------------#
  88. # Logging
  89. log_event "$OK" "$EVENT"
  90. exit