-
Notifications
You must be signed in to change notification settings - Fork 2
/
updatethreadcache.sh
86 lines (71 loc) · 1.81 KB
/
updatethreadcache.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
#!/bin/sh
cd $(dirname "$0")
. ./params.sh
pad=$(printf %70s | tr ' ' _)
for thread in $(ls -td [0-9]* 2>/dev/null)
do
if [ -e $thread/archive ]
then
continue
fi
cd $thread
lastposts=$(ls -v [0-9]* 2>/dev/null | tail -n $LAST_POSTS)
npost=$(ls [0-9]* 2>/dev/null | wc -l)
nlast=$(echo -n "$lastposts" | grep -c .)
if [ $npost -eq 0 ] && [ "$SHOW_EMPTY_THREADS" != y ]
then
continue
fi
printf "1[thread] %s (%d " "$(cat gophertag)" $npost
if [ $npost -eq 1 ]
then
printf post
else
printf posts
fi
printf ")\t%s\t%s\t%s\r\n" "$CHAN_ROOT/$thread" "$SERVER_HOST" "$SERVER_PORT"
i=$((npost - nlast))
for post in $lastposts
do
stamp=$(echo "$post" | cut -d _ -f 1)
no=$(echo "$post" | cut -d _ -f 2)
posted=$(date -d @$stamp +"$DATE_FORMAT")
tripcode=$(grep -E "^${no} .*$" ../tripcodes | head -n 1 | sed -r 's/^[0-9]+ (.*)$/\1/')
postid=$(grep -E "^${no} .*$" ../postids | head -n 1 | sed -r 's/^[0-9]+ (.*)$/\1/')
if test -n "$tripcode" -a -n "$postid"
then
header=$(printf "__[%s #%d !%s ID: %s]%s" "$posted" "$no" "$tripcode" "$postid" "$pad" | cut -c1-70)
elif test -n "$tripcode"
then
header=$(printf "__[%s #%d !%s]%s" "$posted" "$no" "$tripcode" "$pad" | cut -c1-70)
elif test -n "$postid"
then
header=$(printf "__[%s #%d ID: %s]%s" "$posted" "$no" "$postid" "$pad" | cut -c1-70)
else
header=$(printf "__[%s #%d]%s" "$posted" $no "$pad" | cut -c1-70)
fi
phinfo "$header"
saveifs="$IFS"
IFS=''
cat $post | while read -r line
do
if echo "$line" | grep -q " "
then
printf "%s\r\n" "$line"
else
printf "%s\n" "$line" | fmt -70 | fold -w 70 | while read -r fmtline
do
phinfo "$fmtline"
done
fi
done
IFS="$saveifs"
phline
i=$((i + 1))
done
if [ "$LAST_POSTS" -gt 0 ] && [ "$nlast" -gt 0 ]
then
phline
fi
cd ..
done