11#! /bin/bash
2- # info: update vesta after rpm update
3- # options: VERSION
2+ # info: update vesta package/configs
3+ # options: PACKAGE [ VERSION]
44#
5- # The function is runs as rpm update trigger. It pulls shell script from vesta
5+ # The function runs as rpm update trigger. It pulls shell script from vesta
66# server and runs it.
77
88
1111# ----------------------------------------------------------#
1212
1313# Argument defenition
14- version=$1
15- updates=' '
14+ package=$1
15+ version=$2
16+ release=$3
1617
1718# Importing system enviroment
1819source /etc/profile
@@ -27,79 +28,27 @@ source $VESTA/func/main.sh
2728# ----------------------------------------------------------#
2829
2930# Checking arg number
30- check_args ' 1' " $# " ' VERSION'
31+ check_args ' 1' " $# " ' PACKAGE [ VERSION] [RELEASE] '
3132
3233
3334# ----------------------------------------------------------#
3435# Action #
3536# ----------------------------------------------------------#
3637
37- # Compare versions
38- if [ " $version " != " $VERSION " ]; then
39- # Downloading version tree
40- upd_host=" yum.vestacp.com"
41- wget -O " /tmp/versions" http://$V_UPD_HOST /upd_scripts/version_tree.txt \
42- & > /dev/null
38+ # Clean yum chache
39+ yum -q clean all
4340
44- # Checking download result
45- if [ " $? " -ne " 0" ]; then
46- echo " Error: version tree update failed"
41+ # Define yum cmd
42+ yum=" yum -q -y --noplugins --disablerepo=* --enablerepo=vesta"
43+
44+ # Update vesta package
45+ if [ -z " $version " ]; then
46+ $yum update $package > /dev/null 2>&1
47+ if [ $? -ne 0 ]; then
48+ echo " Error: $package update failed"
4749 log_event " $E_UPDATE " " $EVENT "
4850 exit $E_UPDATE
4951 fi
50-
51- # Deviding version
52- v1=$( echo " $version " | cut -f 1 -d ' .' )
53- v2=$( echo " $version " | cut -f 2 -d ' .' )
54- v3=$( echo " $version " | cut -f 3 -d ' .' )
55- V1=$( echo " $VERSION " | cut -f 1 -d ' .' )
56- V2=$( echo " $VERSION " | cut -f 2 -d ' .' )
57- V3=$( echo " $VERSION " | cut -f 3 -d ' .' )
58-
59-
60- # Checking difference between versions
61- # Too nested tests, sory about complexity
62- if [ " $V1 " -lt " $v1 " ]; then
63- for ver in $( seq $V1 $v1 ) ; do
64- updates=" $updates $( grep " ^$ver ." /tmp/versions| grep " :1$" | \
65- cut -f 1 -d :) "
66- done
67- else
68- if [ " $V2 " -lt " $v2 " ]; then
69- for ver in $( seq $V2 $v2 ) ; do
70- updates=" $updates $( grep " ^$v1 .$ver ." /tmp/versions | \
71- grep " :1$" | cut -f 1 -d :) "
72- done
73- else
74- V4=$(( V3 + 1 ))
75- for ver in $( seq $V4 $v3 ) ; do
76- updates=" $updates $( grep " ^$v1 .$v2 .$ver " /tmp/versions | \
77- grep " :1$" | cut -f 1 -d :) "
78- done
79- fi
80- fi
81-
82- # Executing update scripts
83- if [ ! -z " $updates " ]; then
84- mkdir $BIN /updates & > /dev/null
85-
86- for update in $updates ; do
87- wget -O $BIN /updates/$update .sh \
88- http://$V_UPD_HOST /upd_scripts/$update .sh & > /dev/null
89-
90- # Checking download result
91- if [ " $? " -ne " 0" ]; then
92- echo " Error: version tree update failed"
93- log_event " $E_UPDATE " " $EVENT "
94- exit $E_UPDATE
95- fi
96- bash $BIN /updates/$update .sh
97- done
98- rm -rf $BIN /updates
99- fi
100-
101- # Updating config version
102- sed -i " s/VERSION='$VERSION '/VERSION='$version '/g" $VESTA /conf/vesta.conf
10352fi
10453
10554
0 commit comments