/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/bash

ADEI_PATH=${ADEI_PATH:-/srv/www/htdocs/adei}
ADEI_ADMIN=${ADEI_ADMIN:-0}

date=$(date -Iseconds)

function process_setup {
    setup="$1"
    parallel="$2"

    local args="-parallel $parallel"
    if [ -n "$setup" ]; then
	args="$args -setup $setup"
    else 
	setup=$(php  -r 'require "adei.php"; echo $ADEI_SETUP;')
    fi

    if [ ! -d "setups/$setup" ]; then
        echo "$setup is not existing"
        return
    fi

    if [ "$ADEI_ADMIN" -ne 1 -a -f "setups/$setup/.debug" ]; then
	echo "$date ADEI setup $setup is under debug, skipping..."
	return
    fi

    if [ -f setups/$setup/adei_manager.cron.sh ]; then
	setups/$setup/adei_manager.cron.sh
	return
    fi

    if [ -f setups/$setup/.cache_archives ]; then
	/usr/bin/php system/cache.php -archives $args
    fi

    if [ -f setups/$setup/.backup ]; then
	/usr/bin/php system/backup.php $args
    fi
}

# Keep the first entry for compatibility with obsolete (but stable) docker containers
[ -f /adei/env ] && . /adei/env
[ -f /tmp/adei.env ] && . /tmp/adei.env


if [ "$ADEI_ADMIN" -ne 1 -a -f "/adei/cfg/.debug" ]; then
    echo "$date ADEI is under debug, skipping..."
    exit
fi


script=$( cd $(dirname "$0") && pwd )/$( basename "$0" )
if [ -f /adei/sys/adei_manager.cron.sh -a "$script" != /adei/sys/adei_manager.cron.sh ]; then
    /adei/sys/adei_manager.cron.sh
    exit
fi

(
    cd "$ADEI_PATH"
    
    if [ -d "tmp/adminscripts" ]; then
        for name in $(find tmp/adminscripts -mindepth 1 -maxdepth 1); do
	    echo "$date Processing administrative script $(basename $name)" 
	    php "$name" && rm "$name"
        done
    fi

    if [ -n "$ADEI_SETUP" -o -n "$ADEI_ENABLED_SETUPS" ]; then
        if [ "$ADEI_SETUP" = "all" ]; then
            list=$(echo "$ADEI_ENABLED_SETUPS" | xargs -n 1 | sort -u)
        else
            list=$(echo "$ADEI_SETUP $ADEI_ENABLED_SETUPS" | xargs -n 1 | sort -u)
        fi
    else
        for name in setups/*; do
	    if [ -f $name/.cache ]; then
	        list="$list $(basename $name)"
	    fi
        done
    fi

    if [ -n "$list" ]; then
	for setup in $list; do
	    process_setup "$setup" "$ADEI_PARALLEL" &
	    pids="$pids $!"
	done
    else
	process_setup "" "$ADEI_PARALLEL" &
	pids="$!"
    fi

    /usr/bin/php system/downloads_clean.php

    for pid in $pids; do
        wait $pid
    done
)