[1778] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | #
|
---|
| 4 | # HyPer-Linux perl script
|
---|
| 5 | # ======================
|
---|
| 6 | # The script is a cgi-bin script allowing the automatic configuration
|
---|
| 7 | # of HP ProLiant through a Web Browser, for preloaded Linux distribution
|
---|
| 8 | # customization.
|
---|
| 9 | #
|
---|
| 10 | # This program is free software and is made available under the GPLv2.
|
---|
| 11 | # (c) 2013 B. Cornec - Hewlett-Packard
|
---|
| 12 | #
|
---|
| 13 |
|
---|
| 14 | use strict;
|
---|
| 15 | use CGI;
|
---|
| 16 | use CGI::Carp qw(fatalsToBrowser);
|
---|
| 17 |
|
---|
| 18 | my $distrib = "RH64";
|
---|
| 19 | my $infofile = "/usr/share/lib/locale";
|
---|
| 20 |
|
---|
| 21 | my $cgi = new CGI;
|
---|
| 22 |
|
---|
| 23 | my $name;
|
---|
| 24 | my $s;
|
---|
| 25 | my $ftp;
|
---|
| 26 | my $shortname;
|
---|
| 27 | my $sysfont;
|
---|
| 28 | my $unused;
|
---|
| 29 | my %lang;
|
---|
| 30 | my %keyboard;
|
---|
| 31 | my %timezone;
|
---|
| 32 | my @lang;
|
---|
| 33 | my @keyboard;
|
---|
| 34 | my @timezone;
|
---|
| 35 | my $lang;
|
---|
| 36 | my $keyboard;
|
---|
| 37 | my $timezone;
|
---|
| 38 |
|
---|
| 39 | open(INFO,$infofile) || die "Unable to open $infofile";
|
---|
| 40 | while (<INFO>) {
|
---|
| 41 | s/ / /g;
|
---|
| 42 | ($name, $shortname, $sysfont, $unused, $lang, $keyboard, $timezone) = split(/ /);
|
---|
| 43 | chomp($timezone);
|
---|
| 44 | $name =~ s/ //g;
|
---|
| 45 | $timezone =~ s/ //g;
|
---|
| 46 | $keyboard =~ s/ //g;
|
---|
| 47 | $lang =~ s/ //g;
|
---|
| 48 | $lang{$lang} = "$name"." ($lang)";
|
---|
| 49 | push(@lang, ($lang));
|
---|
| 50 | $keyboard{$keyboard} = "$name"." ($keyboard)";
|
---|
| 51 | push(@keyboard, ($keyboard));
|
---|
| 52 | $timezone{$timezone} = "$name"." ($timezone)";
|
---|
| 53 | push(@timezone, ($timezone));
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | print $cgi->header;
|
---|
| 57 | print $cgi->start_html('HyPer-Linux Configuration');
|
---|
| 58 | print $cgi->h1('HyPer-Linux Configuration');
|
---|
| 59 | print $cgi->hr;
|
---|
| 60 | print << EOF;
|
---|
| 61 | <TABLE WIDTH="100%" >
|
---|
| 62 | <TR>
|
---|
| 63 | <TD rowspan=2><IMG SRC="hp.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT> </TD>
|
---|
| 64 | <TD> <FONT SIZE=+3> RedHat Enterprise Linux Installation Server </FONT> </TD>
|
---|
| 65 | </TR>
|
---|
| 66 | <TR>
|
---|
| 67 | <TD align=right></TD>
|
---|
| 68 | </TR>
|
---|
| 69 | </TABLE>
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | if (not ($cgi->param())) {
|
---|
| 73 | print $cgi->start_form;
|
---|
| 74 | print $cgi->h2('Configuration of the localization');
|
---|
| 75 | print "Language : ",$cgi->popup_menu(-name=>'language',
|
---|
| 76 | -values=>\@lang,
|
---|
| 77 | -default=>'fr_FR',
|
---|
| 78 | -labels=>\%lang);
|
---|
| 79 | print "<P>\n";
|
---|
| 80 | print "Keyboard : ",$cgi->popup_menu(-name=>'keyboard',
|
---|
| 81 | -values=>\@keyboard,
|
---|
| 82 | -default=>'fr',
|
---|
| 83 | -labels=>\%keyboard);
|
---|
| 84 | print "<P>\n";
|
---|
| 85 | print "Timezone : ",$cgi->popup_menu(-name=>'timezone',
|
---|
| 86 | -values=>\@timezone,
|
---|
| 87 | -default=>'Europe/Paris',
|
---|
| 88 | -labels=>\%timezone);
|
---|
| 89 | print "<P>\n";
|
---|
| 90 | print $cgi->hr;
|
---|
| 91 |
|
---|
| 92 | my %labels = ('MySQL' => 'MySQL Server',
|
---|
| 93 | 'PGSQL' => 'PostgreSQL Server',
|
---|
| 94 | 'EDB' => 'EnterpriseDB Server');
|
---|
| 95 | print $cgi->h2('Configuration of the services');
|
---|
| 96 | print "Which services do you want to activate by default at boot time : <P>\n",$cgi->popup_menu(-name=>'services',
|
---|
| 97 | -values=>['MySQL','PGSQL','EDB'],
|
---|
| 98 | -defaults=>['PGSQL'],
|
---|
| 99 | -labels=>\%labels);
|
---|
| 100 | print $cgi->hr;
|
---|
| 101 | print $cgi->h2('Configuration of the network parameters');
|
---|
| 102 | %labels = ('DHCP' => 'Configuration through a DHCP server',
|
---|
| 103 | 'STATIC' => 'Static IP configuration');
|
---|
| 104 | print "Mode : ",$cgi->popup_menu(-name=>'mode',
|
---|
| 105 | -values=>['DHCP','STATIC'],
|
---|
| 106 | -default=>'DHCP',
|
---|
| 107 | -labels=>\%labels);
|
---|
| 108 | print "<P>\n";
|
---|
| 109 | print "If you choose just above the Static IP configuration mode, please fill the following fields :<P>\n";
|
---|
| 110 | print "Full Qualified Domain Name of the system : ",$cgi->textfield(-name=>'name',
|
---|
| 111 | -default=>'netserver',
|
---|
| 112 | -size=>15,
|
---|
| 113 | -maxlenght=>15);
|
---|
| 114 | print "<P>IP address : ",$cgi->textfield(-name=>'address',
|
---|
| 115 | -default=>'192.168.1.1',
|
---|
| 116 | -size=>15,
|
---|
| 117 | -maxlenght=>15);
|
---|
| 118 | print " Netmask : ",$cgi->textfield(-name=>'netmask',
|
---|
| 119 | -default=>'255.255.255.0',
|
---|
| 120 | -size=>15,
|
---|
| 121 | -maxlenght=>15);
|
---|
| 122 | print "<P>Gateway : ",$cgi->textfield(-name=>'gateway',
|
---|
| 123 | -default=>'192.168.1.254',
|
---|
| 124 | -size=>15,
|
---|
| 125 | -maxlenght=>15);
|
---|
| 126 | print " Primary DNS : ",$cgi->textfield(-name=>'dns',
|
---|
| 127 | -default=>'192.168.1.100',
|
---|
| 128 | -size=>15,
|
---|
| 129 | -maxlenght=>15);
|
---|
| 130 | print "<P>\n";
|
---|
| 131 | print $cgi->submit;
|
---|
| 132 | print $cgi->end_form;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | else {
|
---|
| 136 | print $cgi->h2('You made the following choices :');
|
---|
| 137 | print $cgi->hr;
|
---|
| 138 | print "<BOLD>Localisation </BOLD> - ";
|
---|
| 139 | print "Language : <em>",$cgi->param('language'),", </em>";
|
---|
| 140 | print "Keyboard : <em>",$cgi->param('keyboard'),", </em>";
|
---|
| 141 | print "Timezone : <em>",$cgi->param('timezone'),"</em>";
|
---|
| 142 | print $cgi->hr;
|
---|
| 143 | print "<BOLD>Network</BOLD> configuration mode ";
|
---|
| 144 | if ($cgi->param('mode') eq 'STATIC') {
|
---|
| 145 | print "<em>static</em><P>";
|
---|
| 146 | print "Name : <em>",$cgi->param('name'),"</em><P>";
|
---|
| 147 | print "IP address : <em>",$cgi->param('address'),", </em>";
|
---|
| 148 | print "Netmask : <em>",$cgi->param('netmask'),"</em><P>";
|
---|
| 149 | print "Gateway : <em>",$cgi->param('gateway'),", </em>";
|
---|
| 150 | print "DNS server : <em>",$cgi->param('dns'),", </em>";
|
---|
| 151 | }
|
---|
| 152 | else {
|
---|
| 153 | print "<em>dynamic (DHCP)</em>"
|
---|
| 154 | }
|
---|
| 155 | print $cgi->hr;
|
---|
| 156 | print "<BOLD>Services</BOLD> activated at boot time : ";
|
---|
| 157 | foreach $s ($cgi->param('services')) {
|
---|
| 158 | print "- <em>MySQL server</em> -" if ( $s =~ /MySQL/);
|
---|
| 159 | print "- <em>PostgreSQL server</em> -" if ($s =~ /PGSQL/);
|
---|
| 160 | print "- <em>EnterpriseDB server</em> -" if ($s =~ /EDB/);
|
---|
| 161 | }
|
---|
| 162 | print $cgi->hr;
|
---|
| 163 | print "Your customization parameters are now being commited to the server which will then reboot to ensure a proper environement.<P>";
|
---|
| 164 | print "Please wait till it's done ...";
|
---|
| 165 | print $cgi->end_form;
|
---|
| 166 |
|
---|
| 167 | #
|
---|
| 168 | # Now doing the job ...
|
---|
| 169 | #
|
---|
| 170 | my $gendir = "/var/hyperlinux";
|
---|
| 171 | my $gensys = "$gendir/sysconfig";
|
---|
| 172 | my $gennet = "$gendir/network";
|
---|
| 173 | my $genbin = "$gendir/bin";
|
---|
| 174 | mkdir $gendir,0700;
|
---|
| 175 | mkdir $gensys,0700;
|
---|
| 176 | mkdir $gennet,0700;
|
---|
| 177 | mkdir $genbin,0700;
|
---|
| 178 |
|
---|
| 179 | if ($distrib eq "RH70") {
|
---|
| 180 | #
|
---|
| 181 | # Localisation
|
---|
| 182 | #
|
---|
| 183 | open(T,"> $gensys/clock") || die "Unable to open $gensys/clock";
|
---|
| 184 | print T 'ZONE="',$cgi->param('timezone'),'"',"\n";
|
---|
| 185 | #print T "UTC=false\n";
|
---|
| 186 | #print T "ARC=false\n";
|
---|
| 187 | close(T);
|
---|
| 188 | open(T,"> $gensys/keyboard") || die "Unable to open $gensys/keyboard";
|
---|
| 189 | print T 'KEYBOARDTYPE="pc"',"\n";
|
---|
| 190 | print T 'KEYTABLE="',$cgi->param('keyboard'),'"',"\n";
|
---|
| 191 | close(T);
|
---|
| 192 | open(T,"> $gensys/i18n") || die "Unable to open $gensys/i18n";
|
---|
| 193 | print T 'LANG="',$cgi->param('language'),'"',"\n";
|
---|
| 194 | close(T);
|
---|
| 195 | #
|
---|
| 196 | # Network
|
---|
| 197 | #
|
---|
| 198 | open(T,"> $gensys/network") || die "Unable to open $gensys/network";
|
---|
| 199 | print T 'NETWORKING="yes"',"\n";
|
---|
| 200 | print T 'GATEWAYDEV="eth0"',"\n";
|
---|
| 201 | print T 'GATEWAY="',$cgi->param('gateway'),'"',"\n";
|
---|
| 202 | print T 'HOSTNAME="',$cgi->param('name'),'"',"\n";
|
---|
| 203 | close(T);
|
---|
| 204 | open(T,"> $gennet/ifcfg-eth0") || die "Unable to open $gennet/ifcfg-eth0";
|
---|
| 205 | print T "DEVICE=eth0\n";
|
---|
| 206 | print T "USERCTL=no\n";
|
---|
| 207 | print T "ONBOOT=yes\n";
|
---|
| 208 | if ($cgi->param('mode') eq 'DHCP') {
|
---|
| 209 | print T "BOOTPROTO=dhcp\n";
|
---|
| 210 | print T "IPADDR=\n";
|
---|
| 211 | print T "NETMASK=\n";
|
---|
| 212 | print T "NETWORK=\n";
|
---|
| 213 | print T "BROADCAST=\n";
|
---|
| 214 | }
|
---|
| 215 | else {
|
---|
| 216 | print T "BOOTPROTO=none\n";
|
---|
| 217 | print T 'IPADDR="',$cgi->param('address'),'"',"\n";
|
---|
| 218 | print T 'NETMASK="',$cgi->param('netmask'),'"',"\n";
|
---|
| 219 | print T "NETWORK=\n";
|
---|
| 220 | print T "BROADCAST=\n";
|
---|
| 221 | }
|
---|
| 222 | close(T);
|
---|
| 223 | #
|
---|
| 224 | # Services
|
---|
| 225 | #
|
---|
| 226 | open(T,"> $genbin/populate") || die "Unable to open $genbin/populate";
|
---|
| 227 | print T "#!/bin/sh\n";
|
---|
| 228 | print T "#\n";
|
---|
| 229 |
|
---|
| 230 | $ftp = 0;
|
---|
| 231 | foreach $s ($cgi->param('services')) {
|
---|
| 232 | print T "/sbin/chkconfig --level 345 mysqld on\n" if ($s =~ /MySQL/);
|
---|
| 233 | print T "/sbin/chkconfig --level 345 postgresql on\n" if ($s =~ /PGSQL/);
|
---|
| 234 | print T "/sbin/chkconfig --level 345 EDB on\n" if ($s =~ /EDB/);
|
---|
| 235 | }
|
---|
| 236 | print T "/bin/mv $gensys/* /etc/sysconfig\n";
|
---|
| 237 | print T "/bin/mv $gennet/* /etc/sysconfig/network-scripts\n";
|
---|
| 238 | print T "/sbin/shutdown -r +1 'Reboot for HyPer-Linux Configuration...'\n";
|
---|
| 239 | close(T);
|
---|
| 240 | chmod 0755,"$genbin/populate";
|
---|
| 241 | system("sudo $genbin/populate");
|
---|
| 242 | }
|
---|
| 243 | }
|
---|