Welcome to mirror list, hosted at ThFree Co, Russian Federation.

extract_mini.sh « tools - github.com/jappix/jappix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8d88871da88ad97f8bdc40fdf8b049f3a308ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
#
# Jappix - An open social platform
#
# This script extracts a PHP-independent version of
# Jappix Mini under the AGPL or the MPLv2.
#
# -------------------------------------------------
#
# License: WTFPL
# Authors: Leberwurscht, Valérian Saliou
#

#
# Usage example:
# --------------
#
# - $ ./extract_mini.sh
# - move the newly created mini/ directory onto your webserver
# - Create index.html:
#     <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
#     <script type="text/javascript" src="/mini/javascripts/mini.js"></script>
#     <script type="text/javascript">
#       jQuery(document).ready(function() {
#         JAPPIX_STATIC = "/mini/";
#         HOST_BOSH = "https://bind.jappix.com/"
#
#         JappixMini.launch({
#           connection: {
#             user: 'username',
#             password: 'password',
#             domain: 'server.tld'
#           },
#           application: {
#             network: {
#               autoconnect: true
#             },
#             interface: {
#               showpane: false
#             }
#           }
#         });
#       });
#     </script>
#

# absolute path to script
ABSPATH=$(cd "$(dirname "$0")"; pwd)

# standard settings
BASE_DIR="$ABSPATH/.."
SOURCE_DIR="$BASE_DIR/app"
TARGET_DIR="$BASE_DIR/mini"
LICENSE=MPL

# parse command line options
while getopts "t:l:h" opt; do
  case $opt in
    t) # target directory
      TARGET_DIR="$OPTARG"
      ;;
    l) # license setting
      case $OPTARG in
        MPL)
          LICENSE=MPL
          ;;
        AGPL)
          LICENSE=AGPL
          ;;
        *)
          echo "Invalid license '$OPTARG' - need MPL or AGPL" >&2
          exit 1
          ;;
      esac
      ;;
    h) # help
      echo "Usage: $0 [-h] [-t TARGET_DIR] [-l MPL|AGPL]" >&2
      exit 1
      ;;
  esac
done

# set compatible licenses and file header
if [ "$LICENSE" == "MPL" ]; then
  COMPATIBLE_LICENSES="PD MPL MIT WTFPL"
  LICENSE_HEADER='/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *'
fi
if [ "$LICENSE" == "AGPL" ]; then
  COMPATIBLE_LICENSES="PD MPL MIT WTFPL AGPL GPL"
  LICENSE_HEADER='/*
 * 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/>.
 *'
fi

LICENSE_HEADER="$LICENSE_HEADER"'
 *
 * This compound file may be composed of several subfiles by different authors.
 * The particular authors, copyright information, disclaimers and alternative
 * licenses for the subfiles are indicated in separate headers.
 *
 */'

# create directory
if [ -e "$TARGET_DIR" ]; then
  echo "Target directory '$TARGET_DIR' already exists. Doing nothing." >&2
  exit 1
else
  echo "Extracting Jappix Mini into directory '$TARGET_DIR'" >&2
  mkdir "$TARGET_DIR"
fi

mkdir "$TARGET_DIR/stylesheets/"
mkdir "$TARGET_DIR/javascripts/"
mkdir "$TARGET_DIR/images/"

# define license check function
check_license()
{
  filename=$1
  allowed_licenses=$2

  # find licenses line of this file
  LICENSES="`head $filename | grep -i 'Licenses\?:\|Licensed under'`"

  # make sure this line contains a compatible license
  match=0
  matching_license=""
  for license in $allowed_licenses; do
    if [ `echo $LICENSES | grep -c "\(\W\|\<\)$license\(\W\|\>\)"` -gt 0 ]; then
      match=1
      matching_license="$license"
    fi
    if [ $license == "MPL" -a `echo $LICENSES | grep -c "\(\W\|\<\)\(Mozilla Public License version 1.1\|MPLv2\)\(\W\|\>\)"` -gt 0 ]; then
      match=1
      matching_license="$license"
    fi
  done
  if [ $match -eq 0 ]; then
    echo >&2
    echo "ERROR: Could not detect a $LICENSE-compatible license for file '$filename'!" >&2
    rm -r -- "$TARGET_DIR"
    exit 1
  else
    echo "$filename detected to be licensed under the $LICENSE-compatible license $matching_license:"
    echo -en "\t"
    echo "$LICENSES"
  fi
}

# create compound javascript file
echo "$LICENSE_HEADER" > "$TARGET_DIR/javascripts/mini.js"

JS_FILES="`cat $SOURCE_DIR/bundles/mini.xml | sed -n "s/.*<js>\(.*\)<\/js>.*/\1/p" | sed "s/~/ /g"`"
for js_file in $JS_FILES; do
  check_license "$SOURCE_DIR/javascripts/$js_file" "$COMPATIBLE_LICENSES"

  # add to compound file removing UTF-8 byte order mark
  cat "$SOURCE_DIR/javascripts/$js_file" | sed s/^\\xef\\xbb\\xbf// >> "$TARGET_DIR/javascripts/mini.js"
done

# simple configuraton
cat >> "$TARGET_DIR/javascripts/mini.js" << EOF

// Configuration
XML_LANG = 'en';
JAPPIX_VERSION = jQuery.trim('`cat $BASE_DIR/VERSION`');
JAPPIX_STATIC = '/mini/';
EOF

# create compound style sheet file
echo "$LICENSE_HEADER" > "$TARGET_DIR/stylesheets/mini.css"

CSS_FILES="`cat $SOURCE_DIR/bundles/mini.xml | sed -n "s/.*<css>\(.*\)<\/css>.*/\1/p" | sed "s/~/ /g"`"
for css_file in $CSS_FILES; do
  check_license "$SOURCE_DIR/stylesheets/$css_file" "$COMPATIBLE_LICENSES"

  # add to compound file removing UTF-8 byte order mark
  cat "$SOURCE_DIR/stylesheets/$css_file" | sed s/^\\xef\\xbb\\xbf// >> "$TARGET_DIR/stylesheets/mini.css"
done

# copy artwork
# mini.png, mini.gif, animate.png and animate.gif are licensed under CC-BY
mkdir -p "$TARGET_DIR/images/sprites/"
cp "$SOURCE_DIR/images/sprites/mini.gif" "$TARGET_DIR/images/sprites/mini.gif"
cp "$SOURCE_DIR/images/sprites/mini.png" "$TARGET_DIR/images/sprites/mini.png"
cp "$SOURCE_DIR/images/sprites/animate.png" "$TARGET_DIR/images/sprites/animate.png"
cp "$SOURCE_DIR/images/sprites/animate.gif" "$TARGET_DIR/images/sprites/animate.gif"

# copy wait-typing.gif
mkdir -p "$TARGET_DIR/images/wait/"
cp "$SOURCE_DIR/images/wait/wait-typing.gif" "$TARGET_DIR/images/wait/wait-typing.gif"

# copy blank.gif
mkdir -p "$TARGET_DIR/images/others/"
cp "$SOURCE_DIR/images/others/blank.gif" "$TARGET_DIR/images/others/blank.gif"

# copy sounds
# receive-message.mp3, receive-message.oga are licensed under CC-BY
mkdir -p "$TARGET_DIR/sounds/"
cp "$SOURCE_DIR/sounds/receive-message.mp3" "$TARGET_DIR/sounds/receive-message.mp3"
cp "$SOURCE_DIR/sounds/receive-message.oga" "$TARGET_DIR/sounds/receive-message.oga"

# license information
cat > "$TARGET_DIR/COPYING" << EOF
Code
----

The code is licensed under the $LICENSE, as indicated in the source files.

Artwork
-------

The files ./app/images/sprites/mini.png, ./app/images/sprites/mini.gif, ./app/images/sprites/animate.png, ./app/images/sprites/animate.gif and ./app/images/wait/wait-typing.gif were created by
Valérian Saliou and are dual-licensed under the Creative Commons Attribution 2.5
License and the Creative Commons Attribution 3.0 License.
They contain work from the FamFamFam Silk icon set by Mark James.

 * http://famfamfam.com/lab/icons/silk/
 * http://creativecommons.org/licenses/by/2.5/
 * http://creativecommons.org/licenses/by/3.0/
EOF