-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
245 lines (217 loc) · 7.41 KB
/
setup.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Setup params.sh
if [ -e "params.sh" ]
then
. ./params.sh
DEFAULT_SERVER_HOST="$SERVER_HOST"
DEFAULT_SERVER_PORT="$SERVER_PORT"
DEFAULT_CHAN_ROOT="$CHAN_ROOT"
DEFAULT_MAX_THREADS=$MAX_THREADS
DEFAULT_MAX_TITLELEN=$MAX_TITLELEN
DEFAULT_MAX_POSTS=$MAX_POSTS
DEFAULT_MAX_POSTLEN=$MAX_POSTLEN
DEFAULT_ENABLE_ARCHIVE=$ENABLE_ARCHIVE
DEFAULT_DATE_FORMAT="$DATE_FORMAT"
DEFAULT_SHOW_EMPTY_THREADS=$SHOW_EMPTY_THREADS
DEFAULT_LAST_POSTS=$LAST_POSTS
DEFAULT_MAX_UPLOAD=$MAX_UPLOAD
DEFAULT_REMOTE_FILE_UPLOAD=$REMOTE_FILE_UPLOAD
DEFAULT_MAX_IMAGE=$MAX_IMAGE
DEFAULT_DATA_DIR=$DATA_DIR
DEFAULT_DELETE_TIME=$DELETE_TIME
DEFAULT_MAX_RSS_ITEMS=$MAX_RSS_ITEMS
DEFAULT_POST_LIMIT=$POST_LIMIT
DEFAULT_SALT_DIR=$SALT_DIR
DEFAULT_ENABLE_POST_IDS=$ENABLE_POST_IDS
else
DEFAULT_SERVER_HOST=localhost
DEFAULT_SERVER_PORT=70
DEFAULT_CHAN_ROOT=/$(basename $(pwd))
DEFAULT_MAX_THREADS=15
DEFAULT_MAX_TITLELEN=40
DEFAULT_MAX_POSTS=0
DEFAULT_MAX_POSTLEN=256
DEFAULT_ENABLE_ARCHIVE=y
DEFAULT_DATE_FORMAT='%Y-%m-%d(%a)%H:%M:%S'
DEFAULT_SHOW_EMPTY_THREADS=y
DEFAULT_LAST_POSTS=3
DEFAULT_MAX_UPLOAD=1000000
DEFAULT_REMOTE_FILE_UPLOAD=n
DEFAULT_MAX_IMAGE=5000x5000
DEFAULT_DATA_DIR=/var/1436chan
DEFAULT_DELETE_TIME=600
DEFAULT_MAX_RSS_ITEMS=10
DEFAULT_POST_LIMIT=30
DEFAULT_SALT_DIR=/var/1436chan/salts
DEFAULT_ENABLE_POST_IDS=n
fi
if [ "$1" != "-quick" ]
then
read -p "Hostname of the server [$DEFAULT_SERVER_HOST]: " SERVER_HOST
read -p "Port of the server [$DEFAULT_SERVER_PORT]: " SERVER_PORT
read -p "Selector for the board [$DEFAULT_CHAN_ROOT]: " CHAN_ROOT
read -p "Max threads [$DEFAULT_MAX_THREADS]: " MAX_THREADS
read -p "Max thread title length [$DEFAULT_MAX_TITLELEN]: " MAX_TITLELEN
read -p "Max posts [$DEFAULT_MAX_POSTS]: " MAX_POSTS
read -p "Max post length [$DEFAULT_MAX_POSTLEN]: " MAX_POSTLEN
read -p "Enable archive? (y/n) [y]: " ENABLE_ARCHIVE
read -p "Date format [$DEFAULT_DATE_FORMAT]: " DATE_FORMAT
read -p "Show empty threads (y/n) [$DEFAULT_SHOW_EMPTY_THREADS]: " SHOW_EMPTY_THREADS
read -p "Last posts to show [$DEFAULT_LAST_POSTS]: " LAST_POSTS
read -p "Enable uploading of files? (y/n) [y]: " ENABLE_UPLOAD
if [ ! "$ENABLE_UPLOAD" = "n" ]
then
read -p "Maximum uploaded file size (bytes) [$DEFAULT_MAX_UPLOAD]: " MAX_UPLOAD
else
MAX_UPLOAD=0
fi
read -p "Enable remote file uploads? (y/n) [$DEFAULT_REMOTE_FILE_UPLOAD]: " REMOTE_FILE_UPLOAD
read -p "Maximum image dimensions (WxH) [$DEFAULT_MAX_IMAGE]: " MAX_IMAGE
read -p "Data directory [$DEFAULT_DATA_DIR]: " DATA_DIR
read -p "Time limit to delete posts [$DEFAULT_DELETE_TIME]: " DELETE_TIME
read -p "Max RSS items [$DEFAULT_MAX_RSS_ITEMS]: " MAX_RSS_ITEMS
read -p "Post cooldown [$DEFAULT_POST_LIMIT]: " POST_LIMIT
read -p "Salt directory [$DEFAULT_SALT_DIR]: " SALT_DIR
read -p "Enable post IDs? (y/n) [$DEFAULT_ENABLE_POST_IDS]: " ENABLE_POST_IDS
fi
if [ -z "$SERVER_HOST" ]; then SERVER_HOST="$DEFAULT_SERVER_HOST"; fi
if [ -z "$SERVER_PORT" ]; then SERVER_PORT="$DEFAULT_SERVER_PORT"; fi
if [ -z "$CHAN_ROOT" ]; then CHAN_ROOT="$DEFAULT_CHAN_ROOT"; fi
if [ -z "$MAX_THREADS" ]; then MAX_THREADS=$DEFAULT_MAX_THREADS; fi
if [ -z "$MAX_TITLELEN" ]; then MAX_TITLELEN=$DEFAULT_MAX_TITLELEN; fi
if [ -z "$MAX_POSTS" ]; then MAX_POSTS=$DEFAULT_MAX_POSTS; fi
if [ -z "$MAX_POSTLEN" ]; then MAX_POSTLEN=$DEFAULT_MAX_POSTLEN; fi
if [ -z "$ENABLE_ARCHIVE" ]; then ENABLE_ARCHIVE=$DEFAULT_ENABLE_ARCHIVE; fi
if [ -z "$DATE_FORMAT" ]; then DATE_FORMAT="$DEFAULT_DATE_FORMAT"; fi
if [ -z "$SHOW_EMPTY_THREADS" ]; then SHOW_EMPTY_THREADS=$DEFAULT_SHOW_EMPTY_THREADS; fi
if [ -z "$LAST_POSTS" ]; then LAST_POSTS=$DEFAULT_LAST_POSTS; fi
if [ -z "$MAX_UPLOAD" ]; then MAX_UPLOAD=$DEFAULT_MAX_UPLOAD; fi
if [ -z "$REMOTE_FILE_UPLOAD" ]; then REMOTE_FILE_UPLOAD=$DEFAULT_REMOTE_FILE_UPLOAD; fi
if [ -z "$MAX_IMAGE" ]; then MAX_IMAGE=$DEFAULT_MAX_IMAGE; fi
if [ -z "$DATA_DIR" ]; then DATA_DIR=$DEFAULT_DATA_DIR; fi
if [ -z "$DELETE_TIME" ]; then DELETE_TIME=$DEFAULT_DELETE_TIME; fi
if [ -z "$MAX_RSS_ITEMS" ]; then MAX_RSS_ITEMS=$DEFAULT_MAX_RSS_ITEMS; fi
if [ -z "$POST_LIMIT" ]; then POST_LIMIT=$DEFAULT_POST_LIMIT; fi
if [ -z "$SALT_DIR" ]; then SALT_DIR=$DEFAULT_SALT_DIR; fi
if [ -z "$ENABLE_POST_IDS" ]; then ENABLE_POST_IDS=$DEFAULT_ENABLE_POST_IDS; fi
echo "SERVER_HOST=$SERVER_HOST" > params.sh
echo "SERVER_PORT=$SERVER_PORT" >> params.sh
echo "CHAN_ROOT=$CHAN_ROOT" >> params.sh
echo "MAX_THREADS=$MAX_THREADS" >> params.sh
echo "MAX_TITLELEN=$MAX_TITLELEN" >> params.sh
echo "MAX_POSTS=$MAX_POSTS" >> params.sh
echo "MAX_POSTLEN=$MAX_POSTLEN" >> params.sh
echo "ENABLE_ARCHIVE=$ENABLE_ARCHIVE" >> params.sh
echo "DATE_FORMAT='$DATE_FORMAT'" >> params.sh
echo "SHOW_EMPTY_THREADS=$SHOW_EMPTY_THREADS" >> params.sh
echo "LAST_POSTS=$LAST_POSTS" >> params.sh
echo "MAX_UPLOAD=$MAX_UPLOAD" >> params.sh
echo "REMOTE_FILE_UPLOAD=$REMOTE_FILE_UPLOAD" >> params.sh
echo "MAX_IMAGE=$MAX_IMAGE" >> params.sh
echo "DATA_DIR=$DATA_DIR" >> params.sh
echo "DELETE_TIME=$DELETE_TIME" >> params.sh
echo "MAX_RSS_ITEMS=$MAX_RSS_ITEMS" >> params.sh
echo "POST_LIMIT=$POST_LIMIT" >> params.sh
echo "SALT_DIR=$SALT_DIR" >> params.sh
echo "ENABLE_POST_IDS=$ENABLE_POST_IDS" >> params.sh
# root permissions
chmod -f g+w .
chmod -f g+s .
# setup state files
if [ ! -e threads ]
then
echo 0 > threads
fi
if [ ! -e posts ]
then
echo 0 > posts
fi
touch tripcodes
touch postids
chmod -f g+w threads posts tripcodes postids
# setup data directory
if [ ! -e "$DATA_DIR" ]
then
mkdir "$DATA_DIR"
fi
if [ "$DELETE_TIME" -gt 0 ]
then
touch "$DATA_DIR/postpass"
fi
if [ "$POST_LIMIT" -gt 0 ]
then
touch "$DATA_DIR/postcooldown"
touch "$DATA_DIR/threadcooldown"
fi
chmod -Rf g+w "$DATA_DIR"
chmod -f g+s "$DATA_DIR"
# setup salt directory
mkdir -p "$SALT_DIR"
chmod -Rf g+w "$SALT_DIR"
chmod -f g+s "$SALT_DIR"
# thread permissions
chmod -f g+w template_*
chmod -f g+s [0-9]*
chmod -f g+w [0-9]*
chmod -f g+s sticky_[0-9]*
chmod -f g+w sticky_[0-9]*
# fix thread links
for thread in $(ls -dtr [0-9]* 2>/dev/null)
do
rm -f $thread/gophermap
if [ -e $thread/post ]
then
rm -f $thread/post
rm -f $thread/postlink
rm -f $thread/postfile
rm -f $thread/postsplr
rm -f $thread/postfileb64
rm -f $thread/postb64
ln template_post $thread/post
ln template_postlink $thread/postlink
ln template_postfile $thread/postfile
ln template_postsplr $thread/postsplr
ln template_postfileb64 $thread/postfileb64
ln template_postb64 $thread/postb64
ln template_gophermap $thread/gophermap
else
ln template_readonly_gophermap $thread/gophermap
fi
rm -f $thread/postcache
sh updatepostcache.sh $thread > $thread/postcache
touch $thread
done
for thread in $(ls -dtr sticky_* 2>/dev/null)
do
rm -f $thread/gophermap
if [ -e $thread/post ]
then
rm -f $thread/post
rm -f $thread/postlink
rm -f $thread/postfile
rm -f $thread/postsplr
rm -f $thread/postfileb64
rm -f $thread/postb64
ln template_post $thread/post
ln template_postlink $thread/postlink
ln template_postfile $thread/postfile
ln template_postsplr $thread/postsplr
ln template_postfileb64 $thread/postfileb64
ln template_postb64 $thread/postb64
ln template_gophermap $thread/gophermap
else
ln template_readonly_gophermap $thread/gophermap
fi
rm -f $thread/postcache
sh updatepostcache.sh $thread > $thread/postcache
touch $thread
done
sh updatethreadcache.sh > threadcache
if [ "$MAX_RSS_ITEMS" -gt 0 ]
then
sh initrss.sh
fi
# postcache permissions
chmod -f g+w [0-9]*/postcache
chmod -f g+w sticky_[0-9]*/postcache
chmod -f g+w threadcache
chmod -f g+w rss.xml