v_upd_sys_vesta 3.2 KB

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