From 44d907f2020369dc1a575ae35bf56f20ba668701 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 16 Apr 2014 02:26:45 +0300 Subject: [PATCH] autoupdates --- bin/v-add-cron-vesta-autoupdate | 79 +++++++++++++++++++++++++++ bin/v-delete-cron-vesta-autoupdate | 63 +++++++++++++++++++++ bin/v-list-sys-vesta-autoupdate | 64 ++++++++++++++++++++++ bin/v-update-sys-vesta-all | 30 ++++++++++ web/add/cron/autoupdate/index.php | 15 +++++ web/delete/cron/autoupdate/index.php | 15 +++++ web/list/updates/index.php | 4 ++ web/templates/admin/list_updates.html | 14 +++++ 8 files changed, 284 insertions(+) create mode 100755 bin/v-add-cron-vesta-autoupdate create mode 100755 bin/v-delete-cron-vesta-autoupdate create mode 100755 bin/v-list-sys-vesta-autoupdate create mode 100755 bin/v-update-sys-vesta-all create mode 100644 web/add/cron/autoupdate/index.php create mode 100644 web/delete/cron/autoupdate/index.php diff --git a/bin/v-add-cron-vesta-autoupdate b/bin/v-add-cron-vesta-autoupdate new file mode 100755 index 000000000..b29f3e286 --- /dev/null +++ b/bin/v-add-cron-vesta-autoupdate @@ -0,0 +1,79 @@ +#!/bin/bash +# info: add cron job for vesta autoupdates +# options: NONE +# +# The function adds cronjob for vesta autoupdate. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=admin + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM' +is_package_full 'CRON_JOBS' +get_next_cronjob +check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf) +if [ ! -z "$check_cron" ]; then + exit +fi + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Define time somewhere at nigth +min=$(gen_password '012345' '2') +hour=$(gen_password '1234567' '1') +day='*' +month='*' +WDAY='*' +command='sudo /usr/local/vesta/bin/v-update-sys-vesta-all' + +# Concatenating cron string +str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'" +str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" + +# Adding to crontab +echo "$str" >> $VESTA/data/users/$user/cron.conf + +# Chaning permissions +chmod 660 $VESTA/data/users/$user/cron.conf + +# Sort jobs by id number +sort_cron_jobs + +# Sync cronjobs with system crond +sync_cron_jobs + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Increasing cron value +increase_user_value $user '$U_CRON_JOBS' + +# Restart crond +$BIN/v-restart-cron +if [ $? -ne 0 ]; then + exit $E_RESTART +fi + +# Logging +log_history "added cron job $job" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-delete-cron-vesta-autoupdate b/bin/v-delete-cron-vesta-autoupdate new file mode 100755 index 000000000..ee5f74a6b --- /dev/null +++ b/bin/v-delete-cron-vesta-autoupdate @@ -0,0 +1,63 @@ +#!/bin/bash +# info: delete vesta autoupdate cron job +# options: NONE +# +# The function deletes vesta autoupdate cron job. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=admin + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM' +check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf) +if [ -z "$check_cron" ]; then + exit +fi + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + + +# Deleting job +job=$(echo $check_cron|tr ' ' "\n"|grep JOB|cut -f 2 -d "'") +sed -i "/JOB='$job' /d" $USER_DATA/cron.conf + +# Sorting jobs by id +sort_cron_jobs + +# Sync system cron with user +sync_cron_jobs + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Decreasing cron value +decrease_user_value "$user" '$U_CRON_JOBS' + +# Restart crond +$BIN/v-restart-cron +if [ $? -ne 0 ]; then + exit $E_RESTART +fi + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-list-sys-vesta-autoupdate b/bin/v-list-sys-vesta-autoupdate new file mode 100755 index 000000000..ca64646c2 --- /dev/null +++ b/bin/v-list-sys-vesta-autoupdate @@ -0,0 +1,64 @@ +#!/bin/bash +# info: list vesta autoupdate settings +# options: NONE +# +# The function for obtaining autoupdate setings. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user='admin' +format=${1-shell} + +# Includes +source $VESTA/func/main.sh + +# Json function +json_list_autoupdate() { + echo '[' + if [ -z "$check_cron" ]; then + echo -e "\t\"Disabled\"," + else + echo -e "\t\"Enabled\"" + fi + echo "]" +} + +# Shell function +shell_list_autoupdate() { + if [ -z "$nohead" ]; then + echo "AUTOUPDATE" + echo "----------" + fi + if [ -z "$check_cron" ]; then + echo "Disabled" + else + echo "Enabled" + fi +} + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Check cron tab +check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf) + +# Listing domains +case $format in + json) json_list_autoupdate ;; + plain) nohead=1; shell_list_autoupdate ;; + shell) shell_list_autoupdate ;; + *) check_args '1' '0' '[FORMAT]' ;; +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-update-sys-vesta-all b/bin/v-update-sys-vesta-all new file mode 100755 index 000000000..67b0712c6 --- /dev/null +++ b/bin/v-update-sys-vesta-all @@ -0,0 +1,30 @@ +#!/bin/bash +# info: update all vesta packages +# options: USER [RESTART] +# +# The function of updating all vesta packages + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Starting update loop +for package in vesta vesta-ngin vesta-php; do + $BIN/v-update-sys-vesta "$package" +done + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/web/add/cron/autoupdate/index.php b/web/add/cron/autoupdate/index.php new file mode 100644 index 000000000..c3866579d --- /dev/null +++ b/web/add/cron/autoupdate/index.php @@ -0,0 +1,15 @@ + @@ -16,6 +17,19 @@ +