Files
VestaCP/bin/v_update_sys_vesta
2012-01-03 21:46:07 +02:00

115 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# info: update vesta after rpm update
# options: version
#
# The function is runs as rpm update trigger. It pulls shell script from vesta
# server and runs it.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
version=$1
updates=''
# Importing system enviroment
source /etc/profile.d/vesta.sh
# Importing variables
source $VESTA/conf/vars.conf
source $V_CONF/vesta.conf
source $V_FUNC/shared.func
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'version'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Compare versions
if [ "$version" != "$VERSION" ]; then
# Downloading version tree
upd_host="yum.vestacp.com"
wget -O "/tmp/versions" http://$V_UPD_HOST/upd_scripts/version_tree.txt \
>/dev/null 2>&1
# Checking download result
if [ "$?" -ne "0" ]; then
echo "Error: version tree update failed"
log_event 'debug' "$E_UPDATE $V_EVENT"
exit $E_UPDATE
fi
# Deviding version
v1=$(echo "$version" |cut -f 1 -d '.')
v2=$(echo "$version" |cut -f 2 -d '.')
v3=$(echo "$version" |cut -f 3 -d '.')
V1=$(echo "$VERSION" |cut -f 1 -d '.')
V2=$(echo "$VERSION" |cut -f 2 -d '.')
V3=$(echo "$VERSION" |cut -f 3 -d '.')
# Checking difference between versions
# Too nested tests, sory about complexity
if [ "$V1" -lt "$v1" ]; then
for ver in $(seq $V1 $v1); do
updates="$updates $(grep "^$ver." /tmp/versions|grep ":1$"|\
cut -f 1 -d :)"
done
else
if [ "$V2" -lt "$v2" ]; then
for ver in $(seq $V2 $v2); do
updates="$updates $(grep "^$v1.$ver." /tmp/versions |\
grep ":1$"|cut -f 1 -d :)"
done
else
V4=$((V3 + 1))
for ver in $(seq $V4 $v3); do
updates="$updates $(grep "^$v1.$v2.$ver" /tmp/versions |\
grep ":1$"|cut -f 1 -d :)"
done
fi
fi
# Executing update scripts
if [ ! -z "$updates" ]; then
mkdir $V_BIN/updates >/dev/null 2>&1
for update in $updates; do
wget -O $V_BIN/updates/$update.sh \
http://$V_UPD_HOST/upd_scripts/$update.sh >/dev/null 2>&1
# Checking download result
if [ "$?" -ne "0" ]; then
echo "Error: version tree update failed"
log_event 'debug' "$E_UPDATE $V_EVENT"
exit $E_UPDATE
fi
bash $V_BIN/updates/$update.sh
done
rm -rf $V_BIN/updates
fi
# Updating config version
sed -i "s/VERSION='$VERSION'/VERSION='$version'/g" $V_CONF/vesta.conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event 'system' "$V_EVENT"
exit