2016-09-07 21:44:32 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
2017-03-31 22:49:20 +02:00
# Pelican static blog
2016-09-07 21:44:32 +02:00
#
# License
# =======
#
2018-01-25 19:35:39 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-09-07 21:44:32 +02:00
#
# 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/>.
2017-03-31 22:50:55 +02:00
VARIANTS="full full-vim writer"
2016-09-07 21:44:32 +02:00
2016-10-19 22:52:59 +02:00
IN_DEFAULT_INSTALL=0
2017-03-31 22:50:55 +02:00
SHOW_ON_ABOUT=1
2016-10-19 22:52:59 +02:00
2017-03-31 22:47:00 +02:00
PELICAN_DOMAIN_NAME=
2017-03-25 19:07:31 +01:00
PELICAN_BLOG_CODE=
2017-03-31 23:36:59 +02:00
PELICAN_ONION_PORT=8113
2017-03-25 19:07:31 +01:00
2016-09-07 21:44:32 +02:00
PELICAN_THEMES_REPO="https://github.com/getpelican/pelican-themes"
PELICAN_PLUGINS_REPO="https://github.com/getpelican/pelican-plugins"
2016-09-09 10:31:27 +02:00
DEFAULT_BLOG_TITLE=$"Freedombone Blog"
2016-09-07 21:44:32 +02:00
2017-03-26 13:36:52 +02:00
PELICAN_BLOG_INSTALL_DIR=/etc/blog
2017-03-26 14:02:04 +02:00
PELICAN_CURRENT_BLOG_INDEX=$PELICAN_BLOG_INSTALL_DIR/.blog-index
2017-03-26 13:36:52 +02:00
2016-10-16 13:51:04 +02:00
pelican_variables=(MY_USERNAME
2017-03-25 19:07:31 +01:00
ONION_ONLY
2017-03-31 22:47:00 +02:00
PELICAN_DOMAIN_NAME
2017-03-25 19:07:31 +01:00
PELICAN_BLOG_CODE)
2016-10-05 23:33:41 +02:00
2017-12-31 11:44:21 +01:00
function pelican_remove_bad_blog_links {
2018-03-01 00:17:49 +01:00
find ./ -type f -name "*.css" -exec sed -i -e '/googleapi/d' {} \;
find ./ -type f -name "*.scss" -exec sed -i -e '/googleapi/d' {} \;
find ./ -type f -name "*.html" -exec sed -i -e '/googleapi/d' {} \;
find ./ -type f -name "*.css" -exec sed -i -e '/bootstrapcdn/d' {} \;
find ./ -type f -name "*.scss" -exec sed -i -e '/bootstrapcdn/d' {} \;
find ./ -type f -name "*.html" -exec sed -i -e '/bootstrapcdn/d' {} \;
2017-12-31 11:44:21 +01:00
}
2017-07-01 20:14:28 +02:00
function logging_on_pelican {
echo -n ''
}
function logging_off_pelican {
echo -n ''
}
2017-03-31 22:47:00 +02:00
function install_pelican_website {
2017-03-31 23:44:28 +02:00
if [[ $ONION_ONLY != 'no' ]]; then
2017-03-31 22:47:00 +02:00
echo -n '' > /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
return
fi
function_check nginx_http_redirect
nginx_http_redirect $PELICAN_DOMAIN_NAME
2018-03-01 00:17:49 +01:00
{ echo 'server {';
echo ' listen 443 ssl;';
echo ' #listen [::]:443 ssl;';
echo " root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
echo " server_name ${PELICAN_DOMAIN_NAME};";
echo ' access_log /dev/null;';
echo " error_log /dev/null;";
echo ' index index.html;';
echo ' charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check nginx_ssl
2018-03-01 00:17:49 +01:00
nginx_ssl "$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check nginx_disable_sniffing
2018-03-01 00:17:49 +01:00
nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
{ echo ' add_header Strict-Transport-Security "max-age=0;";';
echo '';
echo ' location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check nginx_limits
2018-03-01 00:17:49 +01:00
nginx_limits "$PELICAN_DOMAIN_NAME"
{ echo ' }';
echo '';
echo ' # block these file types';
echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
echo ' deny all;';
echo ' }';
echo '';
echo ' # deny access to all dot files';
echo ' location ~ /\. {';
echo ' deny all;';
echo ' }';
echo '';
echo ' location ~ /(data|conf|bin|inc)/ {';
echo ' deny all;';
echo ' }';
echo ' location ~ /\.ht {';
echo ' deny all;';
echo ' }';
echo '}';
echo ''; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check create_site_certificate
2018-03-01 00:17:49 +01:00
create_site_certificate "$PELICAN_DOMAIN_NAME" 'yes'
2017-03-31 22:47:00 +02:00
}
function install_pelican_website_onion {
2018-03-01 00:17:49 +01:00
{ echo 'server {';
echo " listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;";
echo " root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
echo " server_name ${PELICAN_DOMAIN_NAME};";
echo ' access_log /dev/null;';
echo " error_log /dev/null;";
echo ' index index.html;';
echo ' charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check nginx_disable_sniffing
2018-03-01 00:17:49 +01:00
nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
{ echo ' add_header Strict-Transport-Security "max-age=0;";';
echo '';
echo ' location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
function_check nginx_limits
2018-03-01 00:17:49 +01:00
nginx_limits "$PELICAN_DOMAIN_NAME"
{ echo ' }';
echo '';
echo ' # block these file types';
echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
echo ' deny all;';
echo ' }';
echo '';
echo ' # deny access to all dot files';
echo ' location ~ /\. {';
echo ' deny all;';
echo ' }';
echo '';
echo ' location ~ /(data|conf|bin|inc)/ {';
echo ' deny all;';
echo ' }';
echo ' location ~ /\.ht {';
echo ' deny all;';
echo ' }';
echo '}'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
2017-03-31 22:47:00 +02:00
}
2017-03-26 13:50:52 +02:00
function pelican_editor_config {
if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
2018-03-01 00:17:49 +01:00
{ echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)";
echo '(setq org-support-shift-select t)';
echo '(setq standard-indent 4)';
echo '(setq-default tab-width 4)';
echo '(setq c-basic-offset 4)';
echo '(mouse-wheel-mode t)';
echo '(setq make-backup-files t)';
echo '(setq version-control t)';
echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
echo "(setq default-major-mode 'text-mode)";
echo "(dolist (hook '(text-mode-hook))";
echo ' (add-hook hook (lambda () (flyspell-mode 1))))';
echo '(setq-default fill-column 72)';
echo '(setq auto-fill-mode 0)';
echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)";
echo "(setq-default auto-fill-function 'do-auto-fill)"; } > "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican"
2017-03-26 13:50:52 +02:00
fi
}
2017-03-26 13:36:52 +02:00
function pelican_regenerate_blog {
clear
echo ''
echo $'Regenerating blog...'
2018-03-01 00:17:49 +01:00
cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
2017-03-26 13:36:52 +02:00
make html
2017-03-31 22:47:00 +02:00
cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
2017-03-26 13:36:52 +02:00
}
function pelican_new_blog {
DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
2017-03-26 13:50:52 +02:00
if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
2018-03-01 00:17:49 +01:00
{ echo $'Title: Blog Post Title';
echo $"Date: ${DATESTR}";
echo $"Author: $(toxid --showuser)";
echo $'Category: default';
echo $'Tags: blog, tag';
echo '';
echo $'Add your text here';
echo '';
echo -n $'To include an image copy it into the /etc/blog/content/images directory, ';
echo $'then link to it with:';
echo '';
echo $'![My image]({filename}images/myimage.jpg)';
echo ''; } > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
2017-03-26 13:50:52 +02:00
fi
if [ -f /usr/bin/emacs ]; then
emacs -q --load $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
else
editor $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
fi
2017-03-26 13:36:52 +02:00
if grep -q $"Add your text here" $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry; then
return
fi
if grep -q $"Blog Post Title" $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry; then
return
fi
2017-03-26 14:02:04 +02:00
if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
echo '0' > $PELICAN_CURRENT_BLOG_INDEX
2017-03-26 13:36:52 +02:00
fi
# move to the content directory
2017-03-26 14:02:04 +02:00
CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
2018-03-01 00:17:49 +01:00
mv "$PELICAN_BLOG_INSTALL_DIR/.new-blog-entry" "$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md"
2017-03-26 13:36:52 +02:00
# increment the index
CURRENT_INDEX=$((CURRENT_INDEX + 1))
2017-03-26 14:02:04 +02:00
echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
2017-03-26 13:36:52 +02:00
pelican_regenerate_blog
}
function pelican_edit_blog {
2017-03-26 14:02:04 +02:00
if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
2017-03-26 13:36:52 +02:00
return
fi
2017-03-26 14:02:04 +02:00
CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
2017-03-26 13:36:52 +02:00
PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
2018-03-01 00:17:49 +01:00
if [ ! -f "$LAST_BLOG_ENTRY" ]; then
2017-03-26 13:36:52 +02:00
return
fi
2017-03-26 13:50:52 +02:00
if [ -f /usr/bin/emacs ]; then
2018-03-01 00:17:49 +01:00
emacs -q --load "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican" "$LAST_BLOG_ENTRY"
2017-03-26 13:50:52 +02:00
else
2018-03-01 00:17:49 +01:00
editor "$LAST_BLOG_ENTRY"
2017-03-26 13:50:52 +02:00
fi
pelican_regenerate_blog
2017-03-26 13:36:52 +02:00
}
function pelican_delete_blog {
2017-03-26 14:02:04 +02:00
if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
2017-03-26 13:36:52 +02:00
return
fi
2017-03-26 14:02:04 +02:00
CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
2017-03-26 13:36:52 +02:00
PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
2018-03-01 00:17:49 +01:00
if [ ! -f "$LAST_BLOG_ENTRY" ]; then
2017-03-26 13:36:52 +02:00
return
fi
dialog --title $"Delete the previous blog entry" \
--backtitle $"Freedombone Mesh" \
--defaultno \
2018-03-01 00:17:49 +01:00
--yesno $"\\nAre you sure that you wish to delete the previous blog entry?" 8 60
2017-03-26 13:36:52 +02:00
sel=$?
case $sel in
2018-03-01 00:17:49 +01:00
0) rm "$LAST_BLOG_ENTRY"
if [ "$CURRENT_INDEX" -gt 0 ]; then
2017-03-26 13:36:52 +02:00
CURRENT_INDEX=$PREVIOUS_INDEX
2017-03-26 14:02:04 +02:00
echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
2017-03-26 13:36:52 +02:00
else
2017-03-26 14:02:04 +02:00
rm -f $PELICAN_CURRENT_BLOG_INDEX
2017-03-26 13:36:52 +02:00
fi
pelican_regenerate_blog
;;
esac
}
function pelican_change_theme {
THEMES=()
for d in $PELICAN_BLOG_INSTALL_DIR/themes/*/ ; do
THEME_NAME=$(echo "$d" | awk -F '/' '{print $6}')
THEMES+=("$THEME_NAME")
done
themelist=""
n=1
theme_index=0
curr_theme_index=
if [ -f $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index ]; then
curr_theme_index=$(cat $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index)
fi
for a in "${THEMES[@]}"
do
is_selected='off'
2018-03-01 00:17:49 +01:00
if [ "$curr_theme_index" ]; then
if [ $n -eq "$curr_theme_index" ]; then
2017-03-26 13:36:52 +02:00
is_selected='on'
fi
else
if [[ "$a" == 'nice-blog' ]]; then
is_selected='on'
fi
fi
themelist="$themelist $n $a $is_selected"
2018-03-01 00:17:49 +01:00
n=$((n+1))
theme_index=$((theme_index+1))
2017-03-26 13:36:52 +02:00
done
2018-03-01 00:17:49 +01:00
data=$(mktemp 2>/dev/null)
2017-03-26 13:36:52 +02:00
dialog --backtitle $"Freedombone Mesh" \
--title $"Select Blog Theme" \
--radiolist $'Choose:' \
2018-03-01 00:17:49 +01:00
80 40 20 "$themelist" 2> "$data"
2017-03-26 13:36:52 +02:00
sel=$?
case $sel in
2018-03-01 00:17:49 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
2017-03-26 13:36:52 +02:00
esac
2018-03-01 00:17:49 +01:00
CHOSEN_THEME_INDEX=$(cat "$data")
rm -f "$data"
2017-03-26 13:36:52 +02:00
echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
2017-12-31 19:17:01 +01:00
2018-03-01 00:17:49 +01:00
cd "$PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME" || exit 2648268284
2017-12-31 19:17:01 +01:00
pelican_remove_bad_blog_links
2017-03-26 13:36:52 +02:00
if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
else
echo "THEME='themes/${CHOSEN_THEME}'" >> $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
fi
pelican_regenerate_blog
}
2016-10-16 13:51:04 +02:00
function configure_interactive_pelican {
2018-03-01 00:17:49 +01:00
data=$(mktemp 2>/dev/null)
2017-03-26 13:36:52 +02:00
dialog --backtitle $"Freedombone Configuration" \
--title $"Pelican Blogging" \
--radiolist $"Choose an operation:" 18 50 11 \
1 $"New blog entry" off \
2 $"Edit the previous blog entry" off \
3 $"Delete the previous blog entry" off \
4 $"Change theme" off \
2018-03-01 00:17:49 +01:00
5 $"Exit" off 2> "$data"
2017-03-26 13:36:52 +02:00
sel=$?
case $sel in
2018-03-01 00:17:49 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
2017-03-26 13:36:52 +02:00
esac
2018-03-01 00:17:49 +01:00
case $(cat "$data") in
2017-03-26 13:36:52 +02:00
1) pelican_new_blog;;
2) pelican_edit_blog;;
3) pelican_delete_blog;;
4) pelican_change_theme;;
esac
2018-03-01 00:17:49 +01:00
rm -f "$data"
2016-09-30 14:34:09 +02:00
}
2016-10-16 13:51:04 +02:00
function install_interactive_pelican {
2018-03-01 00:17:49 +01:00
if [ ! "$ONION_ONLY" ]; then
2017-03-25 19:07:31 +01:00
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
2017-03-31 22:47:00 +02:00
PELICAN_DOMAIN_NAME='pelican.local'
2017-03-25 19:07:31 +01:00
else
PELICAN_DETAILS_COMPLETE=
while [ ! $PELICAN_DETAILS_COMPLETE ]
do
2018-03-01 00:17:49 +01:00
data=$(mktemp 2>/dev/null)
2017-03-25 19:07:31 +01:00
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
dialog --backtitle $"Freedombone Configuration" \
--title $"Pelican Blog Configuration" \
2018-03-01 00:17:49 +01:00
--form $"\\nPlease enter your blog details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
2017-03-31 22:47:00 +02:00
$"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
2017-03-25 19:07:31 +01:00
$"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
2018-03-01 00:17:49 +01:00
2> "$data"
2017-03-25 19:07:31 +01:00
else
dialog --backtitle $"Freedombone Configuration" \
--title $"Pelican Blog Configuration" \
2018-03-01 00:17:49 +01:00
--form $"\\nPlease enter your GNU Social details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
2017-03-31 22:47:00 +02:00
$"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
2018-03-01 00:17:49 +01:00
2> "$data"
2017-03-25 19:07:31 +01:00
fi
sel=$?
case $sel in
2018-03-01 00:17:49 +01:00
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
2017-03-25 19:07:31 +01:00
esac
2018-03-01 00:17:49 +01:00
PELICAN_DOMAIN_NAME=$(sed -n 1p < "$data")
if [ "$PELICAN_DOMAIN_NAME" ]; then
2017-03-31 22:47:00 +02:00
if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
PELICAN_DOMAIN_NAME=""
2017-03-25 19:07:31 +01:00
fi
2017-03-31 22:47:00 +02:00
TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
2017-03-25 19:07:31 +01:00
validate_domain_name
2018-03-01 00:17:49 +01:00
if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
2017-03-31 22:47:00 +02:00
PELICAN_DOMAIN_NAME=
2017-03-25 19:07:31 +01:00
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
2018-03-01 00:17:49 +01:00
PELICAN_BLOG_CODE=$(sed -n 2p < "$data")
2017-03-25 19:07:31 +01:00
validate_freedns_code "$PELICAN_BLOG_CODE"
2018-03-01 00:17:49 +01:00
if [ ! "$VALID_CODE" ]; then
2017-03-31 22:47:00 +02:00
PELICAN_DOMAIN_NAME=
2017-03-25 19:07:31 +01:00
fi
fi
fi
fi
2017-03-31 22:47:00 +02:00
if [ $PELICAN_DOMAIN_NAME ]; then
2017-03-25 19:07:31 +01:00
PELICAN_DETAILS_COMPLETE="yes"
fi
2018-03-01 00:17:49 +01:00
rm -f "$data"
2017-03-25 19:07:31 +01:00
done
# save the results in the config file
write_config_param "PELICAN_BLOG_CODE" "$PELICAN_BLOG_CODE"
fi
2017-03-31 22:47:00 +02:00
write_config_param "PELICAN_DOMAIN_NAME" "$PELICAN_DOMAIN_NAME"
2016-10-10 20:11:33 +02:00
APP_INSTALLED=1
2016-09-30 12:34:39 +02:00
}
2016-10-16 13:51:04 +02:00
function reconfigure_pelican {
2016-09-07 21:44:32 +02:00
echo -n ''
}
2016-10-16 13:51:04 +02:00
function upgrade_pelican {
2016-09-07 21:44:32 +02:00
echo -n ''
}
2016-10-16 13:51:04 +02:00
function backup_local_pelican {
2017-03-26 12:31:21 +02:00
source_directory=/etc/blog
if [ -d $source_directory ]; then
dest_directory=pelican
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
fi
2017-03-31 22:47:00 +02:00
source_directory=/var/www/$PELICAN_DOMAIN_NAME/htdocs
2017-03-26 12:31:21 +02:00
if [ -d $source_directory ]; then
dest_directory=pelican-site
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
fi
2016-09-07 21:44:32 +02:00
}
2016-10-16 13:51:04 +02:00
function restore_local_pelican {
2017-03-26 12:31:21 +02:00
if [ -d /etc/blog ]; then
2018-03-01 00:17:49 +01:00
if [ -d "$USB_MOUNT_DLNA/backup/pelican" ]; then
2017-03-26 12:31:21 +02:00
temp_restore_dir=/root/temppelican
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir pelican
2017-08-25 18:35:33 +02:00
if [ -d $temp_restore_dir/etc/blog ]; then
cp -r $temp_restore_dir/etc/blog/* /etc/blog/
else
cp -r $temp_restore_dir/* /etc/blog/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2017-03-26 12:31:21 +02:00
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 527942
fi
rm -rf $temp_restore_dir
fi
fi
2017-03-31 22:47:00 +02:00
if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
2018-03-01 00:17:49 +01:00
if [ -d "$USB_MOUNT_DLNA/backup/pelican-site" ]; then
2017-03-26 12:31:21 +02:00
temp_restore_dir=/root/temppelican-site
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir pelican-site
2017-08-25 18:35:33 +02:00
if [ -d $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
cp -r $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
else
cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2017-03-26 12:31:21 +02:00
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 2946282
fi
rm -rf $temp_restore_dir
fi
fi
2016-09-07 21:44:32 +02:00
}
2016-10-16 13:51:04 +02:00
function backup_remote_pelican {
2017-03-26 12:31:21 +02:00
if [ -d /etc/blog ]; then
backup_directory_to_friend /etc/blog pelican
fi
2017-03-31 22:47:00 +02:00
if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
backup_directory_to_friend /var/www/$PELICAN_DOMAIN_NAME/htdocs pelican-site
2017-03-26 12:31:21 +02:00
fi
2016-09-07 21:44:32 +02:00
}
2016-10-16 13:51:04 +02:00
function restore_remote_pelican {
2017-03-26 12:31:21 +02:00
if [ -d /etc/blog ]; then
2018-03-01 00:17:49 +01:00
if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
2017-03-26 12:31:21 +02:00
temp_restore_dir=/root/temppelican
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir pelican
2017-08-25 18:35:33 +02:00
if [ -d $temp_restore_dir/etc/blog ]; then
cp -r $temp_restore_dir/etc/blog/* /etc/blog/
else
cp -r $temp_restore_dir/* /etc/blog/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2017-03-26 12:31:21 +02:00
if [ ! "$?" = "0" ]; then
exit 782352
fi
rm -rf $temp_restore_dir
fi
fi
2017-03-31 22:47:00 +02:00
if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
2018-03-01 00:17:49 +01:00
if [ -d "$SERVER_DIRECTORY/backup/pelican-site" ]; then
2017-03-26 12:31:21 +02:00
temp_restore_dir=/root/temppelican-site
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir pelican-site
2017-08-25 18:35:33 +02:00
if [ -d $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
cp -r $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
else
cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2181
2017-03-26 12:31:21 +02:00
if [ ! "$?" = "0" ]; then
exit 76382562
fi
rm -rf $temp_restore_dir
fi
fi
2016-09-23 21:36:10 +02:00
}
2016-10-16 13:51:04 +02:00
function remove_pelican {
2017-03-31 23:46:24 +02:00
if [ -f /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME ]; then
nginx_dissite pelican
rm /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
if [ -d /var/www/$PELICAN_DOMAIN_NAME ]; then
rm -rf /var/www/$PELICAN_DOMAIN_NAME
fi
systemctl reload nginx
2016-10-17 15:44:49 +02:00
fi
2017-03-31 23:46:24 +02:00
2016-10-17 15:44:49 +02:00
pip uninstall pelican
2017-03-31 22:47:00 +02:00
remove_certs $PELICAN_DOMAIN_NAME
2017-03-31 23:36:59 +02:00
function_check remove_onion_service
2017-03-31 23:54:21 +02:00
remove_onion_service pelican ${PELICAN_ONION_PORT}
2017-03-31 23:39:44 +02:00
remove_app pelican
2017-06-02 12:14:19 +02:00
systemctl restart tor
2016-09-07 21:44:32 +02:00
}
function create_pelican_conf {
2018-03-01 00:17:49 +01:00
STATIC_BLOG_FILE="$1"
{ echo '#!/usr/bin/env python';
echo '# -*- coding: utf-8 -*- #';
echo 'from __future__ import unicode_literals';
echo '';
echo "AUTHOR=u\"$MY_USERNAME\"";
echo "SITENAME=u'$DEFAULT_BLOG_TITLE'";
echo "SITEURL=''";
echo "PATH='content'";
echo 'TIMEZONE=u"Europe/London"';
echo "DEFAULT_LANG=u'en'";
echo '';
echo 'FEED_ALL_ATOM=None';
echo 'CATEGORY_FEED_ATOM=None';
echo 'TRANSLATION_FEED_ATOM=None';
echo 'AUTHOR_FEED_ATOM=None';
echo 'AUTHOR_FEED_RSS=None';
echo '';
echo 'DEFAULT_PAGINATION=False';
echo 'RELATIVE_URLS=True';
echo "THEME='themes/nice-blog'"; } > "$STATIC_BLOG_FILE"
2016-09-07 21:44:32 +02:00
}
function create_pelican_makefile {
2018-03-01 00:17:49 +01:00
STATIC_BLOG_FILE="$1"
{ echo 'PY?=python';
echo 'PELICAN?=pelican';
echo 'PELICANOPTS=';
echo '';
echo "BASEDIR=\$(CURDIR)";
echo "INPUTDIR=\$(BASEDIR)/content";
echo "OUTPUTDIR=$PELICAN_BLOG_PATH";
echo "CONFFILE=\$(BASEDIR)/pelicanconf.py";
echo "PUBLISHCONF=\$(BASEDIR)/publishconf.py";
echo '';
echo 'DEBUG ?= 0';
echo "ifeq (\$(DEBUG), 1)";
echo -e '\tPELICANOPTS += -D';
echo 'endif';
echo '';
echo 'RELATIVE ?= 0';
echo "ifeq (\$(RELATIVE), 1)";
echo -e '\tPELICANOPTS += --relative-urls';
echo 'endif';
echo '';
echo 'html:';
echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
echo '';
echo 'clean:';
echo -e "\\t[ ! -d \$(OUTPUTDIR) ] || rm -rf \$(OUTPUTDIR)";
echo '';
echo 'regenerate:';
echo -e "\\t\$(PELICAN) -r \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
echo '';
echo 'serve:';
echo 'ifdef PORT';
echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server \$(PORT)";
echo 'else';
echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server";
echo 'endif';
echo '';
echo 'serve-global:';
echo 'ifdef SERVER';
echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 \$(SERVER)";
echo 'else';
echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 0.0.0.0";
echo 'endif';
echo '';
echo 'devserver:';
echo 'ifdef PORT';
echo -e "\\t\$(BASEDIR)/develop_server.sh restart \$(PORT)";
echo 'else';
echo -e "\\t\$(BASEDIR)/develop_server.sh restart";
echo 'endif';
echo '';
echo 'stopserver:';
echo -e "\\t\$(BASEDIR)/develop_server.sh stop";
echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."';
echo '';
echo 'publish:';
echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(PUBLISHCONF) \$(PELICANOPTS)";
echo '';
echo '.PHONY: html clean regenerate serve serve-global devserver publish'; } > "$STATIC_BLOG_FILE"
2016-09-07 21:44:32 +02:00
}
function create_pelican_publish_conf {
STATIC_BLOG_FILE=$1
2018-03-01 00:17:49 +01:00
{ echo '#!/usr/bin/env python';
echo '# -*- coding: utf-8 -*- #';
echo 'from __future__ import unicode_literals';
echo '';
echo 'import os';
echo 'import sys';
echo 'sys.path.append(os.curdir)';
echo 'from pelicanconf import *';
echo '';
echo "SITEURL = ''";
echo 'RELATIVE_URLS = True';
echo '';
echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'";
echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'";
echo '';
echo 'DELETE_OUTPUT_DIRECTORY = True'; } > "$STATIC_BLOG_FILE"
2016-09-07 21:44:32 +02:00
}
2016-10-16 13:51:04 +02:00
function pelican_themes {
2016-09-10 19:43:08 +02:00
# Clone themes separately because the themes repo sometimes has bad refs
git clone https://github.com/KenMercusLai/BT3-Flat
git clone https://github.com/abr4xas/Casper2Pelican
git clone https://github.com/alexandrevicenzi/Flex
git clone https://github.com/allenskd/Nuja
git clone https://github.com/ir193/Responsive-Pelican
git clone https://github.com/nairobilug/pelican-alchemy
git clone https://github.com/livibetter-backup/apricot
git clone https://github.com/jody-frankowski/blue-penguin
git clone https://github.com/gregseth/pelican-bgh
git clone https://github.com/blueicefield/pelican-blueidea
git clone https://github.com/demianbrecht/pelican-bold
git clone https://github.com/fly/burrito
git clone https://github.com/yuex/pelican-iliork
git clone https://github.com/tbunnyman/pelican-chunk
git clone https://github.com/hdra/Pelican-Cid
git clone https://github.com/gilsondev/pelican-clean-blog
git clone https://github.com/porterjamesj/crowsfoot
git clone https://github.com/22decembre/dev-random3.git
git clone https://github.com/kura/eevee
git clone https://github.com/talha131/pelican-elegant.git
git clone https://github.com/callmefish/pelican-free-agent
git clone https://github.com/jsliang/pelican-fresh
git clone https://github.com/vaiski/genus
git clone https://github.com/PierrePaul/html5-dopetrope
git clone https://github.com/jvanz/pelican-hyde
git clone https://github.com/erfaan/pelican-theme-irfan
git clone https://github.com/slok/iris
git clone https://github.com/badele/pelican-theme-jesuislibre
git clone https://github.com/mothsART/pelican-lab
git clone https://github.com/siovene/lannisport
git clone https://github.com/lazycoder-ru/lazystrap
git clone https://github.com/chdoig/pelican-bootstrap3-lovers
git clone https://github.com/kplaube/maggner-pelican
git clone https://github.com/cpaulik/martin-pelican
git clone https://github.com/greizgh/pelican-material
git clone https://github.com/eswarm/materialistic-pelican
git clone https://github.com/cprieto/pelican-mediumfox
git clone https://github.com/onuraslan/medius
git clone https://github.com/lucachr/pelican-mg
git clone https://github.com/BYK/pelican-neat
git clone https://github.com/molivier/nest
git clone https://github.com/guilherme-toti/nice-blog
git clone https://github.com/gunchu/nikhil-theme
git clone https://github.com/wilbur-ma/niu-x2
git clone https://github.com/duilio/pelican-octopress-theme
git clone https://github.com/Parbhat/pelican-blue
git clone https://github.com/hdra/pelican-cait
git clone https://github.com/laughk/pelican-hss
git clone https://github.com/wrl/pelican-mockingbird
git clone https://github.com/fle/pelican-simplegrey
git clone https://github.com/fle/pelican-sober
git clone https://github.com/ingwinlu/pelican-twitchy
git clone https://github.com/badele/pelicanthemes-generator
git clone https://github.com/jjimenezlopez/pelipress
git clone https://github.com/xm3ron/pjport
git clone https://github.com/kdeldycke/plumage
git clone https://github.com/habibillah/pujangga
git clone https://github.com/danclaudiupop/pure
git clone https://github.com/wamonite/relapse
git clone https://github.com/ellisonleao/pelican-semantic-ui
git clone https://github.com/kdheepak89/pelican-smoothie
git clone https://github.com/if1live/pelican-sora
git clone https://github.com/redVi/storm
git clone https://github.com/keningle/pelican-sundown
git clone https://github.com/giulivo/pelican-svbhack
git clone https://github.com/wting/pelican-svbtle
git clone https://github.com/frankV/twenty-pelican-html5up
git clone https://github.com/robulouski/voidy-bootstrap
git clone https://github.com/samael500/w3-personal-blog
git clone https://github.com/jarv/water-iris
git clone https://github.com/kplaube/yapeme
2017-12-09 16:01:48 +01:00
2017-12-31 11:44:21 +01:00
pelican_remove_bad_blog_links
2016-09-10 20:23:49 +02:00
}
2016-10-16 13:51:04 +02:00
function mesh_install_pelican {
2018-03-01 00:17:49 +01:00
if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
2016-09-10 20:23:49 +02:00
return
fi
2018-03-01 00:17:49 +01:00
# shellcheck disable=SC2154
2016-10-23 20:38:14 +02:00
chroot "$rootdir" apt-get -yq install python-pip
2016-09-10 20:23:49 +02:00
chroot "$rootdir" pip install ipython
chroot "$rootdir" pip install Markdown
chroot "$rootdir" pip install typogrify
chroot "$rootdir" pip install pelican
2017-03-26 13:36:52 +02:00
PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
2016-09-10 20:23:49 +02:00
2018-03-01 00:17:49 +01:00
if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR" ]; then
mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR"
2016-09-10 20:23:49 +02:00
fi
2018-03-01 00:17:49 +01:00
if [ ! -d "$rootdir$PELICAN_BLOG_PATH" ]; then
mkdir -p "$rootdir$PELICAN_BLOG_PATH"
2016-09-10 20:23:49 +02:00
fi
2018-03-01 00:17:49 +01:00
if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images" ]; then
mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images"
2016-09-10 20:23:49 +02:00
fi
2018-03-01 00:17:49 +01:00
create_pelican_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
create_pelican_makefile "$rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile"
create_pelican_publish_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
2016-09-10 20:23:49 +02:00
2018-03-01 00:17:49 +01:00
mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes"
cd "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes" || exit 74624524
2016-10-16 13:51:04 +02:00
pelican_themes
2016-09-10 19:43:08 +02:00
2017-03-26 13:36:52 +02:00
#git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
2016-09-07 21:44:32 +02:00
2018-03-01 00:17:49 +01:00
chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/Public"
2016-09-07 21:44:32 +02:00
}
2016-10-16 13:51:04 +02:00
function install_pelican {
2018-03-01 00:17:49 +01:00
if [ "$INSTALLING_MESH" ]; then
2016-10-16 13:51:04 +02:00
mesh_install_pelican
2016-09-07 21:44:32 +02:00
return
fi
2016-10-23 20:38:14 +02:00
apt-get -yq install python-pip
2016-09-07 21:44:32 +02:00
pip install ipython
pip install Markdown
pip install typogrify
pip install pelican
2017-03-31 22:47:00 +02:00
PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
2016-09-08 10:35:53 +02:00
2018-03-01 00:17:49 +01:00
if [ ! -d "$PELICAN_BLOG_INSTALL_DIR" ]; then
mkdir -p "$PELICAN_BLOG_INSTALL_DIR"
2016-09-07 21:44:32 +02:00
fi
2017-03-26 13:36:52 +02:00
if [ ! -d $PELICAN_BLOG_PATH ]; then
mkdir -p $PELICAN_BLOG_PATH
2016-09-07 21:44:32 +02:00
fi
2018-03-01 00:17:49 +01:00
if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/content" ]; then
mkdir -p "$PELICAN_BLOG_INSTALL_DIR/content"
2016-09-08 10:35:53 +02:00
fi
2016-09-07 21:44:32 +02:00
2018-03-01 00:17:49 +01:00
create_pelican_conf "$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
create_pelican_makefile "$PELICAN_BLOG_INSTALL_DIR/Makefile"
create_pelican_publish_conf "$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
2016-09-07 21:44:32 +02:00
2018-03-01 00:17:49 +01:00
mkdir -p "$PELICAN_THEMES_REPO" "$PELICAN_BLOG_INSTALL_DIR/themes"
cd "$PELICAN_BLOG_INSTALL_DIR/themes" || exit 45357282883
2016-10-16 13:51:04 +02:00
pelican_themes
2016-09-10 20:23:49 +02:00
2017-03-26 13:36:52 +02:00
#git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
2016-09-07 21:44:32 +02:00
2018-03-01 00:17:49 +01:00
chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
2017-03-26 13:36:52 +02:00
chown -R www-data:www-data $PELICAN_BLOG_PATH
2017-03-26 13:50:52 +02:00
pelican_editor_config
2017-03-31 23:36:59 +02:00
PELICAN_ONION_HOSTNAME=$(add_onion_service pelican 80 ${PELICAN_ONION_PORT})
set_completion_param "pelican onion domain" "$PELICAN_ONION_HOSTNAME"
2017-03-31 22:47:00 +02:00
install_pelican_website
install_pelican_website_onion
2017-03-31 23:59:30 +02:00
pelican_regenerate_blog
2018-03-01 00:17:49 +01:00
if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
2017-04-01 00:57:14 +02:00
echo $'Failed to generate pelican blog'
exit 521892
fi
2017-03-31 23:59:30 +02:00
2017-03-31 22:47:00 +02:00
function_check nginx_ensite
nginx_ensite $PELICAN_DOMAIN_NAME
systemctl restart nginx
2016-10-10 20:11:33 +02:00
APP_INSTALLED=1
2016-09-07 21:44:32 +02:00
}
# NOTE: deliberately no exit 0