|
| 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 |
0 commit comments