瀏覽代碼

Desktop icon for blog functions

Bob Mottram 8 年之前
父節點
當前提交
09ef52055b
沒有帳戶連結到提交者的電子郵件
共有 5 個檔案被更改,包括 225 行新增1 行删除
  1. 二進制
      img/avatars/blog.jpg
  2. 13
    0
      src/freedombone-image-customise
  3. 6
    0
      src/freedombone-image-mesh
  4. 202
    0
      src/freedombone-mesh-blog
  5. 4
    1
      src/freedombone-mesh-visit-site

二進制
img/avatars/blog.jpg 查看文件


+ 13
- 0
src/freedombone-image-customise 查看文件

@@ -789,6 +789,16 @@ if [ \$no_of_users -gt 0 ]; then
789 789
         echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop
790 790
         chmod +x /home/$MY_USERNAME/Desktop/sites.desktop
791 791
         chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop
792
+
793
+        echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/blog.desktop
794
+        echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/blog.desktop
795
+        echo "Name=Blog" >> /home/$MY_USERNAME/Desktop/blog.desktop
796
+        echo 'Comment=View or create blog entries' >> /home/$MY_USERNAME/Desktop/blog.desktop
797
+        echo 'Exec=mate-terminal -e /usr/local/bin/freedombone-mesh-blog' >> /home/$MY_USERNAME/Desktop/blog.desktop
798
+        echo 'Icon=/usr/share/freedombone/avatars/blog.jpg' >> /home/$MY_USERNAME/Desktop/blog.desktop
799
+        echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/blog.desktop
800
+        chmod +x /home/$MY_USERNAME/Desktop/blog.desktop
801
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/blog.desktop
792 802
     fi
793 803
 
794 804
     if [ ! -f /home/$MY_USERNAME/runtox ]; then
@@ -820,6 +830,9 @@ else
820 830
         if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then
821 831
             rm /home/$MY_USERNAME/Desktop/sites.desktop
822 832
         fi
833
+        if [ -f /home/$MY_USERNAME/Desktop/blog.desktop ]; then
834
+            rm /home/$MY_USERNAME/Desktop/blog.desktop
835
+        fi
823 836
         if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
824 837
             rm /home/$MY_USERNAME/Desktop/tox.desktop
825 838
         fi

+ 6
- 0
src/freedombone-image-mesh 查看文件

@@ -80,6 +80,8 @@ ENABLE_ZERONET=
80 80
 
81 81
 IPFS_PORT=4001
82 82
 
83
+CURRENT_BLOG_INDEX=/home/$MY_USERNAME/.blog-index
84
+
83 85
 function create_avahi_mesh_service {
84 86
     service_name=$1
85 87
     service_type=$2
@@ -756,6 +758,10 @@ function setup_ipfs {
756 758
     su -c "systemctl --user enable ipfs" - $MY_USERNAME
757 759
     su -c "systemctl --user start ipfs" - $MY_USERNAME
758 760
 
761
+    if [ -f $CURRENT_BLOG_INDEX ]; then
762
+        shred -zu $CURRENT_BLOG_INDEX
763
+    fi
764
+
759 765
     if [ -d /home/$MY_USERNAME/Public ]; then
760 766
         rm /home/$MY_USERNAME/Desktop/Public
761 767
         rm -rf /home/$MY_USERNAME/Public

+ 202
- 0
src/freedombone-mesh-blog 查看文件

@@ -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

+ 4
- 1
src/freedombone-mesh-visit-site 查看文件

@@ -36,6 +36,9 @@ IPFS_URL='http://127.0.0.1:8080/ipns'
36 36
 # The browser application to use
37 37
 BROWSER=midori
38 38
 
39
+# An optional suffix to be appended to the URL
40
+SUFFIX=$1
41
+
39 42
 IPFS_USERS_FILE=/home/$USER/.ipfs-users
40 43
 if [ ! -f $IPFS_USERS_FILE ]; then
41 44
     exit 0
@@ -71,7 +74,7 @@ case $sel in
71 74
                 IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
72 75
                 clear
73 76
                 echo $'Opening browser. Please wait...'
74
-                $BROWSER $IPFS_FULL_URL &
77
+                $BROWSER $IPFS_FULL_URL$SUFFIX &
75 78
             fi
76 79
         else
77 80
             exit 1