1
0
Эх сурвалжийг харах

Merge branch 'feature/v-add-cron-hestia-autoupdate' into staging/features

Kristan Kenney 5 жил өмнө
parent
commit
ac81abf9f3

+ 26 - 10
bin/v-add-cron-hestia-autoupdate

@@ -1,8 +1,8 @@
 #!/bin/bash
 # info: add cron job for hestia autoupdates
-# options: NONE
+# options: MODE
 #
-# The function adds cronjob for hestia autoupdate.
+# The function adds cronjob for hestia autoupdate from apt or git.
 
 
 #----------------------------------------------------------#
@@ -11,6 +11,7 @@
 
 # Argument definition
 user=admin
+mode=$1
 
 # Includes
 source $HESTIA/func/main.sh
@@ -24,8 +25,9 @@ source $HESTIA/conf/hestia.conf
 is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
 is_package_full 'CRON_JOBS'
 get_next_cronjob
-check_cron=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
-if [ ! -z "$check_cron" ]; then
+check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
+check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
+if [ ! -z "$check_cron_apt" ] || [ ! -z "$check_cron_git" ]; then
     exit
 fi
 
@@ -42,13 +44,27 @@ time_n_date=$(date +'%T %F')
 time=$(echo "$time_n_date" |cut -f 1 -d \ )
 date=$(echo "$time_n_date" |cut -f 2 -d \ )
 
+# Remove existing cron job
+$BIN/v-delete-cron-hestia-autoupdate
+
 # Define time somewhere at night
-min=$(generate_password '012345' '2')
-hour=$(generate_password '1234567' '1')
-day='*'
-month='*'
-wday='*'
-command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
+if [ -z "$mode" ] || [ "$mode" = "apt" ]; then
+    min=$(generate_password '012345' '2')
+    hour=$(generate_password '1234567' '1')
+    day='*'
+    month='*'
+    wday='*'
+    command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
+fi
+
+if [ "$mode" = "git" ]; then
+    min='0'
+    hour='0'
+    day='*'
+    month='*'
+    wday='*'
+    command='sudo /usr/local/hestia/bin/v-update-sys-hestia-git'
+fi
 
 # Concatenating cron string
 str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"

+ 9 - 5
bin/v-delete-cron-hestia-autoupdate

@@ -22,10 +22,8 @@ source $HESTIA/conf/hestia.conf
 #----------------------------------------------------------#
 
 is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
-check_cron=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
-if [ -z "$check_cron" ]; then
-    exit
-fi
+check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
+check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
@@ -37,7 +35,13 @@ check_hestia_demo_mode
 
 
 # Deleting job
-job=$(echo $check_cron|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
+if [ ! -z "$check_cron_apt" ]; then
+    job=$(echo $check_cron_apt|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
+fi
+if [ ! -z "$check_cron_git" ]; then
+    job=$(echo $check_cron_git|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
+fi
+
 sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
 
 # Sorting jobs by id

+ 5 - 1
bin/v-update-sys-hestia-git

@@ -7,6 +7,7 @@
 #           - Will download from the hestiacp repository
 #           - Pulls code from staging/beta branch
 #           - install: installs package immediately
+#           - install-auto: installs package and schedules automatic updates from Git
 #           - 'all': (optional) - compiles nginx and php alongside panel.
 #                                 this option takes a long time, only use when needed
 
@@ -421,8 +422,11 @@ install_build() {
 
 # Define installation routine
 
-if [ "$install" = "install" ] || [ "$install" = "yes" ]; then 
+if [ "$install" = "install" ] || [ "$install" = "yes" ] || [ "$install" = "install-auto" ]; then 
     install_build
+    if [ "$install" = "install-auto" ]; then
+        $HESTIA/bin/v-add-cron-hestia-autoupdate git
+    fi
 else
     warning_message
     read -p "Do you wish to proceed with the installation? [y/n] " answer

+ 1 - 1
install/hst-install-debian.sh

@@ -1848,7 +1848,7 @@ command="sudo $HESTIA/bin/v-update-sys-rrd"
 $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
 
 # Enable automatic updates
-$HESTIA/bin/v-add-cron-hestia-autoupdate
+$HESTIA/bin/v-add-cron-hestia-autoupdate apt
 
 # Building initital rrd images
 $HESTIA/bin/v-update-sys-rrd

+ 1 - 1
install/hst-install-ubuntu.sh

@@ -1852,7 +1852,7 @@ command="sudo $HESTIA/bin/v-update-sys-rrd"
 $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
 
 # Enable automatic updates
-$HESTIA/bin/v-add-cron-hestia-autoupdate
+$HESTIA/bin/v-add-cron-hestia-autoupdate apt
 
 # Building initital rrd images
 $HESTIA/bin/v-update-sys-rrd