Skip to content

Commit 44d907f

Browse files
committed
autoupdates
1 parent 83bd13f commit 44d907f

File tree

8 files changed

+284
-0
lines changed

8 files changed

+284
-0
lines changed

bin/v-add-cron-vesta-autoupdate

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# info: add cron job for vesta autoupdates
3+
# options: NONE
4+
#
5+
# The function adds cronjob for vesta autoupdate.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=admin
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
25+
is_package_full 'CRON_JOBS'
26+
get_next_cronjob
27+
check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
28+
if [ ! -z "$check_cron" ]; then
29+
exit
30+
fi
31+
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
# Define time somewhere at nigth
38+
min=$(gen_password '012345' '2')
39+
hour=$(gen_password '1234567' '1')
40+
day='*'
41+
month='*'
42+
WDAY='*'
43+
command='sudo /usr/local/vesta/bin/v-update-sys-vesta-all'
44+
45+
# Concatenating cron string
46+
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
47+
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
48+
49+
# Adding to crontab
50+
echo "$str" >> $VESTA/data/users/$user/cron.conf
51+
52+
# Chaning permissions
53+
chmod 660 $VESTA/data/users/$user/cron.conf
54+
55+
# Sort jobs by id number
56+
sort_cron_jobs
57+
58+
# Sync cronjobs with system crond
59+
sync_cron_jobs
60+
61+
62+
#----------------------------------------------------------#
63+
# Vesta #
64+
#----------------------------------------------------------#
65+
66+
# Increasing cron value
67+
increase_user_value $user '$U_CRON_JOBS'
68+
69+
# Restart crond
70+
$BIN/v-restart-cron
71+
if [ $? -ne 0 ]; then
72+
exit $E_RESTART
73+
fi
74+
75+
# Logging
76+
log_history "added cron job $job"
77+
log_event "$OK" "$EVENT"
78+
79+
exit

bin/v-delete-cron-vesta-autoupdate

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# info: delete vesta autoupdate cron job
3+
# options: NONE
4+
#
5+
# The function deletes vesta autoupdate cron job.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=admin
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
25+
check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
26+
if [ -z "$check_cron" ]; then
27+
exit
28+
fi
29+
30+
31+
#----------------------------------------------------------#
32+
# Action #
33+
#----------------------------------------------------------#
34+
35+
36+
# Deleting job
37+
job=$(echo $check_cron|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
38+
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
39+
40+
# Sorting jobs by id
41+
sort_cron_jobs
42+
43+
# Sync system cron with user
44+
sync_cron_jobs
45+
46+
47+
#----------------------------------------------------------#
48+
# Vesta #
49+
#----------------------------------------------------------#
50+
51+
# Decreasing cron value
52+
decrease_user_value "$user" '$U_CRON_JOBS'
53+
54+
# Restart crond
55+
$BIN/v-restart-cron
56+
if [ $? -ne 0 ]; then
57+
exit $E_RESTART
58+
fi
59+
60+
# Logging
61+
log_event "$OK" "$EVENT"
62+
63+
exit

bin/v-list-sys-vesta-autoupdate

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# info: list vesta autoupdate settings
3+
# options: NONE
4+
#
5+
# The function for obtaining autoupdate setings.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user='admin'
14+
format=${1-shell}
15+
16+
# Includes
17+
source $VESTA/func/main.sh
18+
19+
# Json function
20+
json_list_autoupdate() {
21+
echo '['
22+
if [ -z "$check_cron" ]; then
23+
echo -e "\t\"Disabled\","
24+
else
25+
echo -e "\t\"Enabled\""
26+
fi
27+
echo "]"
28+
}
29+
30+
# Shell function
31+
shell_list_autoupdate() {
32+
if [ -z "$nohead" ]; then
33+
echo "AUTOUPDATE"
34+
echo "----------"
35+
fi
36+
if [ -z "$check_cron" ]; then
37+
echo "Disabled"
38+
else
39+
echo "Enabled"
40+
fi
41+
}
42+
43+
44+
#----------------------------------------------------------#
45+
# Action #
46+
#----------------------------------------------------------#
47+
48+
# Check cron tab
49+
check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
50+
51+
# Listing domains
52+
case $format in
53+
json) json_list_autoupdate ;;
54+
plain) nohead=1; shell_list_autoupdate ;;
55+
shell) shell_list_autoupdate ;;
56+
*) check_args '1' '0' '[FORMAT]' ;;
57+
esac
58+
59+
60+
#----------------------------------------------------------#
61+
# Vesta #
62+
#----------------------------------------------------------#
63+
64+
exit

bin/v-update-sys-vesta-all

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# info: update all vesta packages
3+
# options: USER [RESTART]
4+
#
5+
# The function of updating all vesta packages
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
source $VESTA/func/main.sh
14+
source $VESTA/conf/vesta.conf
15+
16+
17+
#----------------------------------------------------------#
18+
# Action #
19+
#----------------------------------------------------------#
20+
21+
# Starting update loop
22+
for package in vesta vesta-ngin vesta-php; do
23+
$BIN/v-update-sys-vesta "$package"
24+
done
25+
26+
#----------------------------------------------------------#
27+
# Vesta #
28+
#----------------------------------------------------------#
29+
30+
exit

web/add/cron/autoupdate/index.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
7+
8+
if ($_SESSION['user'] == 'admin') {
9+
exec (VESTA_CMD."v-add-cron-vesta-autoupdate", $output, $return_var);
10+
$_SESSION['error_msg'] = __('Autoupdate has been susscessfully enabled');
11+
unset($output);
12+
}
13+
14+
header("Location: /list/updates/");
15+
exit;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
7+
8+
if ($_SESSION['user'] == 'admin') {
9+
exec (VESTA_CMD."v-delete-cron-vesta-autoupdate", $output, $return_var);
10+
$_SESSION['error_msg'] = __('Autoupdate has been susscessfully disabled');
11+
unset($output);
12+
}
13+
14+
header("Location: /list/updates/");
15+
exit;

web/list/updates/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
exec (VESTA_CMD."v-list-sys-vesta-updates json", $output, $return_var);
1717
$data = json_decode(implode('', $output), true);
1818
unset($output);
19+
exec (VESTA_CMD."v-list-sys-vesta-autoupdate plain", $output, $return_var);
20+
$autoupdate = $output['0'];
21+
unset($output);
22+
1923
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_updates.html');
2024
}
2125

web/templates/admin/list_updates.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<table class="submenu">
23
<tr>
34
<td style="padding: 14px 10px">
@@ -16,6 +17,19 @@
1617
</select>
1718
<input type="submit" name="ok" value="" class="submenu-button-select">
1819
</div>
20+
<div class="submenu-select-block">
21+
<?php
22+
if($autoupdate == 'Enabled') {
23+
?>
24+
<a class="submenu-select-link" href="/delete/cron/autoupdate/">[ <?php print __('disable autoupdate');?> ]</a>
25+
<?php
26+
} else {
27+
?>
28+
<a class="submenu-select-link" href="/add/cron/autoupdate/">[ <?php print __('enable autoupdate');?> ]</a>
29+
<?php
30+
}
31+
?>
32+
</div>
1933
<?php display_error_block(); ?>
2034
</td>
2135
</tr>

0 commit comments

Comments
 (0)