Command for setting blog avatar

This commit is contained in:
Bob Mottram 2016-03-23 15:18:29 +00:00
parent 20a7e5c96b
commit b22631766d
3 changed files with 143 additions and 0 deletions

BIN
man/freedombone-blog.1.gz Normal file

Binary file not shown.

140
src/freedombone-blog Executable file
View File

@ -0,0 +1,140 @@
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Blogging functions
# License
# =======
#
# Copyright (C) 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/>.
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

View File

@ -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