Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use File::Basename;
- use Cwd 'abs_path';
- use lib dirname($0).'/oebin';
- use Getopt::Long;
- use Pod::Usage;
- use File::Basename;
- my ($uninstall, $help) = ();
- GetOptions (
- "uninstall" => \$uninstall
- );
- my $user=uc($ENV{'LOGNAME'}?$ENV{'LOGNAME'}:uc(`id -un`));
- chomp $user;
- my $BYTES_PER_CYLINDER=696000;
- my $rplRoot="___REPLACE_ROOT___";
- my $accountNumber=($ENV{'COMPILER_INSTALL_ACCOUNT_NUMBER'}?$ENV{'COMPILER_INSTALL_ACCOUNT_NUMBER'}:'0');
- my $usrHLQ=($ENV{'COMPILER_INSTALL_HLQ'}?$ENV{'COMPILER_INSTALL_HLQ'}:$user);
- my $msgCLS=($ENV{'COMPILER_INSTALL_MSGCLASS'}?$ENV{'COMPILER_INSTALL_MSGCLASS'}:'S');
- my $jclVol=($ENV{'COMPILER_INSTALL_VOLSER'}?" VOLUME($ENV{'COMPILER_INSTALL_VOLSER'})":());
- my $rplHLQ="___REPLACE_HLQ___";
- my $sqfHLQ="USRHLQ";
- my $instroot=abs_path(dirname($0));
- my $ussRoot="$instroot/uss.images";
- my $tgtRoot="$instroot/bin";
- my @files=();
- my @listOfDatasets=();
- if (&isUninstall) {
- die "<ERR> failed to uninstall because target path $tgtRoot does not exist, please make sure to run ".
- "this script under the same directory where unpack.pl was previously run during installation"
- if (!-d $tgtRoot);
- } else {
- (system("mkdir -p $tgtRoot && cp -rmf $ussRoot/* $tgtRoot/") == 0)||die "copy failed";
- }
- open (FLIST,"find $tgtRoot -type f 2>/dev/null|")||die "failed to find files under $srcRoot";
- while (<FLIST>) {
- my $file=$_;
- chomp $file;
- if ($file =~ m/\/xmits\/$sqfHLQ.*.XMIT$/) {
- push @listOfDatasets,$file;
- } else {
- push @files,$file;
- }
- }
- close FLIST;
- foreach my $ds (@listOfDatasets) {
- if (&isUninstall) {
- print "<DEB> deleting ".&mapDatasetName($ds)."\n";
- &deleteDS(&mapDatasetName($ds)) || print "<DEB> cannot delete ".&mapDatasetName($ds)." -- has it already been deleted?\n";
- } else {
- print "<DEB> unloading $ds into ".&mapDatasetName($ds)."\n";
- &receiveDSfromFile($ds, &mapDatasetName($ds)) || die "<ERR> cannot receive $ds to ". &mapDatasetName($ds);
- }
- }
- if (&isUninstall) {
- opendir my $ussbindir, "$ussRoot/" or die "<ERR> cannot open uss.images dir $ussRoot:$!";
- my @ussbinfiles = grep { /[^\.]/ } readdir ($ussbindir);
- die "<ERR> $ussbindir is empty" if (scalar(@ussbinfiles)<1);
- my $filesToDelete = join(' ',@ussbinfiles);
- closedir $ussbindir;
- (system("cd $tgtRoot/ && rm -rf $filesToDelete") == 0)||die "delete failed:$!";
- print "<INFO> uninstallation complete!\n";
- } else {
- foreach my $f (@files) {
- print "<DEB> processing file $f\n";
- &doReplaceDataset($f) || die "cannot parse $f to replace dataset";
- &doReplaceRoot($f) || die "cannot parse $f to replace HFS root";
- }
- &runIVP() || die "fail to verify installation";
- print "<INFO> installation complete!\n";
- }
- sub submit_jcl {
- open (FJCL,">.tempjcl")||die "failed to open .tempjcl";
- my (@list) = @_;
- foreach my $line ( @list ) {
- print FJCL "$line\n";
- }
- close FJCL;
- my $cmd = "submit .tempjcl";
- return (system ($cmd) == 0);
- }
- sub runIVP {
- my $temphello="._temp.hello.cpp";
- open (FHELLO,">$temphello")||die "failed to oepn $temphello";
- print FHELLO "#include <iostream>\n";
- print FHELLO "using namespace std;\n";
- print FHELLO "int main () {\n";
- print FHELLO " cout << \"Hello C++ World!\" << endl;\n";
- print FHELLO " return 0;\n";
- print FHELLO "}\n";
- close FHELLO;
- my $cmd="$tgtRoot/njsc++ $temphello -o hello -qphaseid && $tgtRoot/run ./hello && rm -f $temphello hello";
- print "<INFO> running : $cmd!\n";
- return(system("$cmd")==0);
- }
- sub doReplaceDataset {
- my ($file) = @_;
- my $ofile = "${file}._temp_out";
- open (FIN,"<$file")||die "failed to open $file to read";
- open (FOUT,">$ofile")||die "failed to open ofile to write";
- while (<FIN>) {
- my $line=$_;
- $line=~s/$rplHLQ/$usrHLQ/ig;
- print FOUT $line;
- }
- close FIN;
- close FOUT;
- (system("mv $ofile $file && chmod 755 $file")==0)||die " failed to rename $ofile to $file";
- return 1;
- }
- sub doReplaceRoot {
- my ($file) = @_;
- my $ofile = "${file}._temp_out";
- open (FIN,"<$file")||die "failed to open $file to read";
- open (FOUT,">$ofile")||die "failed to open ofile to write";
- while (<FIN>) {
- my $line=$_;
- if ($line=~m/$rplRoot/) {
- $line=~s/$rplRoot/$tgtRoot/g;
- }
- print FOUT $line;
- }
- close FIN;
- close FOUT;
- (system("mv $ofile $file && chmod 755 $file")==0)||die " failed to rename $ofile to $file";
- return 1;
- }
- sub mapDatasetName {
- my ($dataset) = @_;
- if ($dataset =~ m/.*\/$sqfHLQ\.([^\/]*)\.XMIT$/g) {
- $dataset = "$usrHLQ.$1";
- }
- return $dataset;
- }
- sub receiveDSfromFile {
- my ($file, $dataset) = @_;
- my $tempDS = getTempDSName();
- if (! copyFileToSequentialDS($file, $tempDS)) {
- warn "An error occurred while copying file $file to dataset $tempDS. -- $!";
- return 0;
- }
- if (! receiveDSfromDS($tempDS, $dataset)) {
- warn "An error occurred while receiving temporary dataset $tempDS to dataset $dataset.";
- return 0;
- }
- if (! deleteDS($tempDS)) {
- warn "An error occurred when deleting $tempDS.";
- return 0;
- }
- return 1;
- }
- sub receiveDSfromDS {
- my ($in_dataset, $target_dataset) = @_;
- $in_dataset=uc($in_dataset);
- $target_dataset=uc($target_dataset);
- my @jcl;
- my $hostname=uc(`hostname -s`);
- chomp($hostname);
- return 0 if (!$in_dataset || !$target_dataset || !$user || !$hostname);
- my @receive_jcl = (
- "//${user}A JOB ${accountNumber},'RECEIVE',MSGLEVEL=(1,1),MSGCLASS=$msgCLS,",
- "// CLASS=A,REGION=0M,USER=$user",
- "//REC EXEC PGM=IKJEFT01,DYNAMNBR=3000",
- "//SYSTSPRT DD SYSOUT=*",
- "//SYSPRINT DD SYSOUT=*",
- "//SYSTSIN DD DATA,DLM='!!'",
- " RECEIVE +",
- " INDATASET('$in_dataset')",
- " DATASET('$target_dataset')".($jclVol?' +':''),
- ($jclVol?$jclVol:()),
- );
- push (@receive_jcl, "!!");
- push (@receive_jcl, "//");
- submit_jcl(@receive_jcl);
- return 1;
- }
- sub copyFileToSequentialDS {
- my ($file, $dataset) = @_;
- return 0 if (!$dataset) && (!$file);
- my $num_cyls = getNumCylinders($file);
- #The space parameter doesn't seem to work properly and the documentation is incorrect.
- #It seems that we always get 1 cylinder for the primary extent, so I have specified the
- #required size twice, for primary and secondary allocation units.
- my $copy_cmd = "cp -B -P \"recfm=fb, lrecl=80, blksize=3120, space=(cyl,($num_cyls,$num_cyls))\" $file \"//'$dataset'\"";
- return (system ($copy_cmd) == 0);
- }
- sub getNumCylinders {
- my ($file) = @_;
- return 0 if (!$file);
- my $size = -s $file;
- #Determine the number of cylinders that we need for the DS (always round up by 1)
- my $num_cyls = int($size / $BYTES_PER_CYLINDER) + 1;
- }
- sub deleteDS {
- my ($dataset) = @_;
- $dataset=uc($dataset);
- my @delete_jcl = (
- "//${user}1 JOB ${accountNumber},",
- "// 'DELETE',",
- "// MSGLEVEL=(1,1),",
- "// MSGCLASS=$msgCLS,",
- "// CLASS=A,",
- "// USER=$user",
- "//DELETE EXEC PGM=IEFBR14",
- "//ACLBSR1 DD DISP=(MOD,DELETE,DELETE),",
- "// DSN=$dataset,",
- "// SPACE=(TRK,(1,1))",
- "//",
- );
- submit_jcl(@delete_jcl);
- return 1;
- }
- sub getTempDSName {
- my $time = time();
- my @random_chars = ('A'..'Z');
- #<LAST 7 DIGITS OF CURRENT TIME IN MS>.T<PID>
- $random_string = "T" . substr($time, -7) . ".T" . substr($$, -7);
- $random_string .= "." . $random_chars[int(rand(scalar(@random_chars)))];
- $random_string .= int(rand(scalar(9999999)));
- my $tempDS = "$user.TMP.$random_string";
- return $tempDS;
- }
- sub isUninstall {
- return ($uninstall?1:0);
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement