|
@@ -0,0 +1,202 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# Blogging functions for mesh clients
|
|
12
|
+#
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# This program is free software: you can redistribute it and/or modify
|
|
17
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
18
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
19
|
+# (at your option) any later version.
|
|
20
|
+#
|
|
21
|
+# This program is distributed in the hope that it will be useful,
|
|
22
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24
|
+# GNU Affero General Public License for more details.
|
|
25
|
+#
|
|
26
|
+# You should have received a copy of the GNU Affero General Public License
|
|
27
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
28
|
+
|
|
29
|
+PROJECT_NAME='freedombone'
|
|
30
|
+
|
|
31
|
+export TEXTDOMAIN=${PROJECT_NAME}-mesh-blog
|
|
32
|
+export TEXTDOMAINDIR="/usr/share/locale"
|
|
33
|
+
|
|
34
|
+BLOG_PATH=~/CreateBlog
|
|
35
|
+BLOG_CONTENT_PATH=$BLOG_PATH/content
|
|
36
|
+CURRENT_BLOG_INDEX=/home/$USER/.blog-index
|
|
37
|
+BLOG_EDITOR='pluma'
|
|
38
|
+
|
|
39
|
+function regenerate_blog {
|
|
40
|
+ OLD_STAT_FILE=/home/$USER/.old_stat.txt
|
|
41
|
+ if [ -f $OLD_STAT_FILE ]; then
|
|
42
|
+ rm $OLD_STAT_FILE
|
|
43
|
+ fi
|
|
44
|
+
|
|
45
|
+ cd $BLOG_PATH
|
|
46
|
+ make html
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+function view_blog {
|
|
50
|
+ freedombone-mesh-visit-site '/Blog'
|
|
51
|
+ exit 0
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+function new_blog {
|
|
55
|
+ echo $'Blog Post Title' > ~/.new-blog-entry
|
|
56
|
+ echo $'###############' >> ~/.new-blog-entry
|
|
57
|
+ echo '' >> ~/.new-blog-entry
|
|
58
|
+ echo $':date: 2020-01-01' >> ~/.new-blog-entry
|
|
59
|
+ echo $":author: $(toxid --showuser)" >> ~/.new-blog-entry
|
|
60
|
+ echo $':category: default' >> ~/.new-blog-entry
|
|
61
|
+ echo $':tags: blog, tag' >> ~/.new-blog-entry
|
|
62
|
+ echo '' >> ~/.new-blog-entry
|
|
63
|
+ echo $'Add your text here' >> ~/.new-blog-entry
|
|
64
|
+ echo '' >> ~/.new-blog-entry
|
|
65
|
+
|
|
66
|
+ $BLOG_EDITOR ~/.new-blog-entry
|
|
67
|
+
|
|
68
|
+ if grep -q $"Add your text here" ~/.new-blog-entry; then
|
|
69
|
+ return
|
|
70
|
+ fi
|
|
71
|
+ if grep -q $"Blog Post Title" ~/.new-blog-entry; then
|
|
72
|
+ return
|
|
73
|
+ fi
|
|
74
|
+ if [ ! -f $CURRENT_BLOG_INDEX ]; then
|
|
75
|
+ echo '0' > $CURRENT_BLOG_INDEX
|
|
76
|
+ fi
|
|
77
|
+
|
|
78
|
+ # move to the content directory
|
|
79
|
+ CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
|
|
80
|
+ mv ~/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst
|
|
81
|
+
|
|
82
|
+ # increment the index
|
|
83
|
+ CURRENT_INDEX=$((CURRENT_INDEX + 1))
|
|
84
|
+ echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
|
|
85
|
+
|
|
86
|
+ regenerate_blog
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+function edit_blog {
|
|
90
|
+ if [ ! -f $CURRENT_BLOG_INDEX ]; then
|
|
91
|
+ return
|
|
92
|
+ fi
|
|
93
|
+ CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
|
|
94
|
+ LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst
|
|
95
|
+ if [ ! -f $LAST_BLOG_ENTRY ]; then
|
|
96
|
+ return
|
|
97
|
+ fi
|
|
98
|
+ $BLOG_EDITOR $LAST_BLOG_ENTRY
|
|
99
|
+ regenerate_blog
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+function delete_blog {
|
|
103
|
+ if [ ! -f $CURRENT_BLOG_INDEX ]; then
|
|
104
|
+ return
|
|
105
|
+ fi
|
|
106
|
+ CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
|
|
107
|
+ LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst
|
|
108
|
+ if [ ! -f $LAST_BLOG_ENTRY ]; then
|
|
109
|
+ return
|
|
110
|
+ fi
|
|
111
|
+
|
|
112
|
+ dialog --title $"Delete the previous blog entry" \
|
|
113
|
+ --backtitle $"Freedombone Mesh" \
|
|
114
|
+ --defaultno \
|
|
115
|
+ --yesno $"\nAre you sure that you wish to delete the previous blog entry?" 8 60
|
|
116
|
+ sel=$?
|
|
117
|
+ case $sel in
|
|
118
|
+ 0) rm $LAST_BLOG_ENTRY
|
|
119
|
+ if [ $CURRENT_INDEX -gt 0 ]; then
|
|
120
|
+ CURRENT_INDEX=$((CURRENT_INDEX - 1))
|
|
121
|
+ echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
|
|
122
|
+ fi
|
|
123
|
+ regenerate_blog
|
|
124
|
+ ;;
|
|
125
|
+ esac
|
|
126
|
+}
|
|
127
|
+
|
|
128
|
+function change_theme {
|
|
129
|
+ THEMES=()
|
|
130
|
+ for d in $BLOG_PATH/themes/*/ ; do
|
|
131
|
+ THEME_NAME=$(echo "$d" | awk -F '/' '{print $5}')
|
|
132
|
+ THEMES+=("$THEME_NAME")
|
|
133
|
+ done
|
|
134
|
+
|
|
135
|
+ themelist=""
|
|
136
|
+ n=1
|
|
137
|
+ theme_index=0
|
|
138
|
+ for a in "${THEMES[@]}"
|
|
139
|
+ do
|
|
140
|
+ if [[ $a == "basic" ]]; then
|
|
141
|
+ themelist="$applist $n $a on"
|
|
142
|
+ else
|
|
143
|
+ themelist="$applist $n $a off"
|
|
144
|
+ fi
|
|
145
|
+ n=$[n+1]
|
|
146
|
+ theme_index=$[theme_index+1]
|
|
147
|
+ done
|
|
148
|
+
|
|
149
|
+ data=$(tempfile 2>/dev/null)
|
|
150
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
151
|
+ dialog --stdout --backtitle $"Freedombone Mesh" \
|
|
152
|
+ --title $"Select Blog Theme" \
|
|
153
|
+ --radiolist $'Choose:' \
|
|
154
|
+ 80 40 20 $themelist 2> $data
|
|
155
|
+
|
|
156
|
+ sel=$?
|
|
157
|
+ case $sel in
|
|
158
|
+ 1) exit 1;;
|
|
159
|
+ 255) exit 1;;
|
|
160
|
+ esac
|
|
161
|
+ CHOSEN_THEME_INDEX=$(cat $data)
|
|
162
|
+ CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
|
|
163
|
+
|
|
164
|
+ CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
|
|
165
|
+ if grep -q "THEME=" $BLOG_PATH/pelicanconf.py; then
|
|
166
|
+ sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g"
|
|
167
|
+ else
|
|
168
|
+ echo "THEME='themes/${CHOSEN_THEME}'" >> $BLOG_PATH/pelicanconf.py
|
|
169
|
+ fi
|
|
170
|
+ regenerate_blog
|
|
171
|
+}
|
|
172
|
+
|
|
173
|
+function menu_blog {
|
|
174
|
+ data=$(tempfile 2>/dev/null)
|
|
175
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
176
|
+ dialog --backtitle $"Freedombone Mesh" \
|
|
177
|
+ --title $"Blogging" \
|
|
178
|
+ --radiolist $"Choose an operation:" 19 50 12 \
|
|
179
|
+ 1 $"View a blog" on \
|
|
180
|
+ 2 $"New blog entry" off \
|
|
181
|
+ 3 $"Edit the previous blog entry" off \
|
|
182
|
+ 4 $"Delete the previous blog entry" off \
|
|
183
|
+ 5 $"Change theme" off \
|
|
184
|
+ 6 $"Exit" off 2> $data
|
|
185
|
+ sel=$?
|
|
186
|
+ case $sel in
|
|
187
|
+ 1) exit 1;;
|
|
188
|
+ 255) exit 1;;
|
|
189
|
+ esac
|
|
190
|
+ case $(cat $data) in
|
|
191
|
+ 1) view_blog;;
|
|
192
|
+ 2) new_blog;;
|
|
193
|
+ 3) edit_blog;;
|
|
194
|
+ 4) delete_blog;;
|
|
195
|
+ 6) change_theme;;
|
|
196
|
+ 7) break;;
|
|
197
|
+ esac
|
|
198
|
+}
|
|
199
|
+
|
|
200
|
+menu_blog
|
|
201
|
+
|
|
202
|
+exit 0
|