Static blog on mesh client

This commit is contained in:
Bob Mottram 2016-09-07 20:44:32 +01:00
parent e3f6d1ed1c
commit c174b85797
No known key found for this signature in database
GPG Key ID: 0452CC7CEA982E38
2 changed files with 264 additions and 0 deletions

263
src/freedombone-app-blogstatic Executable file
View File

@ -0,0 +1,263 @@
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Static blog
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# 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 <http://www.gnu.org/licenses/>.
VARIANTS='mesh'
STATIC_BLOG_INSTALL_DIR=/etc/staticblog
PELICAN_THEMES_REPO="https://github.com/getpelican/pelican-themes"
PELICAN_PLUGINS_REPO="https://github.com/getpelican/pelican-plugins"
function reconfigure_tox {
echo -n ''
}
function upgrade_blogstatic {
echo -n ''
}
function backup_local_blogstatic {
echo -n ''
}
function restore_local_blogstatic {
echo -n ''
}
function backup_remote_blogstatic {
echo -n ''
}
function remove_blogstatic {
echo -n ''
}
function create_pelican_conf {
STATIC_BLOG_FILE=$1
echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo "AUTHOR=$MY_NAME" >> $STATIC_BLOG_FILE
echo "SITENAME=u'Freedombone Blog'" >> $STATIC_BLOG_FILE
echo "SITEURL=''" >> $STATIC_BLOG_FILE
echo "PATH='content'" >> $STATIC_BLOG_FILE
echo 'TIMEZONE=Europe/London' >> $STATIC_BLOG_FILE
echo "DEFAULT_LANG=u'en'" >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'FEED_ALL_ATOM=True' >> $STATIC_BLOG_FILE
echo 'CATEGORY_FEED_ATOM=None' >> $STATIC_BLOG_FILE
echo 'TRANSLATION_FEED_ATOM=None' >> $STATIC_BLOG_FILE
echo 'AUTHOR_FEED_ATOM=None' >> $STATIC_BLOG_FILE
echo 'AUTHOR_FEED_RSS=None' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'DEFAULT_PAGINATION=False' >> $STATIC_BLOG_FILE
echo 'RELATIVE_URLS=True' >> $STATIC_BLOG_FILE
}
function create_pelican_makefile {
STATIC_BLOG_FILE=$1
echo 'PY?=python' > $STATIC_BLOG_FILE
echo 'PELICAN?=pelican' >> $STATIC_BLOG_FILE
echo 'PELICANOPTS=' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'BASEDIR=$(CURDIR)' >> $STATIC_BLOG_FILE
echo 'INPUTDIR=$(BASEDIR)/content' >> $STATIC_BLOG_FILE
echo 'OUTPUTDIR=$STATIC_BLOG_PATH' >> $STATIC_BLOG_FILE
echo 'CONFFILE=$(BASEDIR)/pelicanconf.py' >> $STATIC_BLOG_FILE
echo 'PUBLISHCONF=$(BASEDIR)/publishconf.py' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'DEBUG ?= 0' >> $STATIC_BLOG_FILE
echo 'ifeq ($(DEBUG), 1)' >> $STATIC_BLOG_FILE
echo ' PELICANOPTS += -D' >> $STATIC_BLOG_FILE
echo 'endif' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'RELATIVE ?= 0' >> $STATIC_BLOG_FILE
echo 'ifeq ($(RELATIVE), 1)' >> $STATIC_BLOG_FILE
echo ' PELICANOPTS += --relative-urls' >> $STATIC_BLOG_FILE
echo 'endif' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'html:' >> $STATIC_BLOG_FILE
echo ' $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'clean:' >> $STATIC_BLOG_FILE
echo ' [ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'regenerate:' >> $STATIC_BLOG_FILE
echo ' $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'serve:' >> $STATIC_BLOG_FILE
echo 'ifdef PORT' >> $STATIC_BLOG_FILE
echo ' cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)' >> $STATIC_BLOG_FILE
echo 'else' >> $STATIC_BLOG_FILE
echo ' cd $(OUTPUTDIR) && $(PY) -m pelican.server' >> $STATIC_BLOG_FILE
echo 'endif' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'serve-global:' >> $STATIC_BLOG_FILE
echo 'ifdef SERVER' >> $STATIC_BLOG_FILE
echo ' cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)' >> $STATIC_BLOG_FILE
echo 'else' >> $STATIC_BLOG_FILE
echo ' cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0' >> $STATIC_BLOG_FILE
echo 'endif' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'devserver:' >> $STATIC_BLOG_FILE
echo 'ifdef PORT' >> $STATIC_BLOG_FILE
echo ' $(BASEDIR)/develop_server.sh restart $(PORT)' >> $STATIC_BLOG_FILE
echo 'else' >> $STATIC_BLOG_FILE
echo ' $(BASEDIR)/develop_server.sh restart' >> $STATIC_BLOG_FILE
echo 'endif' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'stopserver:' >> $STATIC_BLOG_FILE
echo ' $(BASEDIR)/develop_server.sh stop' >> $STATIC_BLOG_FILE
echo ' @echo "Stopped Pelican and SimpleHTTPServer processes running in background."' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'publish:' >> $STATIC_BLOG_FILE
echo ' $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo '.PHONY: html clean regenerate serve serve-global devserver publish' >> $STATIC_BLOG_FILE
}
function create_pelican_publish_conf {
STATIC_BLOG_FILE=$1
echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'import os' >> $STATIC_BLOG_FILE
echo 'import sys' >> $STATIC_BLOG_FILE
echo 'sys.path.append(os.curdir)' >> $STATIC_BLOG_FILE
echo 'from pelicanconf import *' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo "SITEURL = ''" >> $STATIC_BLOG_FILE
echo 'RELATIVE_URLS = True' >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'" >> $STATIC_BLOG_FILE
echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'" >> $STATIC_BLOG_FILE
echo '' >> $STATIC_BLOG_FILE
echo 'DELETE_OUTPUT_DIRECTORY = True' >> $STATIC_BLOG_FILE
}
function mesh_install_blogstatic {
if [ ! -d $rootdir/home/$MY_USERNAME/Desktop ]; then
return
fi
if [ ! -d $rootdir/home/$MY_USERNAME/Public/Blog ]; then
mkdir -p $rootdir/home/$MY_USERNAME/Public/Blog
chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
fi
STATIC_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
STATIC_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
chroot "$rootdir" apt-get -y install python-pip
chroot "$rootdir" pip install ipython
chroot "$rootdir" pip install Markdown
chroot "$rootdir" pip install typogrify
chroot "$rootdir" pip install pelican
if [ ! -d $rootdir$STATIC_BLOG_INSTALL_DIR ]; then
mkdir -p $rootdir$STATIC_BLOG_INSTALL_DIR
fi
if [ ! -d $rootdir$STATIC_BLOG_INSTALL_DIR/content ]; then
mkdir -p $rootdir$STATIC_BLOG_INSTALL_DIR/content
fi
if [ ! -d $rootdir$STATIC_BLOG_PATH ]; then
mkdir -p $rootdir$STATIC_BLOG_PATH
fi
STATIC_BLOG_FILE=$rootdir$STATIC_BLOG_INSTALL_DIR/pelicanconf.py
create_pelican_conf $STATIC_BLOG_FILE
STATIC_BLOG_FILE=$rootdir$STATIC_BLOG_INSTALL_DIR/Makefile
create_pelican_makefile $STATIC_BLOG_FILE
STATIC_BLOG_FILE=$rootdir$STATIC_BLOG_INSTALL_DIR/publishconf.py
create_pelican_publish_conf $STATIC_BLOG_FILE
git clone --recursive $PELICAN_THEMES_REPO $rootdir$STATIC_BLOG_INSTALL_DIR/themes
git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$STATIC_BLOG_INSTALL_DIR/plugins
chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME $STATIC_BLOG_INSTALL_DIR
}
function install_blogstatic {
if [ $INSTALLING_MESH ]; then
mesh_install_blogstatic
return
fi
if grep -Fxq "install_blogstatic" $COMPLETION_FILE; then
return
fi
STATIC_BLOG_INSTALL_DIR=/etc/blog
STATIC_BLOG_PATH=/var/www/$STATIC_BLOG_DOMAIN/htdocs
apt-get -y install python-pip
pip install ipython
pip install Markdown
pip install typogrify
pip install pelican
if [ ! -d $STATIC_BLOG_INSTALL_DIR ]; then
mkdir -p $STATIC_BLOG_INSTALL_DIR
fi
if [ ! -d $STATIC_BLOG_INSTALL_DIR/content ]; then
mkdir -p $STATIC_BLOG_INSTALL_DIR/content
fi
if [ ! -d $STATIC_BLOG_PATH ]; then
mkdir -p $STATIC_BLOG_PATH
fi
STATIC_BLOG_FILE=$STATIC_BLOG_INSTALL_DIR/pelicanconf.py
create_pelican_conf $STATIC_BLOG_FILE
STATIC_BLOG_FILE=$STATIC_BLOG_INSTALL_DIR/Makefile
create_pelican_makefile $STATIC_BLOG_FILE
STATIC_BLOG_FILE=$STATIC_BLOG_INSTALL_DIR/publishconf.py
create_pelican_publish_conf $STATIC_BLOG_FILE
git clone --recursive $PELICAN_THEMES_REPO $STATIC_BLOG_INSTALL_DIR/themes
git clone --recursive $PELICAN_PLUGINS_REPO $STATIC_BLOG_INSTALL_DIR/plugins
chown -R $MY_USERNAME:$MY_USERNAME $STATIC_BLOG_INSTALL_DIR
echo 'install_blogstatic' >> $COMPLETION_FILE
}
# NOTE: deliberately no exit 0

View File

@ -560,6 +560,7 @@ initialise_mesh() {
install_ipfs
install_tox
install_web_server
install_blogstatic
if [ $ENABLE_ZERONET ]; then
install_zeronet
fi