root/main/trunk/greenstone2/perllib/cpan/compile-zerossl.sh @ 32479

Revision 32479, 10.1 KB (checked in by ak19, 11 months ago)

Rename tmp folder to something more sensible and now works out what the perl version is using Dr Bainbridge's one-line assignment and uses this in the perl folder name

  • Property svn:executable set to *
Line 
1###################################################
2# A basic cascade-make to install the Crypt::LE perl package required for ZeroSSL, to be used to get an https certificate on Mac
3#
4# Crypt::LE depends on the following packages:
5# - Crypt::OpenSSL::Bignum, which needs openssl/err.h
6#   for which we need to set C_INCLUDE_PATH=$GSDL3SRCHOME/bin/darwin/openssl/include
7#   see https://www.perlmonks.org/?node_id=1181472
8#      "If includes arent in default compiler findable directories, let the user add any extra directories, like he is supposed to
9#       http://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html like C_INCLUDE_PATH/LIBRARY_PATH... "
10# - JSON::MaybeXS, which depends on
11#     - JSON::PP
12# - Time::Piece
13# - HTTP::Tiny
14# - Module::Load
15# - Log::Log4perl
16#
17#
18# Compiling AND INSTALLING of all packages takes place in the temporary cpan/tmp folder. A select subset of the compiled/installed
19# products are then copied into their final destinations:
20# - For regular packages, need to put the relevant products (the package folder inside the lib folder) into cpan, maintaining any
21# existing folder structure.
22# - However, for all packages that contain .bundle (mac, or .so for linux) and .xs or .bs bootstrap files, need to put the relevant
23# products (both the "auto" and package folder inside the lib folder) into cpan/perl-<version> ($PERL_FOLDER, e.g. "perl-5.18").
24# In this case, both Crypt::OpenSSL and Time::Piece once compiled up require this second treatment.
25#
26# Compiling as well as RUNNING the final Crypt::LE's le.pl executable requires PERL5LIB to have both the cpan and its $PERL_FOLDER
27# subdirectory included in env var PERL5LIB.
28#
29###################################################
30
31if [ "x$1" = "x--help" ] || [ "x$1" = "x-h" ]; then
32    echo "Usage: $0 [--clean|--keep|--help|-h]"
33    echo "  Run without flags to compile and remove unnecessary stuff at the end."
34    echo "  Run with --keep to retain the cpan/tmp subdir at compilation's end."
35    echo "  Run with --clean to remove all traces of compilation completely so you can recompile from scratch"
36    echo "  Run with --help/-h to see this Usage statement again"
37    exit 0
38fi
39
40if [ "x$GSDL3SRCHOME" = "x" ] ; then
41    echo "GSDL3SRCHOME not set, sourcing gs3-setup.sh"
42    echo ""
43    cd ../../..
44    source ./gs3-setup.sh
45    cd $GSDLHOME/perllib/cpan
46fi
47
48echo ""
49echo "**************************"
50
51CPAN_DIR=$GSDLHOME/perllib/cpan
52OLD_PERL5LIB=$PERL5LIB
53
54# PERL_FOLDER is something like "$PERL_FOLDER" (even if the full version number is 5.18.2)
55PERL_FOLDER=`perl -e 'print "perl-5.".substr($],3,2);'`
56
57# make the dirs cpan/$PERL_FOLDER and its subdir auto if they don't already exist
58mkdir -p $CPAN_DIR/$PERL_FOLDER/auto
59
60# dependencies are not found if PERL5LIB is simply set to cpan. PERL5LIB Needs to specifically be exported
61export PERL5LIB=$CPAN_DIR:$CPAN_DIR/$PERL_FOLDER:$PERL5LIB
62
63#echo "**** PERL5LIB is $PERL5LIB"
64
65
66WGET_FLAGS=--no-check-certificate
67# folder where we'll put the downloaded files, the compile products and the temporary install products
68# after everything is installed there, we copy just the relevant installed files to their final locations
69# then the tmp file gets deleted
70TEMP_DIR=$CPAN_DIR/tmp-crypt-le
71
72
73OLD_C_INCLUDE_PATH=$C_INCLUDE_PATH
74
75# if clean was passed in
76if [ "x$1" = "x--clean" ] ; then
77    cd $CPAN_DIR
78    rm -rf $PERL_FOLDER/Crypt $PERL_FOLDER/Time $PERL_FOLDER/auto/Crypt $PERL_FOLDER/auto/Time Log JSON/MaybeXS.pm Log Module JSON/PP.pm JSON/PP Crypt/LE Crypt/LE.pm
79    mv JSON/PP.old JSON/PP
80    mv JSON/PP.pm_old JSON/PP.pm
81    rm -rf $TEMP_DIR
82    echo "Done cleaning Crypt::LE related packages"
83    exit 0
84fi
85
86mkdir -p $TEMP_DIR
87# We'll download, unpack and compile (Makefile.PL, make and make install) packages into TEMP_DIR
88# before copying the necessary components to their final locations
89cd $TEMP_DIR
90
91
92# First run through the dependencies and then finally Crypt::LE itself
93
94# 1 https://metacpan.org/pod/Crypt::OpenSSL::Bignum
95if [ ! -d "$CPAN_DIR/$PERL_FOLDER/Crypt/OpenSSL/Bignum" ]; then
96    CRYPT_OPENSSL_BIGNUM=Crypt-OpenSSL-Bignum
97    CRYPT_OPENSSL_BIGNUM_VER=$CRYPT_OPENSSL_BIGNUM-0.09
98    echo "+ Installing $CRYPT_OPENSSL_BIGNUM"
99    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/K/KM/KMX/$CRYPT_OPENSSL_BIGNUM_VER.tar.gz
100    tar -xvzf $CRYPT_OPENSSL_BIGNUM_VER.tar.gz
101   
102    export C_INCLUDE_PATH=$GSDL3SRCHOME/bin/darwin/openssl/include
103    cd $CRYPT_OPENSSL_BIGNUM_VER
104    perl Makefile.PL PREFIX=$TEMP_DIR/$CRYPT_OPENSSL_BIGNUM
105    make
106    make install
107    #cp -r $TEMP_DIR/$CRYPT_OPENSSL_BIGNUM/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/Crypt/OpenSSL $CPAN_DIR/Crypt/.
108    cp -r $TEMP_DIR/Crypt-OpenSSL-Bignum/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/Crypt $CPAN_DIR/$PERL_FOLDER/.
109    cp -r $TEMP_DIR/Crypt-OpenSSL-Bignum/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/auto/Crypt $CPAN_DIR/$PERL_FOLDER/auto/.
110
111    C_INCLUDE_PATH=
112    cd $TEMP_DIR
113else
114    echo "*** $CPAN_DIR/Crypt/OpenSSL/Bignum already exists, not installing"
115fi
116
117
118# 2a https://metacpan.org/pod/JSON::PP
119# which is the minimum dependency for JSON::MaybeXS
120
121if [ ! -f "$CPAN_DIR/JSON/PP.pm_old" ]; then
122    mv $CPAN_DIR/JSON/PP $CPAN_DIR/JSON/PP.old
123    mv $CPAN_DIR/JSON/PP.pm $CPAN_DIR/JSON/PP.pm_old
124
125    JSON_PP=JSON-PP
126    JSON_PP_VER=$JSON_PP-2.97001
127    echo "+ Installing $JSON_PP"
128    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/I/IS/ISHIGAKI/$JSON_PP_VER.tar.gz
129    tar -xvzf $JSON_PP_VER.tar.gz
130
131    cd $JSON_PP_VER
132    perl Makefile.PL PREFIX=$TEMP_DIR/$JSON_PP
133    make
134    make install
135    cp -r $TEMP_DIR/$JSON_PP/lib/perl5/site_perl/JSON/* JSON $CPAN_DIR/JSON/.
136
137    cd $TEMP_DIR
138else
139    echo "*** The new $CPAN_DIR/JSON/PP.pm already exists, not installing"
140fi
141
142
143# 2 https://metacpan.org/pod/JSON::MaybeXS
144
145if [ ! -f "$CPAN_DIR/JSON/MaybeXS.pm" ]; then
146    JSON_MAYBEXS=JSON-MaybeXS
147    JSON_MAYBEXS_VER=$JSON_MAYBEXS-1.004000
148    echo "+ Installing $JSON_MAYBEXS"
149    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/H/HA/HAARG/$JSON_MAYBEXS_VER.tar.gz
150    tar -xvzf $JSON_MAYBEXS_VER.tar.gz
151
152    cd $JSON_MAYBEXS_VER
153    perl Makefile.PL PREFIX=$TEMP_DIR/$JSON_MAYBEXS
154    make
155    make install
156    cp $TEMP_DIR/$JSON_MAYBEXS/lib/perl5/site_perl/JSON/MaybeXS.pm $CPAN_DIR/JSON/.
157
158    cd $TEMP_DIR
159else
160    echo "*** $CPAN_DIR/JSON/MaybeXS.pm already exists, not installing"
161fi
162
163
164# 3 https://metacpan.org/pod/Log::Log4perl
165
166if [ ! -d "$CPAN_DIR/Log/Log4perl" ]; then
167    LOG4PERL=Log-Log4perl
168    LOG4PERL_VER=$LOG4PERL-1.49
169    echo "+ Installing $LOG4PERL"
170    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/M/MS/MSCHILLI/$LOG4PERL_VER.tar.gz
171    tar -xvzf $LOG4PERL_VER.tar.gz
172
173    cd $LOG4PERL_VER
174    perl Makefile.PL PREFIX=$TEMP_DIR/$LOG4PERL
175    make
176    make install
177    cp -r $TEMP_DIR/$LOG4PERL/lib/perl5/site_perl/Log $CPAN_DIR/.
178
179    cd $TEMP_DIR
180else
181    echo "*** $CPAN_DIR/Log/Log4Perl already exists, not installing"
182fi
183
184# 4 https://metacpan.org/pod/HTTP::Tiny
185
186if [ ! -f "$CPAN_DIR/HTTP/Tiny.pm" ]; then
187    HTTP_TINY=HTTP-Tiny
188    HTTP_TINY_VER=$HTTP_TINY-0.076
189    echo "+ Installing $HTTP_TINY"
190    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/D/DA/DAGOLDEN/$HTTP_TINY_VER.tar.gz
191    tar -xvzf $HTTP_TINY_VER.tar.gz
192
193    cd $HTTP_TINY_VER
194    perl Makefile.PL PREFIX=$TEMP_DIR/$HTTP_TINY
195    make
196    make install
197
198    cp -r $TEMP_DIR/$HTTP_TINY/lib/perl5/site_perl/HTTP/* $CPAN_DIR/HTTP/.
199
200    cd $TEMP_DIR
201else
202    echo "*** $CPAN_DIR/$HTTP_TINY already exists, not installing"
203fi
204
205
206# 5 https://metacpan.org/pod/Module::Load
207
208if [ ! -d "$CPAN_DIR/Module" ]; then
209    MODULE_LOAD=Module-Load
210    MODULE_LOAD_VER=$MODULE_LOAD-0.32
211    echo "+ Installing $MODULE_LOAD"
212    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/B/BI/BINGOS/$MODULE_LOAD_VER.tar.gz
213    tar -xvzf $MODULE_LOAD_VER.tar.gz
214
215    cd $MODULE_LOAD_VER
216    perl Makefile.PL PREFIX=$TEMP_DIR/$MODULE_LOAD
217    make
218    make install
219    cp -r $TEMP_DIR/$MODULE_LOAD/lib/perl5/site_perl/Module $CPAN_DIR/.
220
221    cd $TEMP_DIR
222else
223    echo "*** $CPAN_DIR/$MODULE_LOAD already exists, not installing"
224fi
225
226
227# 6 https://metacpan.org/pod/Time::Piece
228
229if [ ! -f "$CPAN_DIR/$PERL_FOLDER/Time/Piece.pm" ]; then
230    TIME_PIECE=Time-Piece
231    TIME_PIECE_VER=$TIME_PIECE-1.33
232    echo "+ Installing $TIME_PIECE"
233    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/E/ES/ESAYM/$TIME_PIECE_VER.tar.gz
234    tar -xvzf $TIME_PIECE_VER.tar.gz
235
236    cd $TIME_PIECE_VER
237    perl Makefile.PL PREFIX=$TEMP_DIR/$TIME_PIECE
238    make
239    make install
240
241    #cp -r $TEMP_DIR/$TIME_PIECE/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/Time $CPAN_DIR/.
242    cp -r $TEMP_DIR/$TIME_PIECE/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/Time $CPAN_DIR/$PERL_FOLDER
243    cp -r $TEMP_DIR/$TIME_PIECE/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/auto/Time $CPAN_DIR/$PERL_FOLDER/auto/.
244
245    cd $TEMP_DIR
246else
247    echo "*** $CPAN_DIR/$TIME_PIECE already exists, not installing"
248fi
249
250
251
252# FINALLY, compile up Crypt::LE
253# https://metacpan.org/pod/Crypt::LE
254
255if [ ! -d "$CPAN_DIR/Crypt/LE" ]; then
256    CRYPT_LE=Crypt-LE
257    CRYPT_LE_VER=$CRYPT_LE-0.31
258    echo "+ FINALLY, Installing $CRYPT_LE"
259    wget $WGET_FLAGS https://cpan.metacpan.org/authors/id/L/LE/LEADER/$CRYPT_LE_VER.tar.gz
260    tar -xvzf $CRYPT_LE_VER.tar.gz
261
262    cd $CRYPT_LE_VER
263    perl Makefile.PL PREFIX=$TEMP_DIR/$CRYPT_LE
264    make
265    make install
266
267    cp -r $TEMP_DIR/$CRYPT_LE/lib/perl5/site_perl/Crypt/* $CPAN_DIR/Crypt/.
268    # the most important step: we need the le.pl binary
269    cp -r $TEMP_DIR/$CRYPT_LE/bin $CPAN_DIR/Crypt/LE/.
270
271    cd $CPAN_DIR
272else
273    echo "*** $CPAN_DIR/$CRYPT_LE already exists, not installing"
274fi
275
276
277# DONE
278
279echo "*****************************"
280echo "*** Done compiling Crypt::LE."
281if [ "x$1" != "x--keep" ] ; then
282    echo "    Will now delete tmp subdir"
283    rm -rf tmp
284else
285    echo "   Not deleting the $TEMP_DIR"
286fi
287
288# restore env vars
289C_INCLUDE_PATH=$OLD_C_INCLUDE_PATH
290PERL5LIB=$OLD_PERL5LIB
291
292# for this export line to work, would need to source ./compile-zerossl.sh
293#export PERL5LIB=$CPAN_DIR:$CPAN_DIR/$PERL_FOLDER:$PERL5LIB
294
295echo "Restored environment"
296echo "You can now run $CPAN_DIR/Crypt/LE/bin/le.pl after exporting PERL5LIB to contain both cpan and cpan/$PERL_FOLDER. Do:"
297echo "   export PERL5LIB=$CPAN_DIR:$CPAN_DIR/$PERL_FOLDER:$PERL5LIB"
Note: See TracBrowser for help on using the browser.