|
@@ -0,0 +1,395 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# _____ _ _
|
|
4
|
+# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
|
|
5
|
+# | __| _| -_| -_| . | . | | . | . | | -_|
|
|
6
|
+# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
|
|
7
|
+#
|
|
8
|
+# Freedom in the Cloud
|
|
9
|
+#
|
|
10
|
+# License
|
|
11
|
+# =======
|
|
12
|
+#
|
|
13
|
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
|
|
14
|
+#
|
|
15
|
+# This program is free software: you can redistribute it and/or modify
|
|
16
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
17
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
18
|
+# (at your option) any later version.
|
|
19
|
+#
|
|
20
|
+# This program is distributed in the hope that it will be useful,
|
|
21
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+# GNU Affero General Public License for more details.
|
|
24
|
+#
|
|
25
|
+# You should have received a copy of the GNU Affero General Public License
|
|
26
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
27
|
+
|
|
28
|
+VARIANTS='full full-vim'
|
|
29
|
+
|
|
30
|
+IN_DEFAULT_INSTALL=0
|
|
31
|
+SHOW_ON_ABOUT=1
|
|
32
|
+SHOW_ICANN_ADDRESS_ON_ABOUT=0
|
|
33
|
+
|
|
34
|
+SMOLRSS_DOMAIN_NAME=
|
|
35
|
+SMOLRSS_CODE=
|
|
36
|
+SMOLRSS_ONION_PORT=9051
|
|
37
|
+SMOLRSS_REPO="https://github.com/bashrc/smolrss"
|
|
38
|
+SMOLRSS_COMMIT='afa7135651ef87073e366b8ed183917e245ccc0e'
|
|
39
|
+
|
|
40
|
+smolrss_variables=(ONION_ONLY
|
|
41
|
+ SMOLRSS_DOMAIN_NAME
|
|
42
|
+ SMOLRSS_CODE
|
|
43
|
+ DDNS_PROVIDER
|
|
44
|
+ MY_USERNAME)
|
|
45
|
+
|
|
46
|
+function logging_on_smolrss {
|
|
47
|
+ echo -n ''
|
|
48
|
+}
|
|
49
|
+
|
|
50
|
+function logging_off_smolrss {
|
|
51
|
+ echo -n ''
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+function remove_user_smolrss {
|
|
55
|
+ #remove_username="$1"
|
|
56
|
+ echo -n ''
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+function add_user_smolrss {
|
|
60
|
+ #new_username="$1"
|
|
61
|
+ #new_user_password="$2"
|
|
62
|
+
|
|
63
|
+ echo '0'
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+function install_interactive_smolrss {
|
|
67
|
+ echo -n ''
|
|
68
|
+ APP_INSTALLED=1
|
|
69
|
+}
|
|
70
|
+
|
|
71
|
+function change_password_smolrss {
|
|
72
|
+ #curr_username="$1"
|
|
73
|
+ #new_user_password="$2"
|
|
74
|
+ echo -n ''
|
|
75
|
+}
|
|
76
|
+
|
|
77
|
+function reconfigure_smolrss {
|
|
78
|
+ # This is used if you need to switch identity. Dump old keys and generate new ones
|
|
79
|
+ echo -n ''
|
|
80
|
+}
|
|
81
|
+
|
|
82
|
+function smolrss_add_feed {
|
|
83
|
+ data=$(mktemp 2>/dev/null)
|
|
84
|
+ dialog --backtitle $"Smol RSS" \
|
|
85
|
+ --title $"Add an RSS feed" \
|
|
86
|
+ --form "\\n" 8 60 3 \
|
|
87
|
+ $"Title:" 1 1 "" 1 12 40 256 \
|
|
88
|
+ $"Feed URL:" 2 1 "" 2 12 40 10000 \
|
|
89
|
+ 2> "$data"
|
|
90
|
+ sel=$?
|
|
91
|
+ case $sel in
|
|
92
|
+ 1) rm -f "$data"
|
|
93
|
+ return;;
|
|
94
|
+ 255) rm -f "$data"
|
|
95
|
+ return;;
|
|
96
|
+ esac
|
|
97
|
+ title=$(sed -n 1p < "$data")
|
|
98
|
+ url=$(sed -n 2p < "$data")
|
|
99
|
+ rm -f "$data"
|
|
100
|
+
|
|
101
|
+ if [ ! "$title" ]; then
|
|
102
|
+ return
|
|
103
|
+ fi
|
|
104
|
+
|
|
105
|
+ if [ ! "$url" ]; then
|
|
106
|
+ return
|
|
107
|
+ fi
|
|
108
|
+
|
|
109
|
+ if [[ "$url" == *','* ]]; then
|
|
110
|
+ return
|
|
111
|
+ fi
|
|
112
|
+ if [[ "$url" != *'.'* ]]; then
|
|
113
|
+ return
|
|
114
|
+ fi
|
|
115
|
+
|
|
116
|
+ cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || return
|
|
117
|
+
|
|
118
|
+ if grep -q "${title}," feeds.txt; then
|
|
119
|
+ sed -i "s|${title},.*|${title},${url}|g" feeds.txt
|
|
120
|
+ else
|
|
121
|
+ echo "${title},${url}" >> feeds.txt
|
|
122
|
+ fi
|
|
123
|
+
|
|
124
|
+ ./create_feeds feeds.txt > feeds.xml
|
|
125
|
+ chown www-data:www-data feeds.txt
|
|
126
|
+
|
|
127
|
+ dialog --title $"Add an RSS feed" \
|
|
128
|
+ --msgbox $"${title} has been added" 6 70
|
|
129
|
+}
|
|
130
|
+
|
|
131
|
+function smolrss_remove_feed {
|
|
132
|
+ data=$(mktemp 2>/dev/null)
|
|
133
|
+ dialog --title $"Remove an RSS feed" \
|
|
134
|
+ --backtitle $"Smol RSS" \
|
|
135
|
+ --inputbox $"Enter the title of the feed to remove" 8 60 2>"$data"
|
|
136
|
+ sel=$?
|
|
137
|
+ case $sel in
|
|
138
|
+ 0)
|
|
139
|
+ title=$(<"$data")
|
|
140
|
+ if [ "$title" ]; then
|
|
141
|
+ cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || return
|
|
142
|
+ if grep -q "${title}," feeds.txt; then
|
|
143
|
+ sed -i "/${title},/d" feeds.xml
|
|
144
|
+ ./create_feeds feeds.txt > feeds.xml
|
|
145
|
+ chown www-data:www-data feeds.txt
|
|
146
|
+ dialog --title $"Remove an RSS feed" \
|
|
147
|
+ --msgbox $"${title} has been removed" 6 70
|
|
148
|
+ fi
|
|
149
|
+ fi
|
|
150
|
+ ;;
|
|
151
|
+ esac
|
|
152
|
+ rm -f "$data"
|
|
153
|
+}
|
|
154
|
+
|
|
155
|
+function configure_interactive_smolrss {
|
|
156
|
+ W=(1 $"Add an RSS feed"
|
|
157
|
+ 2 $"Remove an RSS feed"
|
|
158
|
+ 3 $'Edit all feeds')
|
|
159
|
+
|
|
160
|
+ read_config_param SMOLRSS_DOMAIN_NAME
|
|
161
|
+
|
|
162
|
+ while true
|
|
163
|
+ do
|
|
164
|
+ # shellcheck disable=SC2068
|
|
165
|
+ selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Smol RSS" --menu $"Choose an operation, or ESC for main menu:" 14 70 3 "${W[@]}" 3>&2 2>&1 1>&3)
|
|
166
|
+
|
|
167
|
+ if [ ! "$selection" ]; then
|
|
168
|
+ break
|
|
169
|
+ fi
|
|
170
|
+ case $selection in
|
|
171
|
+ 1) smolrss_add_feed
|
|
172
|
+ ;;
|
|
173
|
+ 2) smolrss_remove_feed
|
|
174
|
+ ;;
|
|
175
|
+ 3) editor "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs/feeds.txt"
|
|
176
|
+ cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || break
|
|
177
|
+ ./create_feeds feeds.txt > feeds.xml
|
|
178
|
+ chown www-data:www-data feeds.txt
|
|
179
|
+ ;;
|
|
180
|
+ esac
|
|
181
|
+ done
|
|
182
|
+}
|
|
183
|
+
|
|
184
|
+function upgrade_smolrss {
|
|
185
|
+ CURR_SMOLRSS_COMMIT=$(get_completion_param "smolrss commit")
|
|
186
|
+ if [[ "$CURR_SMOLRSS_COMMIT" == "$SMOLRSS_COMMIT" ]]; then
|
|
187
|
+ return
|
|
188
|
+ fi
|
|
189
|
+
|
|
190
|
+ if grep -q "smolrss domain" "$COMPLETION_FILE"; then
|
|
191
|
+ SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain")
|
|
192
|
+ fi
|
|
193
|
+
|
|
194
|
+ # update to the next commit
|
|
195
|
+ set_repo_commit "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" "smolrss commit" "$SMOLRSS_COMMIT" "$SMOLRSS_REPO"
|
|
196
|
+ chown -R www-data:www-data "/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs"
|
|
197
|
+}
|
|
198
|
+
|
|
199
|
+function backup_local_smolrss {
|
|
200
|
+ SMOLRSS_DOMAIN_NAME='smolrss'
|
|
201
|
+ if grep -q "smolrss domain" "$COMPLETION_FILE"; then
|
|
202
|
+ SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain")
|
|
203
|
+ fi
|
|
204
|
+
|
|
205
|
+ source_directory=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs
|
|
206
|
+
|
|
207
|
+ suspend_site "${SMOLRSS_DOMAIN_NAME}"
|
|
208
|
+
|
|
209
|
+ dest_directory=smolrss
|
|
210
|
+ backup_directory_to_usb "$source_directory" $dest_directory
|
|
211
|
+
|
|
212
|
+ restart_site
|
|
213
|
+}
|
|
214
|
+
|
|
215
|
+function restore_local_smolrss {
|
|
216
|
+ if ! grep -q "smolrss domain" "$COMPLETION_FILE"; then
|
|
217
|
+ return
|
|
218
|
+ fi
|
|
219
|
+ SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain")
|
|
220
|
+ if [ ! "$SMOLRSS_DOMAIN_NAME" ]; then
|
|
221
|
+ return
|
|
222
|
+ fi
|
|
223
|
+ suspend_site "${SMOLRSS_DOMAIN_NAME}"
|
|
224
|
+ temp_restore_dir=/root/tempsmolrss
|
|
225
|
+ smolrss_dir=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs
|
|
226
|
+
|
|
227
|
+ restore_directory_from_usb $temp_restore_dir smolrss
|
|
228
|
+ if [ -d $temp_restore_dir ]; then
|
|
229
|
+ if [ -d "$temp_restore_dir$smolrss_dir" ]; then
|
|
230
|
+ cp -rp "$temp_restore_dir$smolrss_dir"/* "$smolrss_dir"/
|
|
231
|
+ else
|
|
232
|
+ if [ ! -d "$smolrss_dir" ]; then
|
|
233
|
+ mkdir "$smolrss_dir"
|
|
234
|
+ fi
|
|
235
|
+ cp -rp "$temp_restore_dir"/* "$smolrss_dir"/
|
|
236
|
+ fi
|
|
237
|
+ chown -R www-data:www-data "$smolrss_dir"
|
|
238
|
+ rm -rf $temp_restore_dir
|
|
239
|
+ fi
|
|
240
|
+ restart_site
|
|
241
|
+}
|
|
242
|
+
|
|
243
|
+function backup_remote_smolrss {
|
|
244
|
+ SMOLRSS_DOMAIN_NAME='smolrss'
|
|
245
|
+ if grep -q "smolrss domain" "$COMPLETION_FILE"; then
|
|
246
|
+ SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain")
|
|
247
|
+ fi
|
|
248
|
+
|
|
249
|
+ source_directory=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs
|
|
250
|
+
|
|
251
|
+ suspend_site "${SMOLRSS_DOMAIN_NAME}"
|
|
252
|
+
|
|
253
|
+ dest_directory=smolrss
|
|
254
|
+ backup_directory_to_friend "$source_directory" $dest_directory
|
|
255
|
+
|
|
256
|
+ restart_site
|
|
257
|
+}
|
|
258
|
+
|
|
259
|
+function restore_remote_smolrss {
|
|
260
|
+ if ! grep -q "smolrss domain" "$COMPLETION_FILE"; then
|
|
261
|
+ return
|
|
262
|
+ fi
|
|
263
|
+ SMOLRSS_DOMAIN_NAME=$(get_completion_param "smolrss domain")
|
|
264
|
+ if [ ! "$SMOLRSS_DOMAIN_NAME" ]; then
|
|
265
|
+ return
|
|
266
|
+ fi
|
|
267
|
+ suspend_site "${SMOLRSS_DOMAIN_NAME}"
|
|
268
|
+ temp_restore_dir=/root/tempsmolrss
|
|
269
|
+ smolrss_dir=/var/www/${SMOLRSS_DOMAIN_NAME}/htdocs
|
|
270
|
+
|
|
271
|
+ restore_directory_from_friend $temp_restore_dir smolrss
|
|
272
|
+ if [ -d $temp_restore_dir ]; then
|
|
273
|
+ if [ -d "$temp_restore_dir$smolrss_dir" ]; then
|
|
274
|
+ cp -rp "$temp_restore_dir$smolrss_dir"/* "$smolrss_dir"/
|
|
275
|
+ else
|
|
276
|
+ if [ ! -d "$smolrss_dir" ]; then
|
|
277
|
+ mkdir "$smolrss_dir"
|
|
278
|
+ fi
|
|
279
|
+ cp -rp $temp_restore_dir/* "$smolrss_dir"/
|
|
280
|
+ fi
|
|
281
|
+ chown -R www-data:www-data "$smolrss_dir"
|
|
282
|
+ rm -rf $temp_restore_dir
|
|
283
|
+ fi
|
|
284
|
+ restart_site
|
|
285
|
+}
|
|
286
|
+
|
|
287
|
+function remove_smolrss {
|
|
288
|
+ nginx_dissite "$SMOLRSS_DOMAIN_NAME"
|
|
289
|
+ remove_certs "$SMOLRSS_DOMAIN_NAME"
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+ if [ -d "/var/www/$SMOLRSS_DOMAIN_NAME" ]; then
|
|
293
|
+ rm -rf "/var/www/$SMOLRSS_DOMAIN_NAME"
|
|
294
|
+ fi
|
|
295
|
+ if [ -f "/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME" ]; then
|
|
296
|
+ rm "/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME"
|
|
297
|
+ fi
|
|
298
|
+ remove_onion_service smolrss "${SMOLRSS_ONION_PORT}"
|
|
299
|
+ if grep -q "smolrss" /etc/crontab; then
|
|
300
|
+ sed -i "/smolrss/d" /etc/crontab
|
|
301
|
+ fi
|
|
302
|
+ remove_app smolrss
|
|
303
|
+ remove_completion_param install_smolrss
|
|
304
|
+ sed -i '/smolrss/d' "$COMPLETION_FILE"
|
|
305
|
+
|
|
306
|
+ remove_ddns_domain "$SMOLRSS_DOMAIN_NAME"
|
|
307
|
+}
|
|
308
|
+
|
|
309
|
+function install_smolrss {
|
|
310
|
+ apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
|
|
311
|
+ apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
|
|
312
|
+
|
|
313
|
+ if [ ! "$SMOLRSS_DOMAIN_NAME" ]; then
|
|
314
|
+ echo $'No domain name was given'
|
|
315
|
+ exit 3568356
|
|
316
|
+ fi
|
|
317
|
+
|
|
318
|
+ if [ -d "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" ]; then
|
|
319
|
+ rm -rf "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
320
|
+ fi
|
|
321
|
+ if [ -d /repos/smolrss ]; then
|
|
322
|
+ mkdir "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
323
|
+ cp -r -p /repos/smolrss/. "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
324
|
+ cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || exit 324687356
|
|
325
|
+ git pull
|
|
326
|
+ else
|
|
327
|
+ git_clone "$SMOLRSS_REPO" "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
328
|
+ fi
|
|
329
|
+
|
|
330
|
+ if [ ! -d "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" ]; then
|
|
331
|
+ echo $'Unable to clone smolrss repo'
|
|
332
|
+ exit 87525
|
|
333
|
+ fi
|
|
334
|
+
|
|
335
|
+ cd "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs" || exit 36587356
|
|
336
|
+ git checkout "$SMOLRSS_COMMIT" -b "$SMOLRSS_COMMIT"
|
|
337
|
+ set_completion_param "smolrss commit" "$SMOLRSS_COMMIT"
|
|
338
|
+
|
|
339
|
+ cp feeds.example.txt feeds.txt
|
|
340
|
+ ./create_feeds feeds.txt > feeds.xml
|
|
341
|
+
|
|
342
|
+ chmod g+w "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
343
|
+ chown -R www-data:www-data "/var/www/$SMOLRSS_DOMAIN_NAME/htdocs"
|
|
344
|
+
|
|
345
|
+ add_ddns_domain "$SMOLRSS_DOMAIN_NAME"
|
|
346
|
+
|
|
347
|
+ SMOLRSS_ONION_HOSTNAME=$(add_onion_service smolrss 80 "${SMOLRSS_ONION_PORT}")
|
|
348
|
+
|
|
349
|
+ smolrss_nginx_site=/etc/nginx/sites-available/$SMOLRSS_DOMAIN_NAME
|
|
350
|
+ echo -n '' > "$smolrss_nginx_site"
|
|
351
|
+ { echo 'server {';
|
|
352
|
+ echo " listen 127.0.0.1:$SMOLRSS_ONION_PORT default_server;";
|
|
353
|
+ echo " server_name $SMOLRSS_ONION_HOSTNAME;";
|
|
354
|
+ echo ''; } >> "$smolrss_nginx_site"
|
|
355
|
+ nginx_compress "$SMOLRSS_DOMAIN_NAME"
|
|
356
|
+ echo '' >> "$smolrss_nginx_site"
|
|
357
|
+ nginx_security_options "$SMOLRSS_DOMAIN_NAME"
|
|
358
|
+ { echo '';
|
|
359
|
+ echo ' access_log /dev/null;';
|
|
360
|
+ echo ' error_log /dev/null;';
|
|
361
|
+ echo '';
|
|
362
|
+ echo " root /var/www/$SMOLRSS_DOMAIN_NAME/htdocs;";
|
|
363
|
+ echo '';
|
|
364
|
+ echo ' index index.php;';
|
|
365
|
+ echo ' location ~ \.php {';
|
|
366
|
+ echo ' include snippets/fastcgi-php.conf;';
|
|
367
|
+ echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
|
|
368
|
+ echo ' fastcgi_read_timeout 30;';
|
|
369
|
+ echo ' fastcgi_param HTTPS off;';
|
|
370
|
+ echo ' }';
|
|
371
|
+ echo '';
|
|
372
|
+ echo ' # Location';
|
|
373
|
+ echo ' location / {'; } >> "$smolrss_nginx_site"
|
|
374
|
+ nginx_limits "$SMOLRSS_DOMAIN_NAME" '15m'
|
|
375
|
+ { echo " try_files \$uri \$uri/ index.php?\$args;";
|
|
376
|
+ echo ' }';
|
|
377
|
+ echo '}'; } >> "$smolrss_nginx_site"
|
|
378
|
+
|
|
379
|
+ configure_php
|
|
380
|
+
|
|
381
|
+ create_site_certificate "$SMOLRSS_DOMAIN_NAME" 'yes'
|
|
382
|
+
|
|
383
|
+ nginx_ensite "$SMOLRSS_DOMAIN_NAME"
|
|
384
|
+
|
|
385
|
+ systemctl restart php7.0-fpm
|
|
386
|
+
|
|
387
|
+ systemctl restart nginx
|
|
388
|
+
|
|
389
|
+ "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a smolrss -p "$SMOLRSS_ADMIN_PASSWORD"
|
|
390
|
+ set_completion_param "smolrss domain" "$SMOLRSS_DOMAIN_NAME"
|
|
391
|
+
|
|
392
|
+ APP_INSTALLED=1
|
|
393
|
+}
|
|
394
|
+
|
|
395
|
+# NOTE: deliberately there is no "exit 0"
|