From 09ef52055b381c93611cc1898fb35f92e46c11ff Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 8 Sep 2016 20:45:04 +0100 Subject: [PATCH] Desktop icon for blog functions --- img/avatars/blog.jpg | Bin 0 -> 2232 bytes src/freedombone-image-customise | 13 ++ src/freedombone-image-mesh | 6 + src/freedombone-mesh-blog | 202 ++++++++++++++++++++++++++++++++ src/freedombone-mesh-visit-site | 5 +- 5 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 img/avatars/blog.jpg create mode 100755 src/freedombone-mesh-blog diff --git a/img/avatars/blog.jpg b/img/avatars/blog.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4a376f52757c4fb617c4b5ddcafcda1415239586 GIT binary patch literal 2232 zcmb7^dpuNmAIE=ZW{k-Wof%@#j2V}~wvT3zoy^XfL8M$GQCeXrm+T6q+^N{2wC*95 zTq@-Dibl1_Hd3^1X<}U(Nk|D<%`(qnpQr8l^ZA~C&g*>7`F(z$&v}1;(&y3<0PnD} zu>ueTf$hizqyxYLz+d4N@N%$%yaJH`E0XlpNy^G3Lv1=mpKbg-$JBT$i)ZtLBX66# z6>ICRAD!L3`2GR@W)7i|NBmCwaM0g(brFa_B$76e80zW_UyH34zW;YgTL1wE;y@f4 zA^;QtLK7fqD^LXhg@(YF1)RpJ5^fciq3FZw_3(l=!vue_T9%%Nmi-X&K4)UC~yx5%8kJyjqMgVN!WbjD|I zmwzmD4_lZM01SlN&A^RS1}&=@b-(>-V)17#NFeOC&1qq!7Z;WcnfBG^9do}7IpJE} z_S%=|jo8mT?%@XyJTCbVhrtrH&+ZIpX&4PH$-ie5(mmV}fPz)ewD&3QJbOmvLZ{%v z&``~rz(g+Bm0Ny20M*;g-)lHr{Mhx5btMF@6OuP%R5*Rzy)o=V|FI}*k5+RsRY_CE zcaw{or+!vrSSROwLL30dqfM4}z8#`rybB%)1%*mysJ~ggvj7`uz>xugRt88&TaA?l zBe5cHpg-pap#YjdWWb6T8k5RJLc}30NCrh^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U-o(=xa(_pNM*u_2 zAuijJcM3G0r;LXUU^7Bb#lnmu)4UrqZCQ5b@yG48*7eq3^(;$$QAC4Wm(03!uY&QO0oSP+qU4F4H$lVD;yoo^r>QR87ZJE=xEsqd^@7qDRbYhOHC_jL3`O= xM}Pd4kSde#vLs2=FKm7gl5P6hIkdq%fDrn1b*|EzF>$EV#h2pwTK=F^^ly_BcqRY< literal 0 HcmV?d00001 diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise index 26ed0752..041427a1 100755 --- a/src/freedombone-image-customise +++ b/src/freedombone-image-customise @@ -789,6 +789,16 @@ if [ \$no_of_users -gt 0 ]; then echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop chmod +x /home/$MY_USERNAME/Desktop/sites.desktop chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop + + echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/blog.desktop + echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/blog.desktop + echo "Name=Blog" >> /home/$MY_USERNAME/Desktop/blog.desktop + echo 'Comment=View or create blog entries' >> /home/$MY_USERNAME/Desktop/blog.desktop + echo 'Exec=mate-terminal -e /usr/local/bin/freedombone-mesh-blog' >> /home/$MY_USERNAME/Desktop/blog.desktop + echo 'Icon=/usr/share/freedombone/avatars/blog.jpg' >> /home/$MY_USERNAME/Desktop/blog.desktop + echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/blog.desktop + chmod +x /home/$MY_USERNAME/Desktop/blog.desktop + chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/blog.desktop fi if [ ! -f /home/$MY_USERNAME/runtox ]; then @@ -820,6 +830,9 @@ else if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then rm /home/$MY_USERNAME/Desktop/sites.desktop fi + if [ -f /home/$MY_USERNAME/Desktop/blog.desktop ]; then + rm /home/$MY_USERNAME/Desktop/blog.desktop + fi if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then rm /home/$MY_USERNAME/Desktop/tox.desktop fi diff --git a/src/freedombone-image-mesh b/src/freedombone-image-mesh index 8a18d075..0e5f734d 100755 --- a/src/freedombone-image-mesh +++ b/src/freedombone-image-mesh @@ -80,6 +80,8 @@ ENABLE_ZERONET= IPFS_PORT=4001 +CURRENT_BLOG_INDEX=/home/$MY_USERNAME/.blog-index + function create_avahi_mesh_service { service_name=$1 service_type=$2 @@ -756,6 +758,10 @@ function setup_ipfs { su -c "systemctl --user enable ipfs" - $MY_USERNAME su -c "systemctl --user start ipfs" - $MY_USERNAME + if [ -f $CURRENT_BLOG_INDEX ]; then + shred -zu $CURRENT_BLOG_INDEX + fi + if [ -d /home/$MY_USERNAME/Public ]; then rm /home/$MY_USERNAME/Desktop/Public rm -rf /home/$MY_USERNAME/Public diff --git a/src/freedombone-mesh-blog b/src/freedombone-mesh-blog new file mode 100755 index 00000000..e09c93f1 --- /dev/null +++ b/src/freedombone-mesh-blog @@ -0,0 +1,202 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# Blogging functions for mesh clients +# +# License +# ======= +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +PROJECT_NAME='freedombone' + +export TEXTDOMAIN=${PROJECT_NAME}-mesh-blog +export TEXTDOMAINDIR="/usr/share/locale" + +BLOG_PATH=~/CreateBlog +BLOG_CONTENT_PATH=$BLOG_PATH/content +CURRENT_BLOG_INDEX=/home/$USER/.blog-index +BLOG_EDITOR='pluma' + +function regenerate_blog { + OLD_STAT_FILE=/home/$USER/.old_stat.txt + if [ -f $OLD_STAT_FILE ]; then + rm $OLD_STAT_FILE + fi + + cd $BLOG_PATH + make html +} + +function view_blog { + freedombone-mesh-visit-site '/Blog' + exit 0 +} + +function new_blog { + echo $'Blog Post Title' > ~/.new-blog-entry + echo $'###############' >> ~/.new-blog-entry + echo '' >> ~/.new-blog-entry + echo $':date: 2020-01-01' >> ~/.new-blog-entry + echo $":author: $(toxid --showuser)" >> ~/.new-blog-entry + echo $':category: default' >> ~/.new-blog-entry + echo $':tags: blog, tag' >> ~/.new-blog-entry + echo '' >> ~/.new-blog-entry + echo $'Add your text here' >> ~/.new-blog-entry + echo '' >> ~/.new-blog-entry + + $BLOG_EDITOR ~/.new-blog-entry + + if grep -q $"Add your text here" ~/.new-blog-entry; then + return + fi + if grep -q $"Blog Post Title" ~/.new-blog-entry; then + return + fi + if [ ! -f $CURRENT_BLOG_INDEX ]; then + echo '0' > $CURRENT_BLOG_INDEX + fi + + # move to the content directory + CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX) + mv ~/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst + + # increment the index + CURRENT_INDEX=$((CURRENT_INDEX + 1)) + echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX + + regenerate_blog +} + +function edit_blog { + if [ ! -f $CURRENT_BLOG_INDEX ]; then + return + fi + CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX) + LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst + if [ ! -f $LAST_BLOG_ENTRY ]; then + return + fi + $BLOG_EDITOR $LAST_BLOG_ENTRY + regenerate_blog +} + +function delete_blog { + if [ ! -f $CURRENT_BLOG_INDEX ]; then + return + fi + CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX) + LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.rst + if [ ! -f $LAST_BLOG_ENTRY ]; then + return + fi + + dialog --title $"Delete the previous blog entry" \ + --backtitle $"Freedombone Mesh" \ + --defaultno \ + --yesno $"\nAre you sure that you wish to delete the previous blog entry?" 8 60 + sel=$? + case $sel in + 0) rm $LAST_BLOG_ENTRY + if [ $CURRENT_INDEX -gt 0 ]; then + CURRENT_INDEX=$((CURRENT_INDEX - 1)) + echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX + fi + regenerate_blog + ;; + esac +} + +function change_theme { + THEMES=() + for d in $BLOG_PATH/themes/*/ ; do + THEME_NAME=$(echo "$d" | awk -F '/' '{print $5}') + THEMES+=("$THEME_NAME") + done + + themelist="" + n=1 + theme_index=0 + for a in "${THEMES[@]}" + do + if [[ $a == "basic" ]]; then + themelist="$applist $n $a on" + else + themelist="$applist $n $a off" + fi + n=$[n+1] + theme_index=$[theme_index+1] + done + + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --stdout --backtitle $"Freedombone Mesh" \ + --title $"Select Blog Theme" \ + --radiolist $'Choose:' \ + 80 40 20 $themelist 2> $data + + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + CHOSEN_THEME_INDEX=$(cat $data) + CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1)) + + CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]} + if grep -q "THEME=" $BLOG_PATH/pelicanconf.py; then + sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" + else + echo "THEME='themes/${CHOSEN_THEME}'" >> $BLOG_PATH/pelicanconf.py + fi + regenerate_blog +} + +function menu_blog { + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Mesh" \ + --title $"Blogging" \ + --radiolist $"Choose an operation:" 19 50 12 \ + 1 $"View a blog" on \ + 2 $"New blog entry" off \ + 3 $"Edit the previous blog entry" off \ + 4 $"Delete the previous blog entry" off \ + 5 $"Change theme" off \ + 6 $"Exit" off 2> $data + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + case $(cat $data) in + 1) view_blog;; + 2) new_blog;; + 3) edit_blog;; + 4) delete_blog;; + 6) change_theme;; + 7) break;; + esac +} + +menu_blog + +exit 0 diff --git a/src/freedombone-mesh-visit-site b/src/freedombone-mesh-visit-site index 6e65c099..9b9297eb 100755 --- a/src/freedombone-mesh-visit-site +++ b/src/freedombone-mesh-visit-site @@ -36,6 +36,9 @@ IPFS_URL='http://127.0.0.1:8080/ipns' # The browser application to use BROWSER=midori +# An optional suffix to be appended to the URL +SUFFIX=$1 + IPFS_USERS_FILE=/home/$USER/.ipfs-users if [ ! -f $IPFS_USERS_FILE ]; then exit 0 @@ -71,7 +74,7 @@ case $sel in IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}') clear echo $'Opening browser. Please wait...' - $BROWSER $IPFS_FULL_URL & + $BROWSER $IPFS_FULL_URL$SUFFIX & fi else exit 1