From bcd5130866229381d45e494f2ecca47190b8c383 Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Wed, 27 Oct 2021 11:14:09 +0200 Subject: [PATCH] implemented cron mode --- init.sh | 14 ++++++++++++++ lib/zzz_main_fct.sh | 14 ++++++++++++-- modules/upgrade_dist.sh | 8 +++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/init.sh b/init.sh index 107f664..e6ad95b 100755 --- a/init.sh +++ b/init.sh @@ -148,6 +148,20 @@ if [[ $RUN_SHELL == true ]]; then exit 0 fi +# If cron mode, run cron tasks then exit +if [[ $CRON_MODE == true ]]; then + for mod in $MODULE_LIST; do + if [[ $(function_exists cron_$mod) ]]; then + prnt I "Running cron task for module $mod ..." + cron_$mod + else + prnt I "No cron task for module $mod." + fi + done + prnt I "All cron executed successfully !" + exit 0 +fi + # Run prechecks if [[ JUMP != true ]]; then tmpfile=$(mktemp /tmp/init-XXXXXX) diff --git a/lib/zzz_main_fct.sh b/lib/zzz_main_fct.sh index d6d5d6e..e788c13 100644 --- a/lib/zzz_main_fct.sh +++ b/lib/zzz_main_fct.sh @@ -76,7 +76,10 @@ read_commandline() export RUN_SHELL=true ;; "--chroot") - local want_chroot + local want_chroot=true + ;; + "--cron") + export CRON_MODE=true ;; *) if [[ $want_module == true ]]; then @@ -273,13 +276,20 @@ process_commandline_and_vars() fi fi + if [[ $CRON_MODE == true ]]; then + if [[ $CHECK_ONLY == true || $JUMP == true ]]; then + prnt E "Des paramètres sont incompatibles avec le mode cron." + die 15 --force + fi + fi + # Configure module list if [[ -n $MANUAL_MODULE_LIST ]]; then prnt W "Une liste de modules manuelle sera utilisé." export MODULE_LIST=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g") fi - # Check for module list existance en basic syntax + # Check for module list existance and basic syntax if [[ -n $MODULE_LIST ]]; then if [[ $(echo $MODULE_LIST | grep '-') ]]; then prnt E "Le tiret est interdit dans les noms de module." diff --git a/modules/upgrade_dist.sh b/modules/upgrade_dist.sh index ee3dcaa..e3c5442 100644 --- a/modules/upgrade_dist.sh +++ b/modules/upgrade_dist.sh @@ -13,7 +13,7 @@ # * PROXYAPTPORT: Working port for APT proxy # ------------------------------------------------------------------------------ -export VER_upgrade_dist="0.1.3" +export VER_upgrade_dist="0.2.0" # As aptitude might fail if clock is too far from real time, we need to depend # on ntp @@ -70,6 +70,12 @@ precheck_upgrade_dist() fi } +cron_upgrade_dist() +{ + pkgupdt + pkgupgd +} + export -f upgrade_dist export -f precheck_upgrade_dist