-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg.sh
executable file
·345 lines (296 loc) · 9.55 KB
/
pkg.sh
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/bash
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Text Trix code.
#
# The Initial Developer of the Original Code is
# Text Flex.
# Portions created by the Initial Developer are Copyright (C) 2003, 2017,
# 2018 the Initial Developer. All Rights Reserved.
#
# Contributor(s): David Young <[email protected]>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
################################
# Help
################################
HELP="
Packages both binary and source code archives of Text Trix. Assumes
that the binaries have already been built, typically using build.sh.
Syntax:
pkg.sh [options]
Parameters:
--help: Lends a hand by displaying yours truly.
--java=javac/binary/path: Specifies the path to javac,
jar, and other Java tools necessary for compilation.
Alternatively, the JAVA variable in pkg.sh can be hand-edited
to specify the path, which would override any command-line
specification. On Linux, this path defaults to
"/usr/java/default/bin", the new link found in Java 6.
--prefix=install/location: the directory in which to install Text Trix.
Defaults to "/usr/share".
--timestamp: adds a mm-dd-yy-hh\'h\'mm timestamp to each package
--ver=version: The version number to append to the package names.
Copyright:
Copyright (c) 2003, 2018 Text Flex
Last updated:
2018-05-12
"
#####################
# User-defined variables
# Check them!
####################
# version number
DATE=`date +'%Y-%m-%d-%Hh%M'`
TIMESTAMP=0
VER="1.3.0"
# the final destination of the resulting packages
PREFIX=""
# the root directory of the source files
BASE_DIR=""
# compiler location
JAVA=""
LAUNCH4J="launch4j"
LAUNCH4J_CONFIG="launch4j-config.xml"
##############################
# System setup
##############################
# Sets the base directory to the script location
if [ "x$BASE_DIR" = "x" ] # empty string
then
BASE_DIR=`dirname $0`
fi
cd "$BASE_DIR"
BASE_DIR="$PWD"
##############
# Respond to user arguments
##############
PAR_JAVA="--java"
PAR_PLUGINS="--plugins"
PAR_PLUG="--plug"
PAR_API="--api"
PAR_CHANGELOG="--log"
PAR_PREFIX="--prefix"
PAR_TIMESTAMP="--timestamp"
PAR_VER="--ver"
if [ $# -gt 0 ]
then
for arg in "$@"
do
# reads arguments
if [ "x$arg" = "x--help" -o "x$arg" = "x-h" ] # help docs
then
if [ "`command -v more`" != '' ]
then
echo "$HELP" | more
elif [ "`command -v less`" != "" ]
then
echo "$HELP" | less
else
echo "$HELP"
fi
exit 0
# Java path
elif [ ${arg:0:${#PAR_JAVA}} = "$PAR_JAVA" ]
then
JAVA="${arg#${PAR_JAVA}=}"
echo "Set to use \"$JAVA\" as the Java compiler path"
# install location
elif [ ${arg:0:${#PAR_PREFIX}} = "$PAR_PREFIX" ]
then
PREFIX="${arg#${PAR_PREFIX}=}"
echo "Set to use \"$PREFIX\" as the install path"
# verion number, which overrides default version
elif [ ${arg:0:${#PAR_VER}} = "$PAR_VER" ]
then
VER="${arg#${PAR_VER}=}"
echo "...set to use \"$VER\" as the version number..."
# timestamp labeling
elif [ ${arg:0:${#PAR_TIMESTAMP}} = "$PAR_TIMESTAMP" ]
then
TIMESTAMP=1
VER="$VER-$DATE"
echo "Set to label packages with \"$VER\""
fi
done
fi
# The working directory is the directory from which this script is run
WK_DIR="$PWD"
# initial output directory
BLD_DIR="$WK_DIR/build"
# Sets the texttrix and plugin source directories
TTX_DIR="$BASE_DIR" # texttrix folder within main dir
PLGS_DIR="${BASE_DIR}/../plugins" # plugins src folder
DIR="com/textflex/texttrix" # src package structure
# Platform and GUI detection
source "$BASE_DIR"/build-setup.sh
##############################
# Build operations
##############################
NAME="texttrix" # UNIX program name
DIR="com/textflex/$NAME" # Java package directory structure
PKGDIR="$NAME-$VER" # name of binary package
PKG=$PKGDIR.zip # name of compressed binary package
SRCPKGDIR="$PKGDIR-src" # name of source package
SRCPKG="$SRCPKGDIR.zip" # name of compressed package of source
JAR="TextTrix.jar" # executable jar
ALL="$PKGDIR $PKG $PKG14DIR $PKG14 $SRCPKGDIR $SRCPKG"
# create build directory if doesn't already exist
if [ ! -d "$BLD_DIR" ]
then
mkdir "$BLD_DIR"
fi
# attempt to clean up build directory
if [ -d "$BLD_DIR" ]
then
cd "$BLD_DIR" # base of operations
rm -rf $ALL
else
echo "Sorry, but $BLD_DIR isn't a directory,"
echo "so I won't be very useful."
echo "Goodbye."
exit 1
fi
##########
# Packaging
echo "Packaging the files..."
# set up new package directories
mkdir $PKGDIR
mkdir $PKGDIR/plugins
mkdir -p $PKGDIR/$DIR/images
cp -rf "$TTX_DIR"/$CLASSES_DIR/com "$TTX_DIR"/readme.txt \
"$TTX_DIR"/README.md \
"$TTX_DIR"/changelog.txt "$TTX_DIR"/lib \
"$TTX_DIR/$DIR"/license.txt "$TTX_DIR"/logo.ico \
"$TTX_DIR"/dictionaries "$TTX_DIR"/run.bat \
"$TTX_DIR"/$LAUNCH4J_CONFIG $PKGDIR
cp "$TTX_DIR"/$DIR/images/*.png $PKGDIR/$DIR/images
cp "$TTX_DIR"/$DIR/*.txt "$TTX_DIR"/$DIR/*.html $PKGDIR/$DIR
JORTHO_DIR=com/inet/jortho
cp -rf "$TTX_DIR"/$JORTHO_DIR/i18n $PKGDIR/$JORTHO_DIR
# create binary package
cd "$BLD_DIR/$PKGDIR"
# remove unnecessary files and directories
rm -rf com/.svn com/*/.svn com/*/*/.svn com/*/*/*/.svn dictionaries/.svn dictionaries/User*
# create source package
cd $BLD_DIR
mkdir $SRCPKGDIR
cp -rf $PKGDIR $SRCPKGDIR/texttrix
cp -rf "${TTX_DIR}/../jsyntaxpanettx" "${TTX_DIR}/../osterttx" "$SRCPKGDIR"
# add the build files
cd "$TTX_DIR"
cp -rf pkg.sh run.sh manifest-additions.mf build*.sh plug.sh README.md \
"$BLD_DIR/$SRCPKGDIR"/texttrix
sed 's/build:/build: '$DATE'/' $DIR/about.txt > \
"$BLD_DIR/$SRCPKGDIR"/texttrix/$DIR/about.txt
# add the plugins, copying the entire folder
# WARNING: Remove any unwanted contents from this folder, as the whole folder
# is currently copied, with only specific files later removed.
cd "$BLD_DIR"
cp -rf $PLGS_DIR $SRCPKGDIR
rm $PKGDIR/README.md # remove source-specific files for binary package
cp "$TTX_DIR"/plugins/*.jar $BLD_DIR/$PKGDIR/plugins # only want jars in binary package
# create binary package
# create/package binaries
cd $BLD_DIR/$PKGDIR
rm -rf com
# create JAR from source package and remove binary files from source
cd $BLD_DIR/$SRCPKGDIR/texttrix
# self-executable jar via "java -jar [path to jar]/$JAR.jar", where $JAR is named above
if [ "$CYGWIN" = "true" ]
then
"$JAVA"jar -cfm "`cygpath -p -w $BLD_DIR/$PKGDIR/$JAR`" "`cygpath -p -w manifest-additions.mf`" $DIR/*.class $DIR/*.txt $DIR/images/*.png $DIR/*.html com/inet
else
"$JAVA"jar -cfm $BLD_DIR/$PKGDIR/$JAR manifest-additions.mf $DIR/*.txt $DIR/*.class $DIR/images/*.png $DIR/*.html com/inet
fi
# make executable so can be run as binary on systems where jexec is installed
chmod 755 $BLD_DIR/$PKGDIR/$JAR
find . -type f -name "*.class" -delete
# Builds launch4j executable
echo -n "Creating Windows executable file..."
cd $BLD_DIR/$PKGDIR
L4J_EXE="$WK_DIR/$LAUNCH4J/launch4j"
if [ -e $L4J_EXE ]
then
L4J_PATH="$BLD_DIR/$PKGDIR/$LAUNCH4J_CONFIG"
if [ "$CYGWIN" = "true" ]
then
L4J_PATH=`cygpath -wp $L4J_PATH`
fi
$L4J_EXE $L4J_PATH
# waits until exe file is built since launch4j appears to run
# in a separate process
while [ ! -f "$BLD_DIR/$PKGDIR/TextTrix.exe" ]
do
sleep 2
done
else
echo -n "could not find launch4j...skipping..."
fi
rm $L4J_PATH
echo "done"
# finish the source package
cd $BLD_DIR/$SRCPKGDIR
# replace classes-oriented com with full com directory
rm -rf texttrix/com
cp -rf "$TTX_DIR"/com texttrix
# clean up classes, git, and backup files
rm -f plugins/*.jar
rm -f texttrix/lib/*.jar
find . -type f -name "*.class" -delete
find . -type d -name "classes" | xargs rm -rf
find . -type d -name ".git" | xargs rm -rf
find . -type f -name ".gitignore" | xargs rm -rf
find . -type f -name "*~" | xargs rm -rf
mv texttrix/*.txt texttrix/*.md .
# Add PKGDIR-specific files
cp $TTX_DIR/$DIR/images/minicon-32x32.png $BLD_DIR/$PKGDIR/icon.png
# zip up and move to PREFIXination
cd $BLD_DIR
cp $PKGDIR/$JAR $TTX_DIR
echo -n "Creating $PKG package..."
zip -rq $PKG $PKGDIR
echo "done"
echo -n "Creating $SRCPKG package..."
zip -rq $SRCPKG $SRCPKGDIR
echo "done"
echo ""
if [ -d "$PREFIX" ]
then
cd "$PREFIX"
rm -rf $ALL # removes any lingering Text Trix build pkgs in PREFIX dir
cd "$BLD_DIR"
mv $ALL "$PREFIX" # moves pkgs to PREFIX
cd "$PREFIX"
echo "Packages output to $PREFIX"
else
echo "Packages output to $BLD_DIR"
fi
# "latest" link to the current packages
rm -f latest latest-src
ln -s $PKGDIR latest
ln -s $SRCPKGDIR latest-src
exit 0