Skip to content

Commit 5518e51

Browse files
authored
Add hestia auto updater scripts.
1 parent bbb4abf commit 5518e51

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed

bin/v-add-cron-hestia-autoupdate

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# info: add cron job for hestia autoupdates
3+
# options: NONE
4+
#
5+
# The function adds cronjob for hestia autoupdate.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=admin
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.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-hestia-all' $USER_DATA/cron.conf)
28+
if [ ! -z "$check_cron" ]; then
29+
exit
30+
fi
31+
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
# Generating timestamp
38+
time_n_date=$(date +'%T %F')
39+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
40+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
41+
42+
# Define time somewhere at night
43+
min=$(generate_password '012345' '2')
44+
hour=$(generate_password '1234567' '1')
45+
day='*'
46+
month='*'
47+
wday='*'
48+
command='sudo /usr/local/vesta/bin/v-update-sys-hestia-all'
49+
50+
# Concatenating cron string
51+
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
52+
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
53+
54+
# Adding to crontab
55+
echo "$str" >> $HESTIA/data/users/$user/cron.conf
56+
57+
# Chaning permissions
58+
chmod 660 $HESTIA/data/users/$user/cron.conf
59+
60+
# Sort jobs by id number
61+
sort_cron_jobs
62+
63+
# Sync cronjobs with system crond
64+
sync_cron_jobs
65+
66+
67+
#----------------------------------------------------------#
68+
# Vesta #
69+
#----------------------------------------------------------#
70+
71+
# Increasing cron value
72+
increase_user_value $user '$U_CRON_JOBS'
73+
74+
# Restarting crond
75+
$BIN/v-restart-cron
76+
check_result $? "Cron restart failed" >/dev/null
77+
78+
# Logging
79+
log_history "added cron job $job"
80+
log_event "$OK" "$ARGUMENTS"
81+
82+
exit

bin/v-update-sys-hestia

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# info: update hestia package/configs
3+
# options: PACKAGE [VERSION]
4+
#
5+
# The function runs as rpm update trigger. It pulls shell script from hestia
6+
# server and runs it.
7+
8+
9+
#----------------------------------------------------------#
10+
# Variable&Function #
11+
#----------------------------------------------------------#
12+
13+
# Argument definition
14+
package=$1
15+
16+
# Importing system environment
17+
source /etc/profile
18+
19+
# Includes
20+
source $HESTIA/func/main.sh
21+
source $HESTIA/conf/hestia.conf
22+
23+
24+
#----------------------------------------------------------#
25+
# Verifications #
26+
#----------------------------------------------------------#
27+
28+
# Checking arg number
29+
check_args '1' "$#" 'PACKAGE'
30+
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
if [ -d "/etc/sysconfig" ]; then
37+
# Clean yum chache
38+
yum -q clean all
39+
40+
# Define yum cmd
41+
yum="yum -q -y --noplugins --disablerepo=* --enablerepo=hestia"
42+
43+
# Update hestia package
44+
$yum update $package > /dev/null 2>&1
45+
check_result $? "$package update failed" $E_UPDATE
46+
else
47+
# Update repo
48+
apt-get update -o Dir::Etc::sourcelist="sources.list.d/hestia.list" \
49+
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" -qq
50+
51+
# Update hestia package
52+
apt-get install $package -qq > /dev/null 2>&1
53+
check_result $? "$package update failed" $E_UPDATE
54+
fi
55+
56+
57+
#----------------------------------------------------------#
58+
# Hestia #
59+
#----------------------------------------------------------#
60+
61+
# Logging
62+
log_event "$OK" "$ARGUMENTS"
63+
64+
exit

bin/v-update-sys-hestia-all

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

0 commit comments

Comments
 (0)