v_upd_sys_vesta 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. V4=$((V3 + 1))
  59. for ver in $(seq $V4 $v3); do
  60. updates="$updates $(grep "^$v1.$v2.$ver" /tmp/versions |\
  61. grep ":1$"|cut -f 1 -d :)"
  62. done
  63. fi
  64. fi
  65. # Executing update scripts
  66. if [ ! -z "$updates" ]; then
  67. mkdir $V_BIN/updates >/dev/null 2>&1
  68. for update in $updates; do
  69. wget -O $V_BIN/updates/$update.sh \
  70. http://$V_UPD_HOST/upd_scripts/$update.sh >/dev/null 2>&1
  71. # Checking download result
  72. if [ "$?" -ne "0" ]; then
  73. echo "Error: version tree update failed"
  74. log_event 'debug' "$E_UPD_FAILED $V_EVENT"
  75. exit $E_UPD_FAILED
  76. fi
  77. bash $V_BIN/updates/$update.sh
  78. done
  79. rm -rf $V_BIN/updates
  80. fi
  81. # Updating config version
  82. sed -i "s/VERSION='$VERSION'/VERSION='$version'/g" $V_CONF/vesta.conf
  83. fi
  84. #----------------------------------------------------------#
  85. # Vesta #
  86. #----------------------------------------------------------#
  87. # Logging
  88. log_event 'system' "$V_EVENT"
  89. exit $OK