-
Notifications
You must be signed in to change notification settings - Fork 2
/
newthread
executable file
·119 lines (97 loc) · 1.98 KB
/
newthread
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
umask 002
cd $(dirname "$0")
. ./params.sh
comment="$@"
len=$(echo -n "$comment" | wc -c)
if [ -e threads ]
then
no=$(cat threads)
else
no=0
fi
no=$(($no + 1))
stamp=$(date +%s)
post=$no
if [ "$len" -gt "$MAX_TITLELEN" ]
then
pherror 'Thread creation failed.'
phline
phinfo "Title too long ($len/$MAX_TITLELEN)"
phitem 1 'Return' "$CHAN_ROOT"
exit 1
fi
if [ "$MAX_THREADS" -lt 1 ]
then
pherror 'New threads are disabled on this board.'
phitem 1 Return "$CHAN_ROOT"
exit 1
fi
if [ "$comment" = "" ]
then
pherror 'Thread creation failed: You must include a title'
phitem 1 Return "$CHAN_ROOT"
exit 1
fi
if ! sh cooldown.sh thread
then
pherror "Thread creation failed"
phline
phinfo "Please wait $POST_LIMIT seconds before creating a new thread."
phitem 1 "Return" "$CHAN_ROOT"
exit 1
fi
nthreads=$(ls -d [0-9]* 2>/dev/null | wc -l)
narchive=$(ls -d [0-9]*/archive 2>/dev/null | wc -l)
if [ $((nthreads - narchive)) -ge "$MAX_THREADS" ]
then
for thread in $(ls -dt [0-9]* 2>/dev/null)
do
if [ -e $thread/archive ]
then
continue
else
old=$thread
fi
done
if [ "$ENABLE_ARCHIVE" != n ]
then
sh archive.sh $old
if [ ! -e $old/archive ]
then
pherror 'Failed to archive thread!'
phitem 1 Return "$CHAN_ROOT"
exit
fi
else
rm -r $old
if [ -e $old ]
then
pherror 'Failed to remove thread!'
phitem 1 Return "$CHAN_ROOT"
exit
fi
fi
fi
mkdir $post
if [ -e $post ]
then
echo "$comment" > $post/gophertag
ln template_gophermap $post/gophermap
ln template_post $post/post
ln template_postlink $post/postlink
ln template_postfile $post/postfile
ln template_postsplr $post/postsplr
ln template_postfileb64 $post/postfileb64
ln template_postb64 $post/postb64
touch $post/postcache
echo $stamp > $post/stamp
phinfo 'Thread created successfully!'
phitem 1 'View thread' "$CHAN_ROOT/$post"
echo $no > threads
sh updatethreadcache.sh > threadcache
else
pherror 'Could not create thread.'
phitem 1 Return "$CHAN_ROOT"
exit 1
fi