-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.sh
More file actions
executable file
·76 lines (62 loc) · 2 KB
/
Copy pathservice.sh
File metadata and controls
executable file
·76 lines (62 loc) · 2 KB
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
#!/system/bin/sh
# Sortify background service.
case "$0" in
*/*) MODDIR=${0%/*} ;;
*) MODDIR=$(pwd) ;;
esac
. "$MODDIR/common.sh"
sortify_common_init "$MODDIR"
wait_until_storage() {
until [ -d "/sdcard" ]; do
sleep 5
done
}
read_service_config() {
sortify_config_refresh
sortify_config_validate_current_schema
sortify_log_config_warning_once
ENABLED=$(sortify_config_get_bool "enabled" "$SORTIFY_DEFAULT_ENABLED")
INTERVAL=$(sortify_config_get_number "interval" "$SORTIFY_DEFAULT_INTERVAL")
BASE_PATH=$(sortify_config_get_string "base_path" "$SORTIFY_DEFAULT_BASE_PATH")
BASE_PATH=$(sortify_normalize_dir "$BASE_PATH")
case "$INTERVAL" in
""|*[!0-9]*) INTERVAL="$SORTIFY_DEFAULT_INTERVAL" ;;
esac
}
wait_until_storage
(
LAST_ENABLED_STATE=""
while true; do
read_service_config
if [ "$ENABLED" = "false" ]; then
if [ "$LAST_ENABLED_STATE" != "false" ]; then
sortify_log_msg "Module disabled in config. Waiting..."
LAST_ENABLED_STATE="false"
sortify_rotate_log
sortify_copy_log_to_base "$BASE_PATH"
fi
sleep 30
continue
fi
if [ "$LAST_ENABLED_STATE" != "true" ]; then
sortify_log_msg "Module enabled."
LAST_ENABLED_STATE="true"
fi
sortify_log_msg "Next sort in ${INTERVAL}s"
sleep "$INTERVAL"
read_service_config
if [ "$ENABLED" = "false" ]; then
if [ "$LAST_ENABLED_STATE" != "false" ]; then
sortify_log_msg "Module disabled before scheduled sort. Skipping..."
LAST_ENABLED_STATE="false"
sortify_rotate_log
sortify_copy_log_to_base "$BASE_PATH"
fi
continue
fi
sh "$MODDIR/action.sh" >> "$SORTIFY_LOG" 2>&1
sortify_log_msg "Cycle done."
sortify_rotate_log
sortify_copy_log_to_base "$BASE_PATH"
done
) &