From b22631766ddad65682d68da014dd325387575510 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 23 Mar 2016 15:18:29 +0000 Subject: [PATCH] Command for setting blog avatar --- man/freedombone-blog.1.gz | Bin 0 -> 398 bytes src/freedombone-blog | 140 ++++++++++++++++++++++++++++++++++++++ src/freedombone-upgrade | 3 + 3 files changed, 143 insertions(+) create mode 100644 man/freedombone-blog.1.gz create mode 100755 src/freedombone-blog diff --git a/man/freedombone-blog.1.gz b/man/freedombone-blog.1.gz new file mode 100644 index 0000000000000000000000000000000000000000..f4725f5555a6c5afacdfe2e4f589577310771989 GIT binary patch literal 398 zcmV;90df8xiwFRBukuy^18tB|Yuhjsh2QlnE`HgQ?KXwcg)tU)nG@C|Cbn0$ZWPJB zu|zG&NLPjZ`zayaIyxaFknZ`;xi@Q8aBzsd)xsJ~#b^h(gk*LF8}49sarriZB<|0D zi=g%B-uPHx0v{8`vU&x{cClF|>=o-r3dQjbQ_l(E5KKqP8h=*R-?qD|Uf2IorV{R@ z^<=olpOA96=TDqsD5d#;5ZnmX!9k69syG8bE$f^8x@y+DZNeIQTzpo>X@z=BL0h@4sH`H#Ga@3`_z50GZ9oG5`Po literal 0 HcmV?d00001 diff --git a/src/freedombone-blog b/src/freedombone-blog new file mode 100755 index 00000000..7936f0d8 --- /dev/null +++ b/src/freedombone-blog @@ -0,0 +1,140 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# Blogging functions + +# License +# ======= +# +# Copyright (C) 2016 Bob Mottram +# +# 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}-blog +export TEXTDOMAINDIR="/usr/share/locale" + +CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg + +HOSTNAME= +AVATAR= + +# get the blog hostname +if grep -q "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE; then + HOSTNAME=$(grep "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}') +fi + +BASE_DIR=/var/www/$HOSTNAME/htdocs + +function show_help { + echo '' + echo $"${PROJECT_NAME}-blog -h [hostname] -a [avatar image file]" + echo '' + echo $'Creates a self-signed certificate for the given hostname' + echo '' + echo $' --help Show help' + echo $' -h --hostname [name] Hostname' + echo $' -a --avatar [url] Filename or url for avatar' + echo '' + exit 0 +} + +while [[ $# > 1 ]] +do + key="$1" + + case $key in + --help) + show_help + ;; + -h|--hostname) + shift + HOSTNAME="$1" + ;; + -a|--avatar) + shift + AVATAR="$1" + ;; + *) + # unknown option + ;; + esac + shift +done + +if [ ! $HOSTNAME ]; then + echo $'No hostname specified' + exit 5748 +fi + +if [ ! -d $BASE_DIR ]; then + echo "$BASE_DIR was not found" + exit 1 +fi + +function set_avatar_from_file { + SOURCE_IMAGE_FILE="$1" + + if [ ! -f $SOURCE_IMAGE_FILE ]; then + echo $'Source file not found' + exit 2 + fi + + # copy the source image + cd $BASE_DIR + AVATAR_FILES=$(find . -name avatar.png) + read -a arr <<<$AVATAR_FILES + + for i in "${arr[@]}" + do + FILENAME="$BASE_DIR$(echo \"$i\" | awk -F '.' '{print $2}')".png + if [[ "$FILENAME" != "$SOURCE_IMAGE_FILE" ]]; then + cp -f $SOURCE_IMAGE_FILE "$FILENAME" + fi + done +} + +function set_avatar_from_url { + if [ ! -d $BASE_DIR/customimages ]; then + mkdir $BASE_DIR/customimages + fi + + # download the image + cd $BASE_DIR/customimages + wget $AVATAR -O avatar.png + if [ ! -f $BASE_DIR/customimages/avatar.png ]; then + echo $'Avatar image could not be downloaded' + exit 3 + fi + chown -R www-data:www-data $BASE_DIR/customimages +} + +if [[ "$AVATAR" == "http"* ]]; then + set_avatar_from_url +fi + +AVATAR=$BASE_DIR/customimages/avatar.png +if [ -f $AVATAR ]; then + set_avatar_from_file $AVATAR +fi + +exit 0 diff --git a/src/freedombone-upgrade b/src/freedombone-upgrade index d83b585f..67ea61f7 100755 --- a/src/freedombone-upgrade +++ b/src/freedombone-upgrade @@ -158,6 +158,9 @@ if [ -f /etc/init.d/sipwitch ]; then rm -f /etc/init.d/sipwitch fi +# update blog avatar +${PROJECT_NAME}-blog + echo ' ' | reset-tripwire