-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
98 lines (81 loc) · 2.45 KB
/
Copy pathmain.lua
File metadata and controls
98 lines (81 loc) · 2.45 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local config = {
older_than_days = 7,
}
local RAN_FILE = PLUGIN_DIR .. "/boot_ran"
local function trim(s)
if not s then return "" end
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
local function load_config()
local function num(v, d)
local n = tonumber(v)
return n ~= nil and n or d
end
config.older_than_days = num(get_config("older_than_days"), 7)
end
local function already_ran_today()
local ok, data = pcall(read_file, RAN_FILE)
if ok and data then
return trim(data) == os.date("%Y-%m-%d")
end
return false
end
local function mark_ran()
pcall(write_file, RAN_FILE, os.date("%Y-%m-%d"))
end
local function clean()
load_config()
info("Cleaning...")
local paths = {
"/data/local/tmp/",
"/data/system/dropbox/",
"/data/vendor/log/",
}
local total = 0
for _, path in ipairs(paths) do
local r = exec("sh", "-c", "find " .. path .. " -type f -mtime +" .. config.older_than_days .. " 2>/dev/null | wc -l")
if r.ok and r.stdout then
local count = tonumber(trim(r.stdout)) or 0
if count > 0 then
exec("sh", "-c", "find " .. path .. " -type f -mtime +" .. config.older_than_days .. " -delete 2>/dev/null")
info("Deleted " .. count .. " from " .. path)
total = total + count
end
end
end
local r2 = exec("sh", "-c", "find /data/adb/modules/*/ -name '*.log' -mtime +" .. config.older_than_days .. " 2>/dev/null | wc -l")
if r2.ok and r2.stdout then
local count = tonumber(trim(r2.stdout)) or 0
if count > 0 then
exec("sh", "-c", "find /data/adb/modules/*/ -name '*.log' -mtime +" .. config.older_than_days .. " -delete 2>/dev/null")
info("Deleted " .. count .. " module logs")
total = total + count
end
end
info("Done: " .. total .. " files removed")
end
load_config()
return {
post_fs_data = function()
info("boot-cleaner loaded")
end,
service = function()
info("boot-cleaner service started")
end,
boot_completed = function()
if already_ran_today() then
info("boot-cleaner already ran today")
return
end
info("boot-cleaner running")
clean()
mark_ran()
end,
action = function()
info("manual clean")
clean()
end,
clean_now = function()
clean()
end,
}