Skip to content

Commit

Permalink
Merge pull request #78 from perftool-incubator/dev-kmr
Browse files Browse the repository at this point in the history
add the ability for the user to set environment variables when distro…
  • Loading branch information
k-rister authored Mar 25, 2024
2 parents ed5eca9 + e331639 commit 110081e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
9 changes: 8 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"2020.03.02",
"2020.04.30",
"2022.07.25",
"2023.02.16"
"2023.02.16",
"2024.03.22"
]
}
},
Expand Down Expand Up @@ -286,6 +287,12 @@
"type": "string",
"minLength": 1
}
},
"environment": {
"type": "object",
"properties": { },
"minProperties": 1,
"additionalProperties": true
}
},
"additionalProperties": false
Expand Down
44 changes: 26 additions & 18 deletions workshop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1454,36 +1454,44 @@ sub delete_proto {
$operation = $req->{'distro_info'}{'operation'};
}

my $environment = "";
if (exists($req->{'distro_info'}{'environment'})) {
$environment = "env ";
foreach my $key (keys %{$req->{'distro_info'}{'environment'}}) {
$environment .= $key . "=" . $req->{'distro_info'}{'environment'}{$key} . " ";
}
}

logger('info', "performing distro package $operation...\n", 2);

if (exists($req->{'distro_info'}{'packages'})) {
foreach my $pkg (@{$req->{'distro_info'}{'packages'}}) {
logger('info', "package '$pkg'...\n", 3);

my $operation_cmd = "";
my $operation_cmd = "$environment";
if ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'dnf') {
if ($operation eq 'install') {
$operation_cmd = "dnf install --allowerasing --assumeyes " . $pkg;
$operation_cmd .= "dnf install --allowerasing --assumeyes " . $pkg;
} elsif ($operation eq 'remove') {
$operation_cmd = "dnf remove --assumeyes " . $pkg;
$operation_cmd .= "dnf remove --assumeyes " . $pkg;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'yum') {
if ($operation eq 'install') {
$operation_cmd = "yum install --assumeyes " . $pkg;
$operation_cmd .= "yum install --assumeyes " . $pkg;
} elsif ($operation eq 'remove') {
$operation_cmd = "yum remove --assumeyes " . $pkg;
$operation_cmd .= "yum remove --assumeyes " . $pkg;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'apt') {
if ($operation eq 'install') {
$operation_cmd = "apt-get install -y " . $pkg;
$operation_cmd .= "apt-get install -y " . $pkg;
} elsif ($operation eq 'remove') {
$operation_cmd = "apt-get remove -y " . $pkg;
$operation_cmd .= "apt-get remove -y " . $pkg;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'zypper') {
if ($operation eq 'install') {
$operation_cmd = "zypper install -y " . $pkg;
$operation_cmd .= "zypper install -y " . $pkg;
} elsif ($operation eq 'remove') {
$operation_cmd = "zypper remove -y " . $pkg;
$operation_cmd .= "zypper remove -y " . $pkg;
}
} else {
logger('info', "failed\n", 4);
Expand All @@ -1510,32 +1518,32 @@ sub delete_proto {
foreach my $grp (@{$req->{'distro_info'}{'groups'}}) {
logger('info', "group '$grp'...\n", 3);

my $operation_cmd = "";
my $operation_cmd = "$environment";
if ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'dnf') {
if ($operation eq 'install') {
$operation_cmd = "dnf groupinstall --allowerasing --assumeyes " . $grp;
$operation_cmd .= "dnf groupinstall --allowerasing --assumeyes " . $grp;
} elsif ($operation eq 'remove') {
$operation_cmd = "dnf groupremove --assumeyes " . $grp;
$operation_cmd .= "dnf groupremove --assumeyes " . $grp;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'yum') {
if ($operation eq 'install') {
$operation_cmd = "yum groupinstall --assumeyes " . $grp;
$operation_cmd .= "yum groupinstall --assumeyes " . $grp;
} elsif ($operation eq 'remove') {
$operation_cmd = "yum groupremove --assumeyes " . $grp;
$operation_cmd .= "yum groupremove --assumeyes " . $grp;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'apt') {
if ($operation eq 'install') {
# The equivalent of 'groupinstall' is just meta-packages for apt, so no special option needed
$operation_cmd = "apt-get install -y --assumeyes " . $grp;
$operation_cmd .= "apt-get install -y --assumeyes " . $grp;
} elsif ($operation eq 'remove') {
# The equivalent of 'groupremove' is just meta-packages for apt, so no special option needed
$operation_cmd = "apt-get remove -y --assumeyes " . $grp;
$operation_cmd .= "apt-get remove -y --assumeyes " . $grp;
}
} elsif ($userenv_json->{'userenv'}{'properties'}{'packages'}{'manager'} eq 'zypper') {
if ($operation eq 'install') {
$operation_cmd = "zypper install -y -t pattern " . $grp;
$operation_cmd .= "zypper install -y -t pattern " . $grp;
} elsif ($operation eq 'remove') {
$operation_cmd = "zypper remove -y -t pattern " . $grp;
$operation_cmd .= "zypper remove -y -t pattern " . $grp;
}
} else {
logger('info', "failed\n", 4);
Expand Down

0 comments on commit 110081e

Please sign in to comment.