2016-09-07 21:44:32 +02:00
|
|
|
#!/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 {
|
2016-09-08 14:30:40 +02:00
|
|
|
if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
|
2016-09-07 21:44:32 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
STATIC_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
|
|
|
|
STATIC_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
|
|
|
|
|
2016-09-07 21:44:32 +02:00
|
|
|
if [ ! -d $rootdir$STATIC_BLOG_INSTALL_DIR ]; then
|
|
|
|
mkdir -p $rootdir$STATIC_BLOG_INSTALL_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $rootdir$STATIC_BLOG_PATH ]; then
|
|
|
|
mkdir -p $rootdir$STATIC_BLOG_PATH
|
|
|
|
fi
|
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
if [ ! -d $rootdir$STATIC_BLOG_INSTALL_DIR/content ]; then
|
|
|
|
mkdir -p $rootdir$STATIC_BLOG_INSTALL_DIR/content
|
|
|
|
fi
|
2016-09-07 21:44:32 +02:00
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
create_pelican_conf $rootdir$STATIC_BLOG_INSTALL_DIR/pelicanconf.py
|
|
|
|
create_pelican_makefile $rootdir$STATIC_BLOG_INSTALL_DIR/Makefile
|
2016-09-08 10:37:36 +02:00
|
|
|
create_pelican_publish_conf $rootdir$STATIC_BLOG_INSTALL_DIR/publishconf.py
|
2016-09-07 21:44:32 +02:00
|
|
|
|
|
|
|
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
|
2016-09-08 10:35:53 +02:00
|
|
|
chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
|
2016-09-07 21:44:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_blogstatic {
|
|
|
|
if [ $INSTALLING_MESH ]; then
|
|
|
|
mesh_install_blogstatic
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if grep -Fxq "install_blogstatic" $COMPLETION_FILE; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -y install python-pip
|
|
|
|
pip install ipython
|
|
|
|
pip install Markdown
|
|
|
|
pip install typogrify
|
|
|
|
pip install pelican
|
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
STATIC_BLOG_INSTALL_DIR=/etc/blog
|
|
|
|
STATIC_BLOG_PATH=/var/www/$STATIC_BLOG_DOMAIN/htdocs
|
|
|
|
|
2016-09-07 21:44:32 +02:00
|
|
|
if [ ! -d $STATIC_BLOG_INSTALL_DIR ]; then
|
|
|
|
mkdir -p $STATIC_BLOG_INSTALL_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $STATIC_BLOG_PATH ]; then
|
|
|
|
mkdir -p $STATIC_BLOG_PATH
|
|
|
|
fi
|
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
if [ ! -d $STATIC_BLOG_INSTALL_DIR/content ]; then
|
|
|
|
mkdir -p $STATIC_BLOG_INSTALL_DIR/content
|
|
|
|
fi
|
2016-09-07 21:44:32 +02:00
|
|
|
|
2016-09-08 10:35:53 +02:00
|
|
|
create_pelican_conf $STATIC_BLOG_INSTALL_DIR/pelicanconf.py
|
|
|
|
create_pelican_makefile $STATIC_BLOG_INSTALL_DIR/Makefile
|
|
|
|
create_pelican_publish_conf $STATIC_BLOG_INSTALL_DIR/publishconf.py
|
2016-09-07 21:44:32 +02:00
|
|
|
|
|
|
|
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
|
2016-09-08 10:35:53 +02:00
|
|
|
chown -R www-data:www-data $STATIC_BLOG_PATH
|
2016-09-07 21:44:32 +02:00
|
|
|
|
|
|
|
echo 'install_blogstatic' >> $COMPLETION_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|