forked from ptt/pttbbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timecap_expire.sh
executable file
·88 lines (72 loc) · 1.93 KB
/
timecap_expire.sh
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
#!/usr/bin/env bash
# expire rules
EXPIRE_MINUTES="+$((103000 / 3))"
HOME_EXPIRE_MINUTES="+$((103000 / 6))"
# configuration
BBSHOME=$HOME
BOARD_BASE="$BBSHOME/boards"
HOME_BASE="$BBSHOME/home"
# check TIME_CAPSULE_BASE_FOLDER_NAME in mbbsd/timecap.c
TIMECAP_NAME=".timecap"
expire_folder() {
local timecap_base="$1/$TIMECAP_NAME"
local expire="$2"
if [ ! -d "$timecap_base" ]; then
return
fi
# first stage, expire files
find "$timecap_base" -mmin "$expire" -ls -delete
# second stage, modify .DIR files
# dir_file="$timecap_base/archive.idx"
$BBSHOME/bin/timecap_buildref "$timecap_base"
}
expire_boards() {
local BOARDS="$($BBSHOME/bin/showboard $BBSHOME/.BRD |
sed 's/^ *[0-9][0-9]* //; s/ .*//')"
local board
local num_boards="$(echo $BOARDS | wc -w)"
local i=0
local timecap_base
for board in $BOARDS
do
i=$((i + 1))
printf '\r%05d / %05d [B] %-12s ...' $i $num_boards "$board" >&2
timecap_base="$(printf "%s/%c/%s" "$BOARD_BASE" "$board" "$board")"
expire_folder "$timecap_base" "$EXPIRE_MINUTES"
done
}
expire_home() {
local userid
local i=0
local timecap_base
$BBSHOME/bin/showuser |
while read userid
do
i=$((i + 1))
printf '\r%07d [U] %-12s ...' $i "$userid" >&2
timecap_base="$(printf "%s/%c/%s" "$HOME_BASE" "$userid" "$userid")"
expire_folder "$timecap_base" "$HOME_EXPIRE_MINUTES"
done
}
expire_all() {
date # for loggin
date >&2 # still for logging
expire_boards
expire_home
echo "" >&2
}
main() {
if [ "$#" = "0" ]; then
expire_all
return
fi
local timecap_base
for timecap_base in "$@"; do
local expire="$EXPIRE_MINUTES"
if echo "$timecap_base" | grep -qw "home"; then
expire="$HOME_EXPIRE_MINUTES"
fi
expire_folder "$timecap_base" "$expire"
done
}
main "$@"