Browse Source

Command for setting blog avatar

Bob Mottram 9 years ago
parent
commit
b22631766d
3 changed files with 143 additions and 0 deletions
  1. BIN
      man/freedombone-blog.1.gz
  2. 140
    0
      src/freedombone-blog
  3. 3
    0
      src/freedombone-upgrade

BIN
man/freedombone-blog.1.gz View File


+ 140
- 0
src/freedombone-blog View File

@@ -0,0 +1,140 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Blogging functions
12
+
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+PROJECT_NAME='freedombone'
32
+
33
+export TEXTDOMAIN=${PROJECT_NAME}-blog
34
+export TEXTDOMAINDIR="/usr/share/locale"
35
+
36
+CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
37
+
38
+HOSTNAME=
39
+AVATAR=
40
+
41
+# get the blog hostname
42
+if grep -q "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE; then
43
+    HOSTNAME=$(grep "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
44
+fi
45
+
46
+BASE_DIR=/var/www/$HOSTNAME/htdocs
47
+
48
+function show_help {
49
+    echo ''
50
+    echo $"${PROJECT_NAME}-blog -h [hostname] -a [avatar image file]"
51
+    echo ''
52
+    echo $'Creates a self-signed certificate for the given hostname'
53
+    echo ''
54
+    echo $'     --help                     Show help'
55
+    echo $'  -h --hostname [name]          Hostname'
56
+    echo $'  -a --avatar [url]             Filename or url for avatar'
57
+    echo ''
58
+    exit 0
59
+}
60
+
61
+while [[ $# > 1 ]]
62
+do
63
+    key="$1"
64
+
65
+    case $key in
66
+        --help)
67
+            show_help
68
+            ;;
69
+        -h|--hostname)
70
+            shift
71
+            HOSTNAME="$1"
72
+            ;;
73
+        -a|--avatar)
74
+            shift
75
+            AVATAR="$1"
76
+            ;;
77
+        *)
78
+            # unknown option
79
+            ;;
80
+    esac
81
+    shift
82
+done
83
+
84
+if [ ! $HOSTNAME ]; then
85
+    echo $'No hostname specified'
86
+    exit 5748
87
+fi
88
+
89
+if [ ! -d $BASE_DIR ]; then
90
+    echo "$BASE_DIR was not found"
91
+    exit 1
92
+fi
93
+
94
+function set_avatar_from_file {
95
+    SOURCE_IMAGE_FILE="$1"
96
+
97
+    if [ ! -f $SOURCE_IMAGE_FILE ]; then
98
+        echo $'Source file not found'
99
+        exit 2
100
+    fi
101
+    
102
+    # copy the source image
103
+    cd $BASE_DIR
104
+    AVATAR_FILES=$(find . -name avatar.png)
105
+    read -a arr <<<$AVATAR_FILES
106
+
107
+    for i in "${arr[@]}"
108
+    do      
109
+        FILENAME="$BASE_DIR$(echo \"$i\" | awk -F '.' '{print $2}')".png
110
+        if [[ "$FILENAME" != "$SOURCE_IMAGE_FILE" ]]; then
111
+            cp -f $SOURCE_IMAGE_FILE "$FILENAME"
112
+        fi      
113
+    done    
114
+}
115
+
116
+function set_avatar_from_url {
117
+    if [ ! -d $BASE_DIR/customimages ]; then
118
+        mkdir $BASE_DIR/customimages
119
+    fi
120
+
121
+    # download the image
122
+    cd $BASE_DIR/customimages
123
+    wget $AVATAR -O avatar.png
124
+    if [ ! -f $BASE_DIR/customimages/avatar.png ]; then
125
+        echo $'Avatar image could not be downloaded'
126
+        exit 3
127
+    fi
128
+    chown -R www-data:www-data $BASE_DIR/customimages
129
+}
130
+
131
+if [[ "$AVATAR" == "http"* ]]; then
132
+    set_avatar_from_url
133
+fi
134
+
135
+AVATAR=$BASE_DIR/customimages/avatar.png
136
+if [ -f $AVATAR ]; then
137
+    set_avatar_from_file $AVATAR
138
+fi
139
+
140
+exit 0

+ 3
- 0
src/freedombone-upgrade View File

@@ -158,6 +158,9 @@ if [ -f /etc/init.d/sipwitch ]; then
158 158
     rm -f /etc/init.d/sipwitch
159 159
 fi
160 160
 
161
+# update blog avatar
162
+${PROJECT_NAME}-blog
163
+
161 164
 echo '
162 165
 
163 166
 ' | reset-tripwire