[script] perltidy
This commit is contained in:
+85
-65
@@ -2,25 +2,27 @@
|
||||
|
||||
use Getopt::Long;
|
||||
|
||||
my $profile = $ENV{BUILDER_PROFILE} // 3;
|
||||
my $jobs = $ENV{BUILDER_JOBS} // 1;
|
||||
my $use_equo = $ENV{USE_EQUO} // 1;
|
||||
my $preserved_rebuild = $ENV{PRESERVED_REBUILD} // 0;
|
||||
my $emerge_defaults_args = $ENV{EMERGE_DEFAULTS_ARGS}
|
||||
// "--accept-properties=-interactive --verbose --oneshot --nospinner --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg";
|
||||
$ENV{FEATURES} = $ENV{FEATURES}
|
||||
// "parallel-fetch protect-owned compressdebug splitdebug -userpriv";
|
||||
|
||||
my $profile = $ENV{BUILDER_PROFILE} // 3;
|
||||
my $jobs = $ENV{BUILDER_JOBS} // 1;
|
||||
my $use_equo = $ENV{USE_EQUO} // 1;
|
||||
my $preserved_rebuild = $ENV{PRESERVED_REBUILD} // 0;
|
||||
my $emerge_defaults_args = $ENV{EMERGE_DEFAULTS_ARGS} // "--accept-properties=-interactive --verbose --oneshot --nospinner --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg";
|
||||
$ENV{FEATURES} = $ENV{FEATURES} // "parallel-fetch protect-owned compressdebug splitdebug -userpriv";
|
||||
|
||||
my $equo_install_atoms = $ENV{EQUO_INSTALL_ATOMS} // 1;
|
||||
my $equo_install_version = $ENV{EQUO_INSTALL_VERSION} // 0;
|
||||
my $equo_split_install = $ENV{EQUO_SPLIT_INSTALL} // 0;
|
||||
my $artifacts_folder = $ENV{ARTIFACTS_DIR};
|
||||
my $equo_install_atoms = $ENV{EQUO_INSTALL_ATOMS} // 1;
|
||||
my $equo_install_version = $ENV{EQUO_INSTALL_VERSION} // 0;
|
||||
my $equo_split_install = $ENV{EQUO_SPLIT_INSTALL} // 0;
|
||||
my $artifacts_folder = $ENV{ARTIFACTS_DIR};
|
||||
|
||||
my @overlays;
|
||||
|
||||
GetOptions('layman|overlay:s{,}' => \@overlays);
|
||||
GetOptions( 'layman|overlay:s{,}' => \@overlays );
|
||||
|
||||
if (@ARGV==0) {
|
||||
help();die();
|
||||
if ( @ARGV == 0 ) {
|
||||
help();
|
||||
die();
|
||||
}
|
||||
|
||||
$ENV{LC_ALL} = "en_US.UTF-8"; #here be dragons
|
||||
@@ -31,37 +33,39 @@ sub package_deps {
|
||||
my $depth = shift // 1;
|
||||
my $atom = shift // 0;
|
||||
return
|
||||
map { $_ =~ s/\[.*\]|\s//g; &atom($_) if $atom; $_ }
|
||||
qx/equery -C -q g --depth=$depth $package/; #depth=0 it's all
|
||||
map { $_ =~ s/\[.*\]|\s//g; &atom($_) if $atom; $_ }
|
||||
qx/equery -C -q g --depth=$depth $package/; #depth=0 it's all
|
||||
}
|
||||
|
||||
#Input: nothing
|
||||
#Output: returns all available packages across all the repository installed in the machine
|
||||
sub available_packages {
|
||||
my @packages;
|
||||
my @repos=qx|equo repo list -q|;
|
||||
chomp(@repos);
|
||||
push(@packages,qx|equo q list available -q $_|) for @repos;
|
||||
chomp(@packages);
|
||||
return @packages;
|
||||
my @packages;
|
||||
my @repos = qx|equo repo list -q|;
|
||||
chomp(@repos);
|
||||
push( @packages, qx|equo q list available -q $_| ) for @repos;
|
||||
chomp(@packages);
|
||||
return @packages;
|
||||
}
|
||||
|
||||
# Input: package (sys-fs/foobarfs)
|
||||
# Output: Array of packages to be installed, that aren't installed in a Sabayon machine
|
||||
sub calculate_missing {
|
||||
my $package = shift;
|
||||
my $package = shift;
|
||||
|
||||
# Getting the package dependencies and the installed packages
|
||||
my @Packages = package_deps($package,1,1);
|
||||
my @Packages = package_deps( $package, 1, 1 );
|
||||
my @Installed_Packages = qx/equo q --quiet list installed/;
|
||||
chomp(@Installed_Packages);
|
||||
|
||||
#taking only the 4th column of output as key of the hashmap
|
||||
my %installed_packs = map { (split(/\s/,$_))[3] => 1 } @Installed_Packages;
|
||||
my %available_packs = map { $_ =>1 } available_packages();
|
||||
my %installed_packs =
|
||||
map { ( split( /\s/, $_ ) )[3] => 1 } @Installed_Packages;
|
||||
my %available_packs = map { $_ => 1 } available_packages();
|
||||
|
||||
# removing from packages the one that are already installed and keeping only the available in the entropy repositories
|
||||
my @to_install = grep( defined $available_packs{$_}, uniq( grep( !defined $installed_packs{$_}, @Packages )) );
|
||||
# removing from packages the one that are already installed and keeping only the available in the entropy repositories
|
||||
my @to_install = grep( defined $available_packs{$_},
|
||||
uniq( grep( !defined $installed_packs{$_}, @Packages ) ) );
|
||||
|
||||
return grep { length } @to_install;
|
||||
}
|
||||
@@ -72,50 +76,59 @@ sub atom { s/-[0-9]{1,}.*$//; }
|
||||
|
||||
# Input: Array
|
||||
# Output: array with unique elements
|
||||
sub uniq { keys %{ { map { $_ => 1 } @_ } }; }
|
||||
sub uniq {
|
||||
keys %{ { map { $_ => 1 } @_ } };
|
||||
}
|
||||
|
||||
# A barely print replacement
|
||||
sub say { print join( "\n", @_ ) . "\n"; }
|
||||
|
||||
sub help {
|
||||
say "-> You should feed me with something","","Examples:","", "\t$0 app-text/tree" , "\t$0 plasma-meta --layman kde","","**************************","", "You can supply multiple overlays as well: $0 plasma-meta --layman kde plab","";
|
||||
say "-> You should feed me with something", "", "Examples:", "",
|
||||
"\t$0 app-text/tree", "\t$0 plasma-meta --layman kde", "",
|
||||
"**************************", "",
|
||||
"You can supply multiple overlays as well: $0 plasma-meta --layman kde plab",
|
||||
"";
|
||||
}
|
||||
|
||||
say "************* IF YOU WANT TO SUPPLY ADDITIONAL ARGS TO EMERGE, pass to docker EMERGE_DEFAULT_OPTS env with your options *************";
|
||||
say
|
||||
"************* IF YOU WANT TO SUPPLY ADDITIONAL ARGS TO EMERGE, pass to docker EMERGE_DEFAULT_OPTS env with your options *************";
|
||||
|
||||
|
||||
if(@overlays>0){
|
||||
say "Overlay(s) to add";
|
||||
foreach my $overlay (@overlays){
|
||||
say "\t- $overlay";
|
||||
}
|
||||
if ( @overlays > 0 ) {
|
||||
say "Overlay(s) to add";
|
||||
foreach my $overlay (@overlays) {
|
||||
say "\t- $overlay";
|
||||
}
|
||||
}
|
||||
|
||||
say "Installing:";
|
||||
|
||||
say "\t* ".$_ for @ARGV;
|
||||
say "\t* " . $_ for @ARGV;
|
||||
|
||||
say "* Syncing stuff for you, if it's the first time, can take a while";
|
||||
|
||||
# Syncronizing portage configuration and adding overlays
|
||||
system("echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen"); #be sure about that.
|
||||
system("cd /etc/portage/;git checkout master; git pull;rm -rfv make.conf;ln -s make.conf.amd64 make.conf");
|
||||
system("echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen"); #be sure about that.
|
||||
system(
|
||||
"cd /etc/portage/;git checkout master; git pull;rm -rfv make.conf;ln -s make.conf.amd64 make.conf"
|
||||
);
|
||||
system("echo 'y' | layman -f -a $_") for @overlays;
|
||||
|
||||
my $reponame="LocalOverlay";
|
||||
my $reponame = "LocalOverlay";
|
||||
|
||||
# Setting up a local overlay if doesn't exists
|
||||
if (!-f "/usr/local/portage/profiles/repo_name") {
|
||||
if ( !-f "/usr/local/portage/profiles/repo_name" ) {
|
||||
system("mkdir -p /usr/local/portage/{metadata,profiles}");
|
||||
system("echo 'LocalOverlay' > /usr/local/portage/profiles/repo_name");
|
||||
system("echo 'masters = gentoo' > /usr/local/portage/metadata/layout.conf");
|
||||
system("chown -R portage:portage /usr/local/portage");
|
||||
} else {
|
||||
open FILE,"</usr/local/portage/profiles/repo_name";
|
||||
my @FILE=<FILE>;
|
||||
}
|
||||
else {
|
||||
open FILE, "</usr/local/portage/profiles/repo_name";
|
||||
my @FILE = <FILE>;
|
||||
close FILE;
|
||||
chomp(@FILE);
|
||||
$reponame=$FILE[0];
|
||||
$reponame = $FILE[0];
|
||||
}
|
||||
|
||||
qx{
|
||||
@@ -124,34 +137,39 @@ location = /usr/local/portage
|
||||
masters = gentoo
|
||||
priority=9999
|
||||
auto-sync = no' > /etc/portage/repos.conf/local.conf
|
||||
}; # Declaring the repo and giving priority
|
||||
}; # Declaring the repo and giving priority
|
||||
|
||||
system("mkdir -p /usr/portage/distfiles/git3-src");
|
||||
|
||||
# sync portage and overlays
|
||||
system("layman -S;emerge --sync");
|
||||
|
||||
# preparing for MOAR automation
|
||||
qx|eselect profile set $profile|;
|
||||
qx{ls /usr/portage/licenses -1 | xargs -0 > /etc/entropy/packages/license.accept}
|
||||
; #HAHA
|
||||
system("equo repo mirrorsort sabayonlinux.org;equo up && equo u") if $use_equo; # Better don't be behind
|
||||
; #HAHA
|
||||
system("equo repo mirrorsort sabayonlinux.org;equo up && equo u")
|
||||
if $use_equo; # Better don't be behind
|
||||
qx|echo 'ACCEPT_LICENSE="*"' >> /etc/portage/make.conf|; #just plain evil
|
||||
|
||||
my @packages = @ARGV;
|
||||
|
||||
if ($use_equo){
|
||||
my @packages_deps;
|
||||
foreach my $p (@packages){
|
||||
push(@packages_deps,calculate_missing($p,1)) if $equo_install_atoms;
|
||||
push(@packages_deps,package_deps($p,1,0)) if $equo_install_version;
|
||||
}
|
||||
@packages_deps = grep { defined() and length() } @packages_deps; #cleaning
|
||||
say "","Installing missing deps with equo", @packages_deps,"";
|
||||
if ( $equo_split_install) {
|
||||
system("equo i $_") for @packages_deps;
|
||||
} else {
|
||||
system("equo i @packages_deps");
|
||||
}
|
||||
if ($use_equo) {
|
||||
my @packages_deps;
|
||||
foreach my $p (@packages) {
|
||||
push( @packages_deps, calculate_missing( $p, 1 ) )
|
||||
if $equo_install_atoms;
|
||||
push( @packages_deps, package_deps( $p, 1, 0 ) )
|
||||
if $equo_install_version;
|
||||
}
|
||||
@packages_deps = grep { defined() and length() } @packages_deps; #cleaning
|
||||
say "", "Installing missing deps with equo", @packages_deps, "";
|
||||
if ($equo_split_install) {
|
||||
system("equo i $_") for @packages_deps;
|
||||
}
|
||||
else {
|
||||
system("equo i @packages_deps");
|
||||
}
|
||||
}
|
||||
|
||||
say "* Ready to compile, finger crossed";
|
||||
@@ -160,13 +178,15 @@ my $rt = system("emerge $emerge_defaults_args -j $jobs @packages");
|
||||
|
||||
my $return = $rt >> 8;
|
||||
|
||||
if($preserved_rebuild){
|
||||
if ($preserved_rebuild) {
|
||||
|
||||
system("emerge -j $jobs --buildpkg \@preserved-rebuild");
|
||||
system("emerge -j $jobs --buildpkg \@preserved-rebuild");
|
||||
|
||||
}
|
||||
|
||||
# Copy files to artifacts folder
|
||||
system("mkdir -p $artifacts_folder;cp -rfv /usr/portage/packages $artifacts_folder") if ($artifacts_folder and !$return );
|
||||
system(
|
||||
"mkdir -p $artifacts_folder;cp -rfv /usr/portage/packages $artifacts_folder"
|
||||
) if ( $artifacts_folder and !$return );
|
||||
|
||||
exit($return);
|
||||
|
||||
Reference in New Issue
Block a user