source: genapp/sbin/install.pl @ 1657

Last change on this file since 1657 was 1657, checked in by ehb, 3 years ago

Update Imagemagick link & centos 7.6 support

File size: 43.7 KB
Line 
1#!/usr/bin/perl
2
3my $gb   = $ENV{ "GENAPP" } || die "$0: environment variable GENAPP must be set\n";
4
5print "perl version is $]\n" if $debug;
6print "command is: $0 @ARGV\n" if $debug;
7
8if ( $] < 5.018 ) {
9    if ( -e "$gb/perl/bin/perl" ) {
10        $pv =`$gb/perl/bin/perl -e 'print \$];'`;
11        if ( $pv >= 5.018 ) {
12            print "will run new version\n" if $debug;
13            unshift @ARGV, $0;
14            exec( "$gb/perl/bin/perl", @ARGV );
15        } else {
16            die "$gb/perl/bin/perl exists, but not a correct version of perl (needs a minimum of 5.18)\n";
17        }
18    } else {
19        die "you need to install a version of perl >= 5.18 in $gb/perl\n
20there is a script $gb/sbin/install-perl-stable to do this";
21    }
22}
23
24# configuration
25
26my $appbase = "/opt/genapp";
27
28# uncomment for debugguing
29# $debug++;
30
31# end configuration
32
33use JSON -support_by_pp;
34
35my $home = $ENV{ "HOME" } || die "$0: environment variable HOME must be set\n";
36
37$sorry = "------------------------------------------------------------
38We are sorry that your operating system / release is not currently supported.
39Please let us know your requirements and we can likely provide an install script to work with your system.
40You can subscribe to the mailing list http://biochem.uthscsa.edu/mailman/listinfo/genapp-devel
41and then send your questions to genapp-devel\@biochem.uthscsa.edu
42------------------------------------------------------------
43";
44
45# utility subs
46
47sub runcmd {
48    my $cmd = $_[0];
49    my $out;
50    print "running shell command:\n--------\n$cmd\n--------\n" if $debug;
51    open my $fh, "$cmd |";
52    while ( <$fh> ) {
53        $out .= $_;
54        print;
55    }
56    close $fh;
57    die "$0: command $cmd failed\n" if $?;
58    $out;
59}
60
61sub runcmdsb {
62    my $cmd = $_[0];
63    $cmd =~ s/"/\\\"/g;
64    $cmd = "sudo bash -c \"$cmd\"";
65    print "sd cmd is <$cmd>\n";
66    runcmd( $cmd );
67}
68
69sub add_to_phpini {
70    my $phpfile = shift;
71
72    die "$0: $phpfile does not exist\n" if !-e $phpfile;
73    die "$0: $phpfile is not readable\n" if !-r $phpfile;
74
75    open my $fh, $phpfile || die "$0: error reading $phpfile\n";
76    my @phpini = <$fh>;
77    close $fh;
78
79    my @phpext = grep ( /extension\s*=/, @phpini );
80    @phpext = grep ( !/\s*;/, @phpext );
81    @phpext = grep ( s/^\s*extension\s*=\s*//, @phpext );
82    @phpext = grep ( s/^\s*//g, @phpext );
83    @phpext = grep ( s/\.so//, @phpext );
84    grep chomp, @phpext;
85
86    my %hasext;
87    foreach my $i ( @phpext ) {
88        $hasext{ $i }++;
89    }
90
91    my $add;
92    foreach my $check ( @_ ) {
93        if ( !$hasext{ $check } ) {
94            $add .= "; Enable $check extension module\nextension=${check}.so\n";
95        }
96    }
97    my $cmd;
98    if ( $add ) {
99        $cmd = "cat <<_EOF >> $phpfile\n${add}_EOF\n";
100    }
101    return $cmd;
102}
103
104# get system configuration information
105my $cfgjson = {};
106my $cfgjsonf = "$gb/etc/config.json";
107my $cfgjsonnotes = '-'x80 . "\n
108$cfgjsonf contains global system information.
109this is used to setup individual applications values.
110to build a default config.json file
111$gb/sbin/setconfig.pl -pj
112and verify the information is correct.
113NB: if the machine is not publically exposed, you probably want to change the hostip and hostname, as it will likely report the public ip of your firewall.
114    You can get a full set of options listed by running $gb/sbin/setconfig.pl -h
115    If you know the ethernet interface to run on, $gb/sbin/setconfig.pl -if network-interface-id can be helpful
116    The -f option will force the changes to a previously set $cfgjsonf file
117    The full options are listed by $gb/sbin/setconfig.pl -h
118    You can also manually edit $cfgjsonf
119
120Once you are satisified that the setting are correct
121you can rerun $gb/sbin/install
122" . '-'x80 . "\n"
123;
124
125# get config info
126
127{
128    my $f = $cfgjsonf;
129    if ( -e $f ) {
130        print "reading $f\n";
131        open my $fh, $f || die "$0: can not open $f\n";
132        my @ol = <$fh>;
133        close $fh;
134        my @l = grep !/^\s*#/ , @ol;
135            my $l = join '', @l;
136        eval {
137            $cfgjson = decode_json( $l );
138            1;
139        } || do {
140            my $e = $@;
141           
142            # figure out line #
143
144            my ( $cp ) = $e =~ /at character offset (\d+) /;
145            my $i;
146            my $cpos = $cp;
147            for ( $i = 0; $i < @ol; ++$i ) {
148                next if $ol[ $i ] =~ /^\s*#/;
149                    $cpos -= length( $ol[ $i ] );
150                last if $cpos < 0;
151            }
152
153            my $sline = $i - 2;
154            my $eline = $i + 2;
155            $sline = 0 if $sline < 0;
156            $eline = @ol - 1 if $eline >= @ol;
157
158            print "JSON Error in file $f near these lines:\n";
159            for ( my $j = $sline; $j <= $eline; ++$j ) {
160                my $uj = $j + 1;
161                print "$uj: $ol[$j]";
162                print "$uj: " .'^'x(length($ol[$j])) . "\n" if $j == $i;
163            }
164            die;
165        };
166    } else {
167        my $res = `$gb/sbin/setconfig.pl -pj`;
168        print "$0 :
169" . '-'x80 . "
170please verify these settings are correct
171" . '-'x80 . "
172$res
173$cfgjsonnotes
174";
175        exit;
176    }
177}
178
179die "$0: no webroot defined in $cfgjson
180please verify and correct before proceeding
181
182$cfgjsonnotes
183" if !$$cfgjson{ 'webroot' };
184
185if ( !$$cfgjson{ 'lockdir' } ) {
186    $$cfgjson{ 'lockdir' } = "$gb/etc";
187}
188
189die "$0: no messaging:wsport defined in $cfgjson
190please verify and correct before proceeding
191
192$cfgjsonnotes
193" if !$$cfgjson{ 'messaging' }{ 'wsport' };
194
195$wsport = $$cfgjson{ 'messaging' }{ 'wsport' };
196
197# screen os / os_release
198
199my $os = $$cfgjson{ 'os' } || die "$0: $cfgjsonf does not contain an 'os' tag. $cfgjsonnotes";
200my $os_release = $$cfgjson{ 'os_release' } || die "$0: $cfgjsonf does not contain an 'os_release' tag. $cfgjsonnotes";
201
202if ( $os eq 'ubuntu' ) {
203    die "only ubuntu 14.04, 16.04 and 18.04 are currently supported and this appears to be version $os_release\n$sorry" if $os_release != 14.04 && $os_release != 16.04 && $os_release != 18.04;
204}
205
206if ( $os eq 'centos' ) {
207    die "only Centos 6.7, 6.8, 6.9, 7.2, 7.3, 7.4, 7.5 and 7.6 are currently supported and this appears to be version $os_release\n$sorry" if $os_release !~ /^6\.(7|8|9)$/ && $os_release !~ /^7\.(2|3|4|5|6)/;
208}
209
210if ( $os eq 'redhat' ) {
211    die "only Red Hat Enterprise Linux Server 6.7, 6.8, 7.5 and 7.6 are currently supported and this appears to be version $os_release\n$sorry" if $os_release !~ /^6\.(7|8)$/ && $os_release !~ /^7\.(5|6)/;
212}   
213
214if ( $os eq 'slackware' ) {
215    die "slackware install not currently supported\n";
216}
217
218my $whoami = `whoami`;
219chomp $whoami;
220
221my $CPUS=`grep processor /proc/cpuinfo | wc -l`;
222grep chomp $CPUS;
223$CPUS = 1 if !$CPUS;
224$CPUS *= 2;
225
226# ------ ubuntu 14.04 ------
227
228if ( $os eq 'ubuntu' && $os_release == 14.04 ) {
229    # install required modules
230
231    runcmd( "sudo apt-get -y install mlocate build-essential apache2 libzmq-dev libapache2-mod-php5 php-pear php5-imagick php-mail php-mail-mime php5-mongo php5-dev mongodb pkg-config re2c uuid-dev abiword wget" );
232    runcmdsb( "yes '' | pecl install uuid zmq-beta" );
233
234    # zmq to php
235
236    runcmdsb( "cat <<_EOF > /etc/php5/mods-available/zmq.ini
237; configuration for php zmq module
238; priority=20
239extension=zmq.so
240_EOF
241php5enmod zmq" );
242
243    # add pcntl to php
244
245    my $pcntl_so_exists = `cd /usr/lib/php5/20*/ ; ls -1 pcntl.so`;
246   
247    if ( $pcntl_so_exists !~ /pcntl.so/ ) {
248        runcmdsb( "mkdir /tmp/phpsource
249cd /tmp/phpsource
250apt-get source php5
251cd /tmp/phpsource/php5-*/ext/pcntl
252phpize
253./configure
254make
255cd modules
256cp pcntl.so /usr/lib/php5/20*/
257cat <<_EOF > /etc/php5/mods-available/pcntl.ini
258; configuration for php pcntl module
259; priority=20
260extension=pcntl.so
261_EOF
262" );
263    } else {
264        print "skipped pcntl.so module install since preexisting\n";
265    }
266    runcmdsb( "sed \"s/^disable_functions = pcntl/\;disable_functions = pcntl/\" /etc/php5/apache2/php.ini > /tmp/_php.ini
267cp /etc/php5/apache2/php.ini{,.org}
268mv /tmp/_php.ini /etc/php5/apache2/php.ini
269#php5enmod pcntl" );
270
271    # add proxy support for ws, wss
272    runcmdsb( "cat <<_EOF > /etc/apache2/mods-available/wsproxy.conf
273# ws proxy pass
274# priority=20
275ProxyPass /ws2 ws://localhost:$wsport/
276_EOF
277cat <<_EOF > /etc/apache2/mods-available/wsproxy.load
278_EOF
279cat <<_EOF > /etc/apache2/mods-available/wssproxy.conf
280# wss proxy pass
281# priority=20
282ProxyPass /wss2 ws://localhost:$wsport/
283_EOF
284cat <<_EOF > /etc/apache2/mods-available/wssproxy.load
285_EOF
286");
287    runcmd( "sudo a2enmod proxy proxy_wstunnel wsproxy" );
288
289    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
290
291    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
292        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
293    }
294
295    # make the base of the genapp instances directory, create group genapp, add user & www-data to genapp group
296
297    runcmdsb( "mkdir -p $appbase
298groupadd genapp
299useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
300chmod g+rwx $appbase
301chown $whoami:genapp $appbase
302chmod g+s $appbase
303mkdir $$cfgjson{'lockdir'}
304chown genapp:genapp $$cfgjson{'lockdir'}
305chmod g+rwx $$cfgjson{'lockdir'}
306usermod -g users -G genapp $whoami
307usermod -G genapp \'www-data\'
308chgrp -R genapp $gb
309chmod g+w $gb/etc
310" );
311
312    # setup local system definitions
313
314    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
315export GENAPP=$gb
316export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
317_EOF
318" );
319
320    # php info for debugging
321   
322    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
323<?php
324phpinfo();
325?>
326_EOF
327" );
328
329    # setup genapptest instance
330
331    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
332
333    # apache2 security needed ?
334
335    runcmdsb( "cat <<_EOF >> /etc/apache2/conf-enabled/security.conf
336# add Alias /genapptest $$cfgjson{'webroot'}/genapptest
337<Directory $$cfgjson{'webroot'}/genapptest>
338 Options FollowSymLinks
339 AllowOverride None
340 Order Allow,Deny
341 Allow from all
342</Directory>
343<Directory /var/www/>
344        Options FollowSymLinks
345        AllowOverride None
346        Require all granted
347</Directory>
348_EOF
349" );
350
351    # add ws servers to startup
352
353    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d
354update-rc.d rc.genapp defaults 99
355update-rc.d mongodb defaults" );
356
357    # start ws servers
358    runcmdsb( "sg genapp -c '/etc/init.d/rc.genapp start'" );
359
360# restart apache2
361
362    runcmd( "sudo service apache2 restart" );
363    exit();
364}
365
366# ------ centos 6.7 & 6.8 & 6.9 -------
367if ( $os eq 'centos' && ( $os_release == 6.7 || $os_release == 6.8 || $os_release == 6.9 ) ) {
368    # install required modules
369
370#    runcmdsb( "rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm" );
371    runcmdsb( "yum -y groupinstall 'Development tools'" );
372    runcmdsb( "yum -y install centos-release-scl" );
373
374    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-devel rh-php56-php rh-php56-php-devel rh-php56-php-pear rh-php56-php-pecl-mongo mongodb mongodb-server wget libuuid-devel zeromq-devel openssl-devel ImageMagick ImageMagick-devel" );
375# old commands
376#    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-devel httpd24-php55 http24-php55w-devel httpd24--pecl-imagick mongodb mongodb-server pkg-config wget libuuid-devel zeromq-devel openssl-devel" );
377#    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-develhttpd24-php55 http24-php55w-devel httpd24--pecl-imagick mongodb mongodb-server pkg-config wget libuuid-devel zeromq-devel openssl-devel" );
378#-zmq php-pecl-http php-pear php-pecl-imagick php-mail php-mail-mime php-pecl-mongo php-devel mongodb mongodb-server pkg-config re2c php-pecl-uuid wget" );
379
380    my $rhsclphp    = "/opt/rh/rh-php56/root";
381    my $rhsclphpetc = "/etc/opt/rh/rh-php56/";
382    my $rhsclhttpd  = "/opt/rh/httpd24/root";
383
384    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl install uuid zmq-beta mongo imagick;
385cat <<_EOF > $rhsclphpetc/php.d/uuid.ini
386; Enable uuid extension module
387extension=uuid.so
388_EOF
389cat <<_EOF > $rhsclphpetc/php.d/zmq.ini
390; Enable zmq extension module
391extension=zmq.so
392_EOF
393cat <<_EOF > $rhsclphpetc/php.d/imagick.ini
394; Enable imagick extension module
395extension=imagick.so
396_EOF
397#cat <<_EOF > $rhsclphpetc/php.d/mongo.ini
398#; Enable mongo extension module
399#extension=mongo.so
400#_EOF
401" );
402
403    runcmdsb( "scl enable rh-php56 'pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.5'" );
404    runcmdsb( "scl enable rh-php56 'pear install --alldeps Mail Mail_Mime Net_SMTP'" );
405
406    `sudo killall mongod 2> /dev/null`;
407    runcmdsb( "service mongod start" );
408
409    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
410# ws proxy pass
411# priority=20
412ProxyPass /ws2 ws://localhost:$wsport/
413ProxyPass /wss2 ws://localhost:$wsport/
414_EOF
415cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
416SetEnv GENAPP $gb
417_EOF
418");
419
420    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
421<Directory \"$rhsclhttpd/var/www/html\">
422    Options FollowSymLinks
423    AllowOverride None
424    Require all granted
425</Directory>
426_EOF
427");
428
429    # scl puts php in $rhsclphp so link it
430
431    runcmdsb( "ln -sf $rhsclphp/usr/bin/php /usr/bin/php" );
432
433    # scl puts httpd root in $rhsclphp so link it
434
435    if ( -e "/var/www" ) {
436        if ( -d "/var/www" || -f "/var/www" ) {
437            my $bdir = "/var/www.previous";
438            my $ext ;
439            while ( -e $bdir ) {
440               $ext++;
441               $bdir = "/var/www.previous-$ext";
442            }
443            $warnings .= "/var/www is backed up in $bdir";
444            runcmdsb( "mv /var/www $bdir" );
445        } else {
446            runcmdsb( "rm /var/www" );
447        }
448    }
449
450    runcmdsb( "ln -sf $rhsclhttpd/var/www /var/www" );
451
452    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
453
454    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
455        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
456    }
457
458    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
459
460    runcmdsb( "mkdir -p $appbase
461groupadd genapp
462useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
463chmod g+rwx $appbase
464chown $whoami:genapp $appbase
465chmod g+s $appbase
466mkdir $$cfgjson{'lockdir'}
467chown genapp:genapp $$cfgjson{'lockdir'}
468chmod g+rwx $$cfgjson{'lockdir'}
469usermod -g users -G genapp $whoami
470usermod -G genapp \'apache\'
471chgrp -R genapp $gb
472chmod g+w $gb/etc
473" );
474
475    # setup local system definitions
476
477    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
478export GENAPP=$gb
479export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
480_EOF
481cat <<_EOF > /etc/profile.d/genapp.csh
482setenv GENAPP $gb
483setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
484_EOF
485
486" );
487
488    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
489<?php
490phpinfo();
491?>
492_EOF
493" );
494
495    # setup genapptest instance
496
497    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
498
499    # add ws servers to startup
500
501    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
502    runcmdsb( "chkconfig --add rc.genapp" );
503    runcmdsb( "/etc/init.d/rc.genapp start" );
504
505    # open ports
506    {
507        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
508        chomp $iptab;
509        if ( $iptab !~ /tcp/ ) {
510            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
511service iptables save" );
512        }
513    }
514    if ( $$cfgjson{ 'https' } ) {
515        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
516        chomp $iptab;
517        if ( $iptab !~ /tcp/ ) {
518            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
519service iptables save" );
520        }
521    }
522
523    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
524    exit();
525}
526
527# ------ centos 7.2,7.3,7.4,7.5 -------
528if ( $os eq 'centos' && $os_release =~ /^7\.(2|3|4|5|6)/ ) {
529
530    # install required modules
531
532#    runcmdsb( "rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm" );
533    runcmdsb( "yum -y groupinstall 'Development tools'" );
534    runcmdsb( "yum -y install centos-release-scl" );
535
536    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-devel rh-php56-php rh-php56-php-devel rh-php56-php-pear rh-php56-php-pecl-mongo mongodb mongodb-server wget libuuid-devel zeromq-devel openssl-devel ImageMagick ImageMagick-devel" );
537# old commands
538#    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-devel httpd24-php55 http24-php55w-devel httpd24--pecl-imagick mongodb mongodb-server pkg-config wget libuuid-devel zeromq-devel openssl-devel" );
539#    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-develhttpd24-php55 http24-php55w-devel httpd24--pecl-imagick mongodb mongodb-server pkg-config wget libuuid-devel zeromq-devel openssl-devel" );
540#-zmq php-pecl-http php-pear php-pecl-imagick php-mail php-mail-mime php-pecl-mongo php-devel mongodb mongodb-server pkg-config re2c php-pecl-uuid wget" );
541
542    my $rhsclphp    = "/opt/rh/rh-php56/root";
543    my $rhsclphpetc = "/etc/opt/rh/rh-php56/";
544    my $rhsclhttpd  = "/opt/rh/httpd24/root";
545
546    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl install uuid zmq-beta mongo imagick;
547cat <<_EOF > $rhsclphpetc/php.d/uuid.ini
548; Enable uuid extension module
549extension=uuid.so
550_EOF
551cat <<_EOF > $rhsclphpetc/php.d/zmq.ini
552; Enable zmq extension module
553extension=zmq.so
554_EOF
555cat <<_EOF > $rhsclphpetc/php.d/imagick.ini
556; Enable imagick extension module
557extension=imagick.so
558_EOF
559#cat <<_EOF > $rhsclphpetc/php.d/mongo.ini
560#; Enable mongo extension module
561#extension=mongo.so
562#_EOF
563" );
564
565    runcmdsb( "scl enable rh-php56 'pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.5'" );
566    runcmdsb( "scl enable rh-php56 'pear install --alldeps Mail Mail_Mime Net_SMTP'" );
567
568    `sudo killall mongod 2> /dev/null`;
569    runcmdsb( "service mongod start" );
570
571    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
572# ws proxy pass
573# priority=20
574ProxyPass /ws2 ws://localhost:$wsport/
575ProxyPass /wss2 ws://localhost:$wsport/
576_EOF
577cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
578SetEnv GENAPP $gb
579_EOF
580");
581
582    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
583<Directory \"$rhsclhttpd/var/www/html\">
584    Options FollowSymLinks
585    AllowOverride None
586    Require all granted
587</Directory>
588_EOF
589");
590
591    # scl puts php in $rhsclphp so link it
592
593    runcmdsb( "ln -sf $rhsclphp/usr/bin/php /usr/bin/php" );
594
595    # scl puts httpd root in $rhsclphp so link it
596
597    if ( -e "/var/www" ) {
598        if ( -d "/var/www" || -f "/var/www" ) {
599            my $bdir = "/var/www.previous";
600            my $ext ;
601            while ( -e $bdir ) {
602               $ext++;
603               $bdir = "/var/www.previous-$ext";
604            }
605            $warnings .= "/var/www is backed up in $bdir";
606            runcmdsb( "mv /var/www $bdir" );
607        } else {
608            runcmdsb( "rm /var/www" );
609        }
610    }
611
612    runcmdsb( "ln -sf $rhsclhttpd/var/www /var/www" );
613
614    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
615
616    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
617        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
618    }
619
620    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
621
622    runcmdsb( "mkdir -p $appbase
623groupadd genapp
624useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
625chmod g+rwx $appbase
626chown $whoami:genapp $appbase
627chmod g+s $appbase
628mkdir $$cfgjson{'lockdir'}
629chown genapp:genapp $$cfgjson{'lockdir'}
630chmod g+rwx $$cfgjson{'lockdir'}
631usermod -g users -G genapp $whoami
632usermod -G genapp \'apache\'
633chgrp -R genapp $gb
634chmod g+w $gb/etc
635" );
636
637    # setup local system definitions
638
639    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
640export GENAPP=$gb
641export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
642_EOF
643cat <<_EOF > /etc/profile.d/genapp.csh
644setenv GENAPP $gb
645setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
646_EOF
647
648" );
649
650    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
651<?php
652phpinfo();
653?>
654_EOF
655" );
656
657    # setup genapptest instance
658
659    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
660
661    # add ws servers to startup
662
663    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
664    runcmdsb( "chkconfig --add rc.genapp" );
665    runcmdsb( "/etc/init.d/rc.genapp start" );
666
667    # open ports
668    {
669        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
670        chomp $iptab;
671        if ( $iptab !~ /tcp/ ) {
672            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
673service iptables save" );
674        }
675    }
676    if ( $$cfgjson{ 'https' } ) {
677        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
678        chomp $iptab;
679        if ( $iptab !~ /tcp/ ) {
680            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
681service iptables save" );
682        }
683    }
684
685    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
686    exit();
687}
688
689# ------ redhat 6.x -------
690
691if ( $os eq 'redhat' && $os_release =~ /^6\.(2|3|4|5)/ ) {
692    # install required modules
693
694#    runcmdsb( "rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm" );
695    runcmdsb( "cat <<_EOF > /etc/yum.repos.d/mongodb.repo
696[mongodb]
697name=MongoDB Repository
698baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
699gpgcheck=0
700enabled=1
701_EOF
702# the 3.2 repo didn't seem to work
703#cat <<_EOF > /etc/yum.repos.d/mongodb-org-3.2.repo
704#[mongodb-org-3.2]
705#name=MongoDB Repository
706#baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.2/x86_64/
707#gpgcheck=1
708#enabled=1
709#gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
710#_EOF
711cat <<_EOF > /etc/yum.repos.d/mongodb-org-2.6.repo
712[mongodb-org-2.6]
713name=MongoDB 2.6 Repository
714baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
715gpgcheck=0
716enabled=1
717_EOF
718cat <<_EOF > /etc/yum.repos.d/fengshuo_zeromq.repo
719[home_fengshuo_zeromq]
720name=The latest stable of zeromq builds (CentOS_CentOS-6)
721type=rpm-md
722baseurl=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/
723gpgcheck=1
724gpgkey=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/repodata/repomd.xml.key
725enabled=1
726_EOF
727# semanage port -a -t mongod_port_t -p tcp 27017
728");
729
730    runcmdsb( "yum -y groupinstall 'Development tools'" );
731    runcmdsb( "yum-config-manager --enable rhel-server-rhscl-6-rpms" );
732    {
733        my @res = `sudo subscription-manager list --available --all 2>&1 | grep 'not yet registered'`;
734        die "$0: could not enable rhel-server-rhscl-6-rpms, the system does not appear to be registered. Try \$ sudo subscription-manager register --help" if @res;
735        @res = `sudo yum repolist 2> /dev/null | grep rhscl`;
736        die '-'x80 . "
737$0: you appeared to be registered, but need to attach to a pool.  you can use:
738\$ sudo subscription-manager list --available
739and identify a 'Pool ID:'=pool_id and then use that pool_id to
740\$ sudo subscription-manager attach --pool=pool_id
741" . '-'x80 . "
742You may also find info at this url:
743https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/2/html-single/2.1_Release_Notes/index.html#sect-Installation-Subscribe
744" . '-'x80 . "
745" if !@res;
746    }
747
748    runcmdsb( "yum -y install mlocate httpd24-httpd httpd24-httpd-devel rh-php56-php rh-php56-php-devel rh-php56-php-pear rh-php56-php-pecl-mongo mongodb-org mongodb-org-server wget libuuid-devel zeromq-devel openssl-devel libpng-devel libjpeg-devel fontconfig-devel freetype-devel fftw-devel libtiff-devel cairo-devel pango pango-devel" );
749
750    # need imagemagick from source :(
751    my $imversion = "ImageMagick-6.9.10-28.tar.xz";
752    runcmd( "rm -fr /tmp/$imversion 2>/dev/null;cd /tmp && wget http://imagemagick.org/download/releases/$imversion && tar Jxf $imversion && cd ImageMagick-* && ./configure && make -j$CPUS && sudo make install" ) if !-e "/usr/local/bin/MagickWand-config";
753
754    my $rhsclphp    = "/opt/rh/rh-php56/root";
755    my $rhsclphpetc = "/etc/opt/rh/rh-php56/";
756    my $rhsclhttpd  = "/opt/rh/httpd24/root";
757
758    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl channel-update pecl.php.net" );
759    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl install uuid zmq-beta mongo imagick;
760cat <<_EOF > $rhsclphpetc/php.d/uuid.ini
761; Enable uuid extension module
762extension=uuid.so
763_EOF
764cat <<_EOF > $rhsclphpetc/php.d/zmq.ini
765; Enable zmq extension module
766extension=zmq.so
767_EOF
768cat <<_EOF > $rhsclphpetc/php.d/imagick.ini
769; Enable imagick extension module
770extension=imagick.so
771_EOF
772#cat <<_EOF > $rhsclphpetc/php.d/mongo.ini
773#; Enable mongo extension module
774#extension=mongo.so
775#_EOF
776" );
777
778    runcmdsb( "scl enable rh-php56 'pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.5'" );
779    runcmdsb( "scl enable rh-php56 'pear install --alldeps Mail Mail_Mime Net_SMTP'" );
780
781    `sudo killall mongod 2> /dev/null`;
782    runcmdsb( "service mongod start" );
783
784    # add proxy support for ws, wss
785    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
786# ws proxy pass
787# priority=20
788ProxyPass /ws2 ws://localhost:$wsport/
789ProxyPass /wss2 ws://localhost:$wsport/
790_EOF
791cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
792SetEnv GENAPP $gb
793_EOF
794");
795
796    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
797<Directory \"$rhsclhttpd/var/www/html\">
798    Options FollowSymLinks
799    AllowOverride None
800    Require all granted
801</Directory>
802_EOF
803");
804
805    # scl puts php in $rhsclphp so link it
806
807    runcmdsb( "ln -sf $rhsclphp/usr/bin/php /usr/bin/php" );
808
809    # scl puts httpd root in $rhsclphp so link it
810
811    if ( -e "/var/www" ) {
812        if ( -d "/var/www" || -f "/var/www" ) {
813            my $bdir = "/var/www.previous";
814            my $ext ;
815            while ( -e $bdir ) {
816               $ext++;
817               $bdir = "/var/www.previous-$ext";
818            }
819            $warnings .= "/var/www is backed up in $bdir";
820            runcmdsb( "mv /var/www $bdir" );
821        } else {
822            runcmdsb( "rm /var/www" );
823        }
824    }
825     
826    runcmdsb( "ln -sf $rhsclhttpd/var/www /var/www" );
827
828    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
829
830    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
831        runcmdsb( "ln -s /usr/bin/php /usr/local/bin/php" );
832    }
833
834    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
835
836    runcmdsb( "mkdir -p $appbase
837groupadd genapp
838useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
839chmod g+rwx $appbase
840chown $whoami:genapp $appbase
841chmod g+s $appbase
842mkdir $$cfgjson{'lockdir'}
843chown genapp:genapp $$cfgjson{'lockdir'}
844chmod g+rwx $$cfgjson{'lockdir'}
845usermod -g users -G genapp $whoami
846usermod -G genapp \'apache\'
847chgrp -R genapp $gb
848chmod g+w $gb/etc
849" );
850
851    # setup local system definitions
852
853    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
854export GENAPP=$gb
855export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
856_EOF
857cat <<_EOF > /etc/profile.d/genapp.csh
858setenv GENAPP $gb
859setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
860_EOF
861
862" );
863
864    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
865<?php
866phpinfo();
867?>
868_EOF
869" );
870
871    # setup genapptest instance
872
873    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
874
875    # add ws servers to startup
876
877    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
878    runcmdsb( "chkconfig --add rc.genapp" );
879    runcmdsb( "/etc/init.d/rc.genapp start" );
880
881    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
882
883    {
884        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
885        chomp $iptab;
886        if ( $iptab !~ /tcp/ ) {
887            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
888service iptables save" );
889        }
890    }
891    if ( $$cfgjson{ 'https' } ) {
892        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
893        chomp $iptab;
894        if ( $iptab !~ /tcp/ ) {
895            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
896service iptables save" );
897        }
898    }
899
900#    runcmdsb( "service httpd restart && chkconfig httpd on" );
901    exit();
902}
903
904# ------ ubuntu 16.04 & 18.04 ------
905if ( $os eq 'ubuntu' && ( $os_release == 16.04 || $os_release == 18.04 ) ) {
906    # install required modules
907
908    my $zmqv = "3" if $os_release == 18.04;
909
910    runcmd( "sudo add-apt-repository -y ppa:ondrej/php && sudo apt-get -y update" );
911    runcmd( "sudo apt-get -y install mlocate build-essential apache2 php5.6-dev libapache2-mod-php5.6 php5.6-xml pkg-config re2c libzmq${zmqv}-dev uuid-dev abiword wget mongodb libmagickwand-6.q16-dev" );
912
913# php-pear php-imagick php-mail php-mail-mime php-mongodb mongodb" );
914
915    runcmdsb( "pear install --alldeps Mail Mail_Mime Net_SMTP" );
916    runcmdsb( "yes '' | pecl install uuid zmq-beta mongo imagick" );
917
918    # zmq to php
919
920    runcmdsb( "cat <<_EOF > /etc/php/5.6/mods-available/zmq.ini
921; configuration for php zmq module
922; priority=20
923extension=zmq.so
924_EOF
925cat <<_EOF > /etc/php/5.6/mods-available/imagick.ini
926; Enable imagick extension module
927extension=imagick.so
928_EOF
929cat <<_EOF > /etc/php/5.6/mods-available/mongo.ini
930; Enable mongo extension module
931extension=mongo.so
932_EOF
933phpenmod zmq mongo imagick" );
934
935    runcmdsb( "sed \"s/^disable_functions = pcntl/\;disable_functions = pcntl/\" /etc/php/5.6/apache2/php.ini > /tmp/_php.ini
936cp /etc/php/5.6/apache2/php.ini{,.org}
937mv /tmp/_php.ini /etc/php/5.6/apache2/php.ini
938#phpenmod pcntl" );
939
940    # add proxy support for ws, wss
941    runcmdsb( "cat <<_EOF > /etc/apache2/mods-available/wsproxy.conf
942# ws proxy pass
943# priority=20
944ProxyPass /ws2 ws://localhost:$wsport/
945_EOF
946cat <<_EOF > /etc/apache2/mods-available/wsproxy.load
947_EOF
948cat <<_EOF > /etc/apache2/mods-available/wssproxy.conf
949# wss proxy pass
950# priority=20
951ProxyPass /wss2 ws://localhost:$wsport/
952_EOF
953cat <<_EOF > /etc/apache2/mods-available/wssproxy.load
954_EOF
955");
956    runcmd( "sudo a2enmod proxy proxy_wstunnel wsproxy" );
957
958    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
959
960    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
961        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
962    }
963
964    # make the base of the genapp instances directory, create group genapp, add user & www-data to genapp group
965
966    runcmdsb( "mkdir -p $appbase
967groupadd genapp
968useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
969chmod g+rwx $appbase
970chown $whoami:genapp $appbase
971chmod g+s $appbase
972mkdir $$cfgjson{'lockdir'}
973chown genapp:genapp $$cfgjson{'lockdir'}
974chmod g+rwx $$cfgjson{'lockdir'}
975usermod -g users -G genapp $whoami
976usermod -G genapp \'www-data\'
977chgrp -R genapp $gb
978chmod g+w $gb/etc
979" );
980
981    # setup local system definitions
982
983    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
984export GENAPP=$gb
985export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
986_EOF
987" );
988
989    # php info for debugging
990   
991    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
992<?php
993phpinfo();
994?>
995_EOF
996" );
997
998    # setup genapptest instance
999
1000    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1001
1002    # apache2 security needed ?
1003
1004    runcmdsb( "cat <<_EOF >> /etc/apache2/conf-enabled/security.conf
1005# add Alias /genapptest $$cfgjson{'webroot'}/genapptest
1006<Directory $$cfgjson{'webroot'}/genapptest>
1007 Options FollowSymLinks
1008 AllowOverride None
1009 Order Allow,Deny
1010 Allow from all
1011</Directory>
1012<Directory /var/www/>
1013        Options FollowSymLinks
1014        AllowOverride None
1015        Require all granted
1016</Directory>
1017_EOF
1018" );
1019
1020    # add ws servers to startup
1021
1022    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d
1023update-rc.d rc.genapp defaults 99
1024update-rc.d mongodb defaults" );
1025
1026    # start ws servers
1027    runcmdsb( "/etc/init.d/rc.genapp start" );
1028
1029# restart apache2
1030
1031    runcmd( "sudo service apache2 restart" );
1032    exit();
1033}
1034
1035# ------ scientific linux 7.2 -------
1036if ( $os eq 'scientific' && $os_release =~ /^7\.(2|3|4)(cernvm|)/ ) {
1037
1038    my $cernvm;
1039    if ( $os_release =~ /cernvm$/ ) {
1040        $cernvm++;
1041    }
1042
1043    runcmdsb( "cat <<_EOF > /etc/yum.repos.d/mongodb.repo
1044[mongodb]
1045name=MongoDB Repository
1046baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
1047gpgcheck=0
1048enabled=1
1049_EOF
1050# the 3.2 repo didn't seem to work
1051#cat <<_EOF > /etc/yum.repos.d/mongodb-org-3.2.repo
1052#[mongodb-org-3.2]
1053#name=MongoDB Repository
1054#baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.2/x86_64/
1055#gpgcheck=1
1056#enabled=1
1057#gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
1058#_EOF
1059cat <<_EOF > /etc/yum.repos.d/mongodb-org-2.6.repo
1060[mongodb-org-2.6]
1061name=MongoDB 2.6 Repository
1062baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
1063gpgcheck=0
1064enabled=1
1065_EOF
1066cat <<_EOF > /etc/yum.repos.d/fengshuo_zeromq.repo
1067[home_fengshuo_zeromq]
1068name=The latest stable of zeromq builds (CentOS_CentOS-6)
1069type=rpm-md
1070baseurl=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/
1071gpgcheck=1
1072gpgkey=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/repodata/repomd.xml.key
1073enabled=1
1074_EOF
1075");
1076
1077    runcmdsb( "semanage port -l | grep mongod_port_t || semanage port -a -t mongod_port_t -p tcp 27017" ) if !$cernvm;
1078
1079    # install required modules
1080
1081#    runcmdsb( "rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm" );
1082    runcmdsb( "yum -y groupinstall 'Development tools'" ) if !$cernvm;
1083
1084    runcmdsb( "yum -y install mlocate wget httpd httpd-devel php php-devel php-pear openssl-devel libuuid-devel mongodb-org mongodb-org-server zeromq-devel" );
1085 
1086    if ( $cernvm ) {
1087        # need imagemagick from source :(
1088        my $imversion = "ImageMagick-6.9.10-28.tar.xz";
1089        runcmd( "rm -fr /tmp/$imversion 2>/dev/null; cd /tmp && wget http://imagemagick.org/download/releases/$imversion && tar Jxf $imversion && cd ImageMagick-* && ./configure && make -j$CPUS && sudo make install" ) if !-e "/usr/local/bin/MagickWand-config";
1090    } else {
1091        runcmdsb( "yum -y install ImageMagick ImageMagick-devel" );
1092    }
1093
1094    my $rhsclphp    = "";
1095    my $rhsclphpetc = "";
1096    my $rhsclhttpd  = "";
1097
1098    runcmdsb( "yes '' | pecl channel-update pecl.php.net" );
1099    runcmdsb( "yes '' | pecl install uuid zmq-beta mongo imagick" );
1100
1101    if ( my $cmd = add_to_phpini( '/etc/php.ini', 'uuid', 'zmq', 'imagick', 'mongo' ) ) {
1102        runcmdsb( $cmd );
1103    }
1104
1105    # rh-php56-php-pecl-mongo mongodb mongodb-server zeromq-devel" );
1106    runcmdsb( "yes '' | pear channel-update pear.php.net" );
1107    runcmdsb( "yes '' | pear install --alldeps Mail Mail_Mime Net_SMTP" );
1108
1109    `sudo killall mongod 2> /dev/null`;
1110    runcmdsb( "service mongod start
1111chkconfig mongod on
1112" );
1113
1114    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
1115# ws proxy pass
1116# priority=20
1117ProxyPass /ws2 ws://localhost:$wsport/
1118ProxyPass /wss2 ws://localhost:$wsport/
1119_EOF
1120cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
1121SetEnv GENAPP $gb
1122_EOF
1123");
1124
1125    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
1126<Directory \"$rhsclhttpd/var/www/html\">
1127    Options FollowSymLinks
1128    AllowOverride None
1129    Require all granted
1130</Directory>
1131_EOF
1132");
1133
1134    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
1135
1136    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
1137        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
1138    }
1139
1140    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
1141
1142    runcmdsb( "mkdir -p $appbase
1143groupadd genapp
1144useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
1145chmod g+rwx $appbase
1146chown $whoami:genapp $appbase
1147chmod g+s $appbase
1148mkdir $$cfgjson{'lockdir'} 2> /dev/null
1149chown genapp:genapp $$cfgjson{'lockdir'}
1150chmod g+rwx $$cfgjson{'lockdir'}
1151usermod -g users -G genapp $whoami
1152usermod -G genapp \'apache\'
1153chgrp -R genapp $gb
1154chmod g+w $gb/etc
1155" );
1156
1157    # setup local system definitions
1158
1159    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
1160export GENAPP=$gb
1161export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
1162_EOF
1163cat <<_EOF > /etc/profile.d/genapp.csh
1164setenv GENAPP $gb
1165setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
1166_EOF
1167
1168" );
1169
1170    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
1171<?php
1172phpinfo();
1173?>
1174_EOF
1175" );
1176
1177    # setup genapptest instance
1178
1179    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1180
1181    # add ws servers to startup
1182
1183    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
1184    runcmdsb( "chkconfig --add rc.genapp" );
1185    runcmdsb( "/etc/init.d/rc.genapp start" );
1186
1187    # open ports
1188    if ( !$cernvm ) {
1189        runcmdsb( "firewall-cmd --permanent --zone=public --add-service=http" );
1190        if ( $$cfgjson{ 'https' } ) {
1191            runcmdsb( "firewall-cmd --permanent --zone=public --add-service=https" );
1192        }
1193        runcmdsb( "systemctl restart firewalld.service" );
1194    }
1195
1196    runcmdsb( "semanage permissive -a httpd_t" ) if !$cernvm;
1197
1198    if ( $cernvm ) {
1199        runcmdsb( "sed --in-place=.prev 's/Listen .*:80/Listen 80/g' /etc/httpd/conf/httpd.conf" );
1200    }
1201
1202    runcmdsb( "systemctl restart httpd.service && systemctl enable httpd.service" );
1203    exit();
1204}
1205
1206# ------ redhat 7.x -------
1207
1208if ( $os eq 'redhat' && $os_release =~ /^7\.(5|6)/ ) {
1209    # install required modules
1210
1211    runcmdsb( "cat <<_EOF > /etc/yum.repos.d/mongodb-org-3.6.repo
1212[mongodb-org-3.6]
1213name=MongoDB Repository
1214baseurl=https://repo.mongodb.org/yum/redhat/_releasever/mongodb-org/3.6/x86_64/
1215gpgcheck=1
1216enabled=1
1217gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
1218_EOF
1219sed -i 's/_/\$/' /etc/yum.repos.d/mongodb-org-3.6.repo
1220# semanage port -a -t mongod_port_t -p tcp 27017
1221");
1222
1223
1224    runcmdsb( "yum-config-manager --enable rhel-server-rhscl-7-rpms" );
1225    {
1226        my @res = `sudo subscription-manager list --available --all 2>&1 | grep 'not yet registered'`;
1227        die "$0: could not enable rhel-server-rhscl-7-rpms, the system does not appear to be registered. Try \$ sudo subscription-manager register --help" if @res;
1228        @res = `sudo yum repolist 2> /dev/null | grep rhscl`;
1229        die '-'x80 . "
1230$0: you appeared to be registered, but need to attach to a pool.  you can use:
1231\$ sudo subscription-manager list --available
1232and identify a 'Pool ID:'=pool_id and then use that pool_id to
1233\$ sudo subscription-manager attach --pool=pool_id
1234" . '-'x80 . "
1235You may also find info at this url:
1236https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/2/html-single/2.1_Release_Notes/index.html#sect-Installation-Subscribe
1237" . '-'x80 . "
1238" if !@res;
1239    }
1240
1241    runcmdsb( "yum -y install mlocate git httpd24-httpd httpd24-httpd-devel rh-php56-php rh-php56-php-devel rh-php56-php-pear rh-php56-php-pecl-mongo mongodb-org mongodb-org-server wget libuuid-devel openssl-devel libpng-devel libjpeg-devel fontconfig-devel freetype-devel fftw-devel libtiff-devel cairo-devel pango pango-devel" );
1242
1243    # need zeromq from source :(
1244
1245    runcmd( "rm -fr /tmp/libzmq 2>/dev/null; cd /tmp && git clone git://github.com/zeromq/libzmq.git && cd libzmq && ./autogen.sh && ./configure && make -j$CPUS && make -j$CPUS check && sudo make -j$CPUS install && cat <<_EOF > /etc/ld.so.conf.d/zeromq.conf
1246/usr/local/lib
1247_EOF
1248sudo ldconfig
1249 " ) if !-e "/usr/local/lib/libzmq.so" || !-e "/etc/ld.so.conf.d/zeromq.conf";
1250
1251    # need imagemagick from source :(
1252    # might need fix to freetype2 https://bugzilla.redhat.com/show_bug.cgi?id=1651788
1253    if ( $os_release eq '7.6' ) {
1254        runcmdsb( "sed -i '801s/FT_ENCODING_PRC/FT_ENCODING_GB2312/' /usr/include/freetype2/freetype/freetype.h" );
1255    }
1256
1257    my $imversion = "ImageMagick-6.9.10-28.tar.xz";
1258    runcmd( "rm -fr /tmp/$imversion 2>/dev/null;cd /tmp && wget http://imagemagick.org/download/releases/$imversion && tar Jxf $imversion && cd ImageMagick-* && ./configure && make -j$CPUS && sudo make install" ) if !-e "/usr/local/bin/MagickWand-config";
1259
1260    my $rhsclphp    = "/opt/rh/rh-php56/root";
1261    my $rhsclphpetc = "/etc/opt/rh/rh-php56/";
1262    my $rhsclhttpd  = "/opt/rh/httpd24/root";
1263
1264    runcmdsb( "sed -i 's/PHP -C -n -q/PHP -C -q/' $rhsclphp/usr/bin/pecl" );
1265    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl channel-update pecl.php.net" );
1266    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl install uuid zmq-beta mongo imagick;
1267cat <<_EOF > $rhsclphpetc/php.d/uuid.ini
1268; Enable uuid extension module
1269extension=uuid.so
1270_EOF
1271cat <<_EOF > $rhsclphpetc/php.d/zmq.ini
1272; Enable zmq extension module
1273extension=zmq.so
1274_EOF
1275cat <<_EOF > $rhsclphpetc/php.d/imagick.ini
1276; Enable imagick extension module
1277extension=imagick.so
1278_EOF
1279#cat <<_EOF > $rhsclphpetc/php.d/mongo.ini
1280#; Enable mongo extension module
1281#extension=mongo.so
1282#_EOF
1283" );
1284
1285    runcmdsb( "scl enable rh-php56 'pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.5'" );
1286    runcmdsb( "scl enable rh-php56 'pear install --alldeps Mail Mail_Mime Net_SMTP'" );
1287
1288    `sudo killall mongod 2> /dev/null`;
1289    runcmdsb( "service mongod start" );
1290
1291    # add proxy support for ws, wss
1292    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
1293# ws proxy pass
1294# priority=20
1295ProxyPass /ws2 ws://localhost:$wsport/
1296ProxyPass /wss2 ws://localhost:$wsport/
1297_EOF
1298cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
1299SetEnv GENAPP $gb
1300_EOF
1301");
1302
1303    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
1304<Directory \"$rhsclhttpd/var/www/html\">
1305    Options FollowSymLinks
1306    AllowOverride None
1307    Require all granted
1308</Directory>
1309_EOF
1310");
1311
1312    # scl puts php in $rhsclphp so link it
1313
1314    runcmdsb( "ln -sf $rhsclphp/usr/bin/php /usr/bin/php" );
1315
1316    # scl puts httpd root in $rhsclphp so link it
1317
1318    if ( -e "/var/www" ) {
1319        if ( -d "/var/www" || -f "/var/www" ) {
1320            my $bdir = "/var/www.previous";
1321            my $ext ;
1322            while ( -e $bdir ) {
1323               $ext++;
1324               $bdir = "/var/www.previous-$ext";
1325            }
1326            $warnings .= "/var/www is backed up in $bdir";
1327            runcmdsb( "mv /var/www $bdir" );
1328        } else {
1329            runcmdsb( "rm /var/www" );
1330        }
1331    }
1332     
1333    runcmdsb( "ln -sf $rhsclhttpd/var/www /var/www" );
1334
1335    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
1336
1337    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
1338        runcmdsb( "ln -s /usr/bin/php /usr/local/bin/php" );
1339    }
1340
1341    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
1342
1343    runcmdsb( "mkdir -p $appbase
1344groupadd genapp
1345useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
1346chmod g+rwx $appbase
1347chown $whoami:genapp $appbase
1348chmod g+s $appbase
1349mkdir $$cfgjson{'lockdir'}
1350chown genapp:genapp $$cfgjson{'lockdir'}
1351chmod g+rwx $$cfgjson{'lockdir'}
1352usermod -g users -G genapp $whoami
1353usermod -G genapp \'apache\'
1354chgrp -R genapp $gb
1355chmod g+w $gb/etc
1356" );
1357
1358    # setup local system definitions
1359
1360    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
1361export GENAPP=$gb
1362export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
1363_EOF
1364cat <<_EOF > /etc/profile.d/genapp.csh
1365setenv GENAPP $gb
1366setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
1367_EOF
1368
1369" );
1370
1371    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
1372<?php
1373phpinfo();
1374?>
1375_EOF
1376" );
1377
1378    # setup genapptest instance
1379
1380    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1381
1382    # add ws servers to startup
1383
1384    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
1385    runcmdsb( "chkconfig --add rc.genapp" );
1386    runcmdsb( "/etc/init.d/rc.genapp start" );
1387
1388    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
1389
1390# iptables replaced by FirewaddD on RH7
1391
1392    if ( 0 ) {
1393      {
1394        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
1395        chomp $iptab;
1396        if ( $iptab !~ /tcp/ ) {
1397            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
1398    service iptables save" );
1399        }
1400      }
1401      if ( $$cfgjson{ 'https' } ) {
1402        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
1403        chomp $iptab;
1404        if ( $iptab !~ /tcp/ ) {
1405            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
1406    service iptables save" );
1407        }
1408      }
1409    }
1410
1411    exit();
1412}
1413
1414
1415die "------------------------------------------------------------
1416Operating system identified as $os / release $os_release
1417$sorry";
Note: See TracBrowser for help on using the repository browser.