source: genapp/sbin/install.pl

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

Fixes for 18.04 & setconfig issue

File size: 44.1 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,7.6-------
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    # need zeromq from source :(
914
915    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
916/usr/local/lib
917_EOF
918sudo ldconfig
919 " ) if !-e "/usr/local/lib/libzmq.so" || !-e "/etc/ld.so.conf.d/zeromq.conf";
920
921# php-pear php-imagick php-mail php-mail-mime php-mongodb mongodb" );
922
923    runcmdsb( "pear install --alldeps Mail Mail_Mime Net_SMTP" );
924    runcmdsb( "yes '' | pecl install uuid zmq-beta mongo imagick" );
925
926    # zmq to php
927
928    runcmdsb( "cat <<_EOF > /etc/php/5.6/mods-available/zmq.ini
929; configuration for php zmq module
930; priority=20
931extension=zmq.so
932_EOF
933cat <<_EOF > /etc/php/5.6/mods-available/imagick.ini
934; Enable imagick extension module
935extension=imagick.so
936_EOF
937cat <<_EOF > /etc/php/5.6/mods-available/mongo.ini
938; Enable mongo extension module
939extension=mongo.so
940_EOF
941phpenmod zmq mongo imagick" );
942
943    runcmdsb( "sed \"s/^disable_functions = pcntl/\;disable_functions = pcntl/\" /etc/php/5.6/apache2/php.ini > /tmp/_php.ini
944cp /etc/php/5.6/apache2/php.ini{,.org}
945mv /tmp/_php.ini /etc/php/5.6/apache2/php.ini
946#phpenmod pcntl" );
947
948    # add proxy support for ws, wss
949    runcmdsb( "cat <<_EOF > /etc/apache2/mods-available/wsproxy.conf
950# ws proxy pass
951# priority=20
952ProxyPass /ws2 ws://localhost:$wsport/
953_EOF
954cat <<_EOF > /etc/apache2/mods-available/wsproxy.load
955_EOF
956cat <<_EOF > /etc/apache2/mods-available/wssproxy.conf
957# wss proxy pass
958# priority=20
959ProxyPass /wss2 ws://localhost:$wsport/
960_EOF
961cat <<_EOF > /etc/apache2/mods-available/wssproxy.load
962_EOF
963");
964    runcmd( "sudo a2enmod proxy proxy_wstunnel wsproxy" );
965
966    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
967
968    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
969        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
970    }
971
972    # make the base of the genapp instances directory, create group genapp, add user & www-data to genapp group
973
974    runcmdsb( "mkdir -p $appbase
975groupadd genapp
976useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
977chmod g+rwx $appbase
978chown $whoami:genapp $appbase
979chmod g+s $appbase
980mkdir $$cfgjson{'lockdir'}
981chown genapp:genapp $$cfgjson{'lockdir'}
982chmod g+rwx $$cfgjson{'lockdir'}
983usermod -g users -G genapp $whoami
984usermod -G genapp \'www-data\'
985chgrp -R genapp $gb
986chmod g+w $gb/etc
987" );
988
989    # setup local system definitions
990
991    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
992export GENAPP=$gb
993export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
994_EOF
995" );
996
997    # php info for debugging
998   
999    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
1000<?php
1001phpinfo();
1002?>
1003_EOF
1004" );
1005
1006    # setup genapptest instance
1007
1008    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1009
1010    # apache2 security needed ?
1011
1012    runcmdsb( "cat <<_EOF >> /etc/apache2/conf-enabled/security.conf
1013# add Alias /genapptest $$cfgjson{'webroot'}/genapptest
1014<Directory $$cfgjson{'webroot'}/genapptest>
1015 Options FollowSymLinks
1016 AllowOverride None
1017 Order Allow,Deny
1018 Allow from all
1019</Directory>
1020<Directory /var/www/>
1021        Options FollowSymLinks
1022        AllowOverride None
1023        Require all granted
1024</Directory>
1025_EOF
1026" );
1027
1028    # add ws servers to startup
1029
1030    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d
1031update-rc.d rc.genapp defaults 99
1032update-rc.d mongodb defaults" );
1033
1034    # start ws servers
1035    runcmdsb( "/etc/init.d/rc.genapp start" );
1036
1037# restart apache2
1038
1039    runcmd( "sudo service apache2 restart" );
1040    exit();
1041}
1042
1043# ------ scientific linux 7.2 -------
1044if ( $os eq 'scientific' && $os_release =~ /^7\.(2|3|4)(cernvm|)/ ) {
1045
1046    my $cernvm;
1047    if ( $os_release =~ /cernvm$/ ) {
1048        $cernvm++;
1049    }
1050
1051    runcmdsb( "cat <<_EOF > /etc/yum.repos.d/mongodb.repo
1052[mongodb]
1053name=MongoDB Repository
1054baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
1055gpgcheck=0
1056enabled=1
1057_EOF
1058# the 3.2 repo didn't seem to work
1059#cat <<_EOF > /etc/yum.repos.d/mongodb-org-3.2.repo
1060#[mongodb-org-3.2]
1061#name=MongoDB Repository
1062#baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.2/x86_64/
1063#gpgcheck=1
1064#enabled=1
1065#gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
1066#_EOF
1067cat <<_EOF > /etc/yum.repos.d/mongodb-org-2.6.repo
1068[mongodb-org-2.6]
1069name=MongoDB 2.6 Repository
1070baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
1071gpgcheck=0
1072enabled=1
1073_EOF
1074cat <<_EOF > /etc/yum.repos.d/fengshuo_zeromq.repo
1075[home_fengshuo_zeromq]
1076name=The latest stable of zeromq builds (CentOS_CentOS-6)
1077type=rpm-md
1078baseurl=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/
1079gpgcheck=1
1080gpgkey=http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/repodata/repomd.xml.key
1081enabled=1
1082_EOF
1083");
1084
1085    runcmdsb( "semanage port -l | grep mongod_port_t || semanage port -a -t mongod_port_t -p tcp 27017" ) if !$cernvm;
1086
1087    # install required modules
1088
1089#    runcmdsb( "rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm" );
1090    runcmdsb( "yum -y groupinstall 'Development tools'" ) if !$cernvm;
1091
1092    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" );
1093 
1094    if ( $cernvm ) {
1095        # need imagemagick from source :(
1096        my $imversion = "ImageMagick-6.9.10-28.tar.xz";
1097        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";
1098    } else {
1099        runcmdsb( "yum -y install ImageMagick ImageMagick-devel" );
1100    }
1101
1102    my $rhsclphp    = "";
1103    my $rhsclphpetc = "";
1104    my $rhsclhttpd  = "";
1105
1106    runcmdsb( "yes '' | pecl channel-update pecl.php.net" );
1107    runcmdsb( "yes '' | pecl install uuid zmq-beta mongo imagick" );
1108
1109    if ( my $cmd = add_to_phpini( '/etc/php.ini', 'uuid', 'zmq', 'imagick', 'mongo' ) ) {
1110        runcmdsb( $cmd );
1111    }
1112
1113    # rh-php56-php-pecl-mongo mongodb mongodb-server zeromq-devel" );
1114    runcmdsb( "yes '' | pear channel-update pear.php.net" );
1115    runcmdsb( "yes '' | pear install --alldeps Mail Mail_Mime Net_SMTP" );
1116
1117    `sudo killall mongod 2> /dev/null`;
1118    runcmdsb( "service mongod start
1119chkconfig mongod on
1120" );
1121
1122    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
1123# ws proxy pass
1124# priority=20
1125ProxyPass /ws2 ws://localhost:$wsport/
1126ProxyPass /wss2 ws://localhost:$wsport/
1127_EOF
1128cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
1129SetEnv GENAPP $gb
1130_EOF
1131");
1132
1133    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
1134<Directory \"$rhsclhttpd/var/www/html\">
1135    Options FollowSymLinks
1136    AllowOverride None
1137    Require all granted
1138</Directory>
1139_EOF
1140");
1141
1142    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
1143
1144    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
1145        runcmd( "sudo bash -c 'ln -s /usr/bin/php /usr/local/bin/php'" );
1146    }
1147
1148    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
1149
1150    runcmdsb( "mkdir -p $appbase
1151groupadd genapp
1152useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
1153chmod g+rwx $appbase
1154chown $whoami:genapp $appbase
1155chmod g+s $appbase
1156mkdir $$cfgjson{'lockdir'} 2> /dev/null
1157chown genapp:genapp $$cfgjson{'lockdir'}
1158chmod g+rwx $$cfgjson{'lockdir'}
1159usermod -g users -G genapp $whoami
1160usermod -G genapp \'apache\'
1161chgrp -R genapp $gb
1162chmod g+w $gb/etc
1163" );
1164
1165    # setup local system definitions
1166
1167    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
1168export GENAPP=$gb
1169export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
1170_EOF
1171cat <<_EOF > /etc/profile.d/genapp.csh
1172setenv GENAPP $gb
1173setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
1174_EOF
1175
1176" );
1177
1178    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
1179<?php
1180phpinfo();
1181?>
1182_EOF
1183" );
1184
1185    # setup genapptest instance
1186
1187    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1188
1189    # add ws servers to startup
1190
1191    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
1192    runcmdsb( "chkconfig --add rc.genapp" );
1193    runcmdsb( "/etc/init.d/rc.genapp start" );
1194
1195    # open ports
1196    if ( !$cernvm ) {
1197        runcmdsb( "firewall-cmd --permanent --zone=public --add-service=http" );
1198        if ( $$cfgjson{ 'https' } ) {
1199            runcmdsb( "firewall-cmd --permanent --zone=public --add-service=https" );
1200        }
1201        runcmdsb( "systemctl restart firewalld.service" );
1202    }
1203
1204    runcmdsb( "semanage permissive -a httpd_t" ) if !$cernvm;
1205
1206    if ( $cernvm ) {
1207        runcmdsb( "sed --in-place=.prev 's/Listen .*:80/Listen 80/g' /etc/httpd/conf/httpd.conf" );
1208    }
1209
1210    runcmdsb( "systemctl restart httpd.service && systemctl enable httpd.service" );
1211    exit();
1212}
1213
1214# ------ redhat 7.x -------
1215
1216if ( $os eq 'redhat' && $os_release =~ /^7\.(5|6)/ ) {
1217    # install required modules
1218
1219    runcmdsb( "cat <<_EOF > /etc/yum.repos.d/mongodb-org-3.6.repo
1220[mongodb-org-3.6]
1221name=MongoDB Repository
1222baseurl=https://repo.mongodb.org/yum/redhat/_releasever/mongodb-org/3.6/x86_64/
1223gpgcheck=1
1224enabled=1
1225gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
1226_EOF
1227sed -i 's/_/\$/' /etc/yum.repos.d/mongodb-org-3.6.repo
1228# semanage port -a -t mongod_port_t -p tcp 27017
1229");
1230
1231
1232    runcmdsb( "yum-config-manager --enable rhel-server-rhscl-7-rpms" );
1233    {
1234        my @res = `sudo subscription-manager list --available --all 2>&1 | grep 'not yet registered'`;
1235        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;
1236        @res = `sudo yum repolist 2> /dev/null | grep rhscl`;
1237        die '-'x80 . "
1238$0: you appeared to be registered, but need to attach to a pool.  you can use:
1239\$ sudo subscription-manager list --available
1240and identify a 'Pool ID:'=pool_id and then use that pool_id to
1241\$ sudo subscription-manager attach --pool=pool_id
1242" . '-'x80 . "
1243You may also find info at this url:
1244https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/2/html-single/2.1_Release_Notes/index.html#sect-Installation-Subscribe
1245" . '-'x80 . "
1246" if !@res;
1247    }
1248
1249    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" );
1250
1251    # need zeromq from source :(
1252
1253    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
1254/usr/local/lib
1255_EOF
1256sudo ldconfig
1257 " ) if !-e "/usr/local/lib/libzmq.so" || !-e "/etc/ld.so.conf.d/zeromq.conf";
1258
1259    # need imagemagick from source :(
1260    # might need fix to freetype2 https://bugzilla.redhat.com/show_bug.cgi?id=1651788
1261    if ( $os_release eq '7.6' ) {
1262        runcmdsb( "sed -i '801s/FT_ENCODING_PRC/FT_ENCODING_GB2312/' /usr/include/freetype2/freetype/freetype.h" );
1263    }
1264
1265    my $imversion = "ImageMagick-6.9.10-28.tar.xz";
1266    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";
1267
1268    my $rhsclphp    = "/opt/rh/rh-php56/root";
1269    my $rhsclphpetc = "/etc/opt/rh/rh-php56/";
1270    my $rhsclhttpd  = "/opt/rh/httpd24/root";
1271
1272    runcmdsb( "sed -i 's/PHP -C -n -q/PHP -C -q/' $rhsclphp/usr/bin/pecl" );
1273    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl channel-update pecl.php.net" );
1274    runcmdsb( "yes '' | $rhsclphp/usr/bin/pecl install uuid zmq-beta mongo imagick;
1275cat <<_EOF > $rhsclphpetc/php.d/uuid.ini
1276; Enable uuid extension module
1277extension=uuid.so
1278_EOF
1279cat <<_EOF > $rhsclphpetc/php.d/zmq.ini
1280; Enable zmq extension module
1281extension=zmq.so
1282_EOF
1283cat <<_EOF > $rhsclphpetc/php.d/imagick.ini
1284; Enable imagick extension module
1285extension=imagick.so
1286_EOF
1287#cat <<_EOF > $rhsclphpetc/php.d/mongo.ini
1288#; Enable mongo extension module
1289#extension=mongo.so
1290#_EOF
1291" );
1292
1293    runcmdsb( "scl enable rh-php56 'pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.5'" );
1294    runcmdsb( "scl enable rh-php56 'pear install --alldeps Mail Mail_Mime Net_SMTP'" );
1295
1296    `sudo killall mongod 2> /dev/null`;
1297    runcmdsb( "service mongod start" );
1298
1299    # add proxy support for ws, wss
1300    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/wsproxy.conf
1301# ws proxy pass
1302# priority=20
1303ProxyPass /ws2 ws://localhost:$wsport/
1304ProxyPass /wss2 ws://localhost:$wsport/
1305_EOF
1306cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/genapp.conf
1307SetEnv GENAPP $gb
1308_EOF
1309");
1310
1311    runcmdsb( "cat <<_EOF > $rhsclhttpd/etc/httpd/conf.d/noindices.conf
1312<Directory \"$rhsclhttpd/var/www/html\">
1313    Options FollowSymLinks
1314    AllowOverride None
1315    Require all granted
1316</Directory>
1317_EOF
1318");
1319
1320    # scl puts php in $rhsclphp so link it
1321
1322    runcmdsb( "ln -sf $rhsclphp/usr/bin/php /usr/bin/php" );
1323
1324    # scl puts httpd root in $rhsclphp so link it
1325
1326    if ( -e "/var/www" ) {
1327        if ( -d "/var/www" || -f "/var/www" ) {
1328            my $bdir = "/var/www.previous";
1329            my $ext ;
1330            while ( -e $bdir ) {
1331               $ext++;
1332               $bdir = "/var/www.previous-$ext";
1333            }
1334            $warnings .= "/var/www is backed up in $bdir";
1335            runcmdsb( "mv /var/www $bdir" );
1336        } else {
1337            runcmdsb( "rm /var/www" );
1338        }
1339    }
1340     
1341    runcmdsb( "ln -sf $rhsclhttpd/var/www /var/www" );
1342
1343    # genapp html5 likes php at /usr/local/bin/php so make sure it exists
1344
1345    if ( -e "/usr/bin/php" && !-e "/usr/local/bin/php" ) {
1346        runcmdsb( "ln -s /usr/bin/php /usr/local/bin/php" );
1347    }
1348
1349    # make the base of the genapp instances directory, create group genapp, add user & apache to genapp group
1350
1351    runcmdsb( "mkdir -p $appbase
1352groupadd genapp
1353useradd genapp -r -s /usr/sbin/nologin -d $appbase -g genapp
1354chmod g+rwx $appbase
1355chown $whoami:genapp $appbase
1356chmod g+s $appbase
1357mkdir $$cfgjson{'lockdir'}
1358chown genapp:genapp $$cfgjson{'lockdir'}
1359chmod g+rwx $$cfgjson{'lockdir'}
1360usermod -g users -G genapp $whoami
1361usermod -G genapp \'apache\'
1362chgrp -R genapp $gb
1363chmod g+w $gb/etc
1364" );
1365
1366    # setup local system definitions
1367
1368    runcmdsb( "cat <<_EOF > /etc/profile.d/genapp.sh
1369export GENAPP=$gb
1370export PATH=\\\\\\\$GENAPP/bin:\\\\\\\$PATH
1371_EOF
1372cat <<_EOF > /etc/profile.d/genapp.csh
1373setenv GENAPP $gb
1374setenv PATH=\\\\\\\$\{GENAPP\}/bin:\\\\\\\$\{PATH}
1375_EOF
1376
1377" );
1378
1379    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
1380<?php
1381phpinfo();
1382?>
1383_EOF
1384" );
1385
1386    # setup genapptest instance
1387
1388    runcmd( "cd $appbase && $gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
1389
1390    # add ws servers to startup
1391
1392    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
1393    runcmdsb( "chkconfig --add rc.genapp" );
1394    runcmdsb( "/etc/init.d/rc.genapp start" );
1395
1396    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
1397
1398# iptables replaced by FirewaddD on RH7
1399
1400    if ( 0 ) {
1401      {
1402        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
1403        chomp $iptab;
1404        if ( $iptab !~ /tcp/ ) {
1405            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
1406    service iptables save" );
1407        }
1408      }
1409      if ( $$cfgjson{ 'https' } ) {
1410        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
1411        chomp $iptab;
1412        if ( $iptab !~ /tcp/ ) {
1413            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
1414    service iptables save" );
1415        }
1416      }
1417    }
1418
1419    exit();
1420}
1421
1422
1423die "------------------------------------------------------------
1424Operating system identified as $os / release $os_release
1425$sorry";
Note: See TracBrowser for help on using the repository browser.