Преглед изворни кода

Add hestia auto updater scripts.

Raphael Schneeberger пре 7 година
родитељ
комит
5518e5161d
3 измењених фајлова са 179 додато и 0 уклоњено
  1. 82 0
      bin/v-add-cron-hestia-autoupdate
  2. 64 0
      bin/v-update-sys-hestia
  3. 33 0
      bin/v-update-sys-hestia-all

+ 82 - 0
bin/v-add-cron-hestia-autoupdate

@@ -0,0 +1,82 @@
+#!/bin/bash
+# info: add cron job for hestia autoupdates
+# options: NONE
+#
+# The function adds cronjob for hestia autoupdate.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=admin
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+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
+    exit
+fi
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Generating timestamp
+time_n_date=$(date +'%T %F')
+time=$(echo "$time_n_date" |cut -f 1 -d \ )
+date=$(echo "$time_n_date" |cut -f 2 -d \ )
+
+# Define time somewhere at night
+min=$(generate_password '012345' '2')
+hour=$(generate_password '1234567' '1')
+day='*'
+month='*'
+wday='*'
+command='sudo /usr/local/vesta/bin/v-update-sys-hestia-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" >> $HESTIA/data/users/$user/cron.conf
+
+# Chaning permissions
+chmod 660 $HESTIA/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'
+
+# Restarting crond
+$BIN/v-restart-cron
+check_result $? "Cron restart failed" >/dev/null
+
+# Logging
+log_history "added cron job $job"
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 64 - 0
bin/v-update-sys-hestia

@@ -0,0 +1,64 @@
+#!/bin/bash
+# info: update hestia package/configs
+# options: PACKAGE [VERSION]
+#
+# The function runs as rpm update trigger. It pulls shell script from hestia
+# server and runs it.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+package=$1
+
+# Importing system environment
+source /etc/profile
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking arg number
+check_args '1' "$#" 'PACKAGE'
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+if [ -d "/etc/sysconfig" ]; then
+    # Clean yum chache
+    yum -q clean all
+
+    # Define yum cmd
+    yum="yum -q -y --noplugins --disablerepo=* --enablerepo=hestia"
+
+    # Update hestia package
+    $yum update $package > /dev/null 2>&1
+    check_result $? "$package update failed" $E_UPDATE
+else
+    # Update repo
+    apt-get update -o Dir::Etc::sourcelist="sources.list.d/hestia.list" \
+        -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" -qq
+
+    # Update hestia package
+    apt-get install $package -qq > /dev/null 2>&1
+    check_result $? "$package update failed" $E_UPDATE
+fi
+
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 33 - 0
bin/v-update-sys-hestia-all

@@ -0,0 +1,33 @@
+#!/bin/bash
+# info: update all hestia packages
+# options: USER [RESTART]
+#
+# The function of updating all vesta packages
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Importing system variables
+source /etc/profile
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Starting update loop
+for package in hestia hestia-nginx hestia-php; do
+    $BIN/v-update-sys-hestia "$package"
+done
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+exit