Compare commits

...

27 Commits

Author SHA1 Message Date
geaaru 4b5d3487c1 Merge pull request #24 from Sabayon/develop
New features
2019-11-06 14:43:02 +01:00
Daniele Rondina 2478662e00 builder: fix pkg version regex 2019-11-06 14:38:15 +01:00
Daniele Rondina 3e2a148a0b dynlink-scanner: qfile -e option is now -v 2019-10-27 13:38:51 +01:00
Daniele Rondina e569b59699 builder: Use last version or matching version for deps 2019-10-20 00:32:45 +02:00
Daniele Rondina 9f16462453 builder: Support previous implementation when dep_ignore_versions is disable 2019-10-07 17:33:50 +02:00
Daniele Rondina 8f5578b7f3 builder: review dependencies calculation
* Add support for env DEPENDENCY_IGNORE_VERSIONS for
  discard version of the packages to install as dependencies

* Add debugging log of installed equo repositories
2019-10-06 23:59:59 +02:00
Ettore Di Giacinto 1853c68b0d Merge pull request #23 from Sabayon/develop
Merge Develop
2019-09-11 20:31:26 +02:00
Ettore Di Giacinto 46204e0562 Merge pull request #21 from Sabayon/broken-links
Add sabayon-brokenlinks script
2019-09-11 20:30:15 +02:00
Daniele Rondina 460101a985 sabayon-brokenlinks: Use FORCE/--force instead of --force-manual 2019-09-11 11:45:37 +02:00
geaaru 7c059c3c9a Merge pull request #22 from gktrk/typo-fix
sabayondevkit-functions.sh: fix a typo, s/of/or/
2019-09-10 10:49:27 +02:00
Göktürk Yüksek e274ddffa3 sabayondevkit-functions.sh: fix a typo, s/of/or/ 2019-09-09 10:28:17 -04:00
Daniele Rondina e7aade22a0 sabayon-brokenlinks: Use USE_EQUO instead of GENTOO_TOOL env 2019-08-23 23:12:32 +02:00
Daniele Rondina d72e8c220b sabayon-brokenlinks: Minor fix on message 2019-08-23 15:02:25 +02:00
Daniele Rondina 280a665707 sabayon-brokenlinks: Add support for libs *.a 2019-08-23 14:59:19 +02:00
Daniele Rondina 631072d2a5 sabayon-brokenlinks: Use equo by default as tool 2019-08-21 18:41:32 +02:00
Daniele Rondina 4839c818de sabayon-brokenlinks: Review with cli arguments support 2019-08-13 15:33:11 +02:00
Daniele Rondina 11977d3afd sabayon-brokenlinks: Integrate automatic remove of broken links 2019-08-12 17:09:30 +02:00
Daniele Rondina 5972c0137f sabayon-brokenlinks: WIP 2019-08-09 19:45:05 +02:00
Ettore Di Giacinto 3be4345ae4 Merge pull request #19 from Sabayon/develop
builder: Add support for git portage tarball
2019-04-27 15:57:22 +02:00
Daniele Rondina 286533e74e builder: Use rsync instead of cp on copy git portage 2019-04-03 18:16:43 +02:00
Daniele Rondina a3f9796c6d builder: Add support for git portage tarball 2019-03-22 22:06:29 +01:00
Ettore Di Giacinto 1921cae295 Extract common func to setup perms, fix git3 perms 2018-09-26 20:14:13 +02:00
Ettore Di Giacinto 3322c5aa17 Make non fatal equo install deps 2018-07-28 18:14:35 +02:00
Ettore Di Giacinto 95ffe4d49d Add hook script function 2018-07-22 17:24:36 +02:00
Ettore Di Giacinto 59855f3bb1 Be quiet also on emerge --sync 2018-07-22 16:46:25 +02:00
Ettore Di Giacinto d151a77e51 Prefer long syntax option 2018-07-22 15:47:43 +02:00
Ettore Di Giacinto 8fda356c53 Also include summary in injected_targets 2018-07-21 21:38:42 +02:00
4 changed files with 700 additions and 36 deletions
+236 -34
View File
@@ -15,31 +15,39 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
use URI;
use Getopt::Long; use Getopt::Long;
use v5.10; use v5.10;
no feature "say"; no feature "say";
use Storable 'dclone'; use Storable 'dclone';
use Sort::Versions;
my $profile = $ENV{BUILDER_PROFILE} // 16; my $profile = $ENV{BUILDER_PROFILE} // 16;
my $jobs = $ENV{BUILDER_JOBS} // 1; my $jobs = $ENV{BUILDER_JOBS} // 1;
my $use_equo = $ENV{USE_EQUO} // 1; my $use_equo = $ENV{USE_EQUO} // 1;
my $preserved_rebuild = $ENV{PRESERVED_REBUILD} // 0; my $preserved_rebuild = $ENV{PRESERVED_REBUILD} // 0;
my $emerge_defaults_args = $ENV{EMERGE_DEFAULTS_ARGS} my $emerge_defaults_args = $ENV{EMERGE_DEFAULTS_ARGS}
// "--accept-properties=-interactive --q --oneshot --complete-graph --buildpkg"; // "--accept-properties=-interactive --quiet --oneshot --complete-graph --buildpkg";
$ENV{FEATURES} = $ENV{FEATURES} $ENV{FEATURES} = $ENV{FEATURES}
// "parallel-fetch protect-owned compressdebug splitdebug -userpriv"; // "parallel-fetch protect-owned compressdebug splitdebug -userpriv";
my $equo_install_atoms = $ENV{EQUO_INSTALL_ATOMS} // 1; my $equo_install_atoms = $ENV{EQUO_INSTALL_ATOMS} // 1;
my $equo_install_version = $ENV{EQUO_INSTALL_VERSION} // 0; my $equo_install_version = $ENV{EQUO_INSTALL_VERSION} // 0;
my $equo_split_install = $ENV{EQUO_SPLIT_INSTALL} // 0; my $equo_split_install = $ENV{EQUO_SPLIT_INSTALL} // 0;
my $equo_mirrorsort = $ENV{EQUO_MIRRORSORT} // 1; my $equo_mirrorsort = $ENV{EQUO_MIRRORSORT} // 1;
my $entropy_repository = $ENV{ENTROPY_REPOSITORY} my $entropy_repository = $ENV{ENTROPY_REPOSITORY}
// "main"; # Can be weekly, main, testing // "main"; # Can be weekly, main, testing
my $artifacts_folder = $ENV{ARTIFACTS_DIR}; my $artifacts_folder = $ENV{ARTIFACTS_DIR};
my $dep_scan_depth = $ENV{DEPENDENCY_SCAN_DEPTH} // 2; my $dep_scan_depth = $ENV{DEPENDENCY_SCAN_DEPTH} // 2;
my $dep_ignore_versions = $ENV{DEPENDENCY_IGNORE_VERSIONS} // 0;
my $skip_portage_sync = $ENV{SKIP_PORTAGE_SYNC} // 0; my $skip_portage_sync = $ENV{SKIP_PORTAGE_SYNC} // 0;
my $emerge_split_install = $ENV{EMERGE_SPLIT_INSTALL} // 0; my $emerge_split_install = $ENV{EMERGE_SPLIT_INSTALL} // 0;
my $webrsync = $ENV{WEBRSYNC} // 0; my $webrsync = $ENV{WEBRSYNC} // 0;
# Define git tarball url to use instead of webrsync or emerge --sync
my $portage_git_url = $ENV{PORTAGE_GIT_URL} // "";
# Define supported tarball types: github|gitlab
my $portage_git_service = $ENV{PORTAGE_GIT_SRV} // "github";
my $portage_git_branch = $ENV{PORTAGE_GIT_BRANCH} // "master";
my $enman_repositories = $ENV{ENMAN_REPOSITORIES}; my $enman_repositories = $ENV{ENMAN_REPOSITORIES};
my $emerge_remove = $ENV{EMERGE_REMOVE}; my $emerge_remove = $ENV{EMERGE_REMOVE};
my $remove_enman_repositories = $ENV{REMOVE_ENMAN_REPOSITORIES}; my $remove_enman_repositories = $ENV{REMOVE_ENMAN_REPOSITORIES};
@@ -128,6 +136,11 @@ sub parse_overlays {
map { $_ =~ s/.*?\:\://g; $_ } grep {/\:\:/} @{ dclone( \@_ ) }; map { $_ =~ s/.*?\:\://g; $_ } grep {/\:\:/} @{ dclone( \@_ ) };
} }
sub hook_script {
my $s = shift;
_system("chmod +x ${s};${s}") if -e $s;
}
sub add_portage_repository { sub add_portage_repository {
my $repo = $_[0]; my $repo = $_[0];
my $reponame; my $reponame;
@@ -165,6 +178,146 @@ auto-sync = yes' > /etc/portage/repos.conf/$reponame.conf
# Input: package, depth, and atom. Package: sys-fs/foobarfs, Depth: 1 (depth of the package tree) , Atom: 1/0 (enable disable atom output) # Input: package, depth, and atom. Package: sys-fs/foobarfs, Depth: 1 (depth of the package tree) , Atom: 1/0 (enable disable atom output)
my %package_dep_cache; my %package_dep_cache;
sub parse_package_str {
my ($pkg, $p, $cat, $v) = @_;
my @parts = split '/', $pkg;
$p = $parts[1];
$cat = $parts[0];
$regex = '[-]r[\d]$';
$regex .= '|_p[\d]+[-]r[\d]$';
$regex .= '|_p[\d]+$';
$regex .= '|_alpha[\d]*$';
$regex .= '|_beta[\d]*$';
$regex .= '|_pre[\d]*$';
$regex .= '|_pre[\d]*[-]r[\d]$';
$regex .= '|_rc[\d]*$';
# Drop extra version suffix for now.
$p =~ s/($regex)//g;
$v = $p; # Version regex
# 1.1
$version_regex = "[0-9]+[.][0-9]+[a-z]*";
# 1
$version_regex .= "|[0-9]+[a-z]*";
# 1.1.1
$version_regex .= "|[0-9]+[.][0-9]+[.][0-9]+[a-z]*";
# 1.1.1.1
$version_regex .= "|[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[a-z]*";
# 1.1.1.1.1
$version_regex .= "|[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[a-z]*";
# 1.1.1.1.1.1
$version_regex .= "|[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[.][0-9]+[a-z]*";
$p =~ m/[-]($version_regex)*$/;
$v = $&; $v = substr $v, 1 if length($v) > 1;
$p =~ s/-[\d.]*$//g;
return $cat, $p, $v;
}
sub parse_package_version {
my ($cat, $p, $v) = parse_package_str(@_);
return $v;
}
sub simplify_package {
my ($cat, $p, $v) = parse_package_str(@_);
$ans = $cat . "/" . $p ;
return $ans;
}
sub sanitize_deps {
my ($pkg, $atom, $dref, $verion) = @_;
my @dependencies = @{ $dref };
my $prev_key = undef;
my %revs = ();
if ($dep_ignore_versions) {
for (@dependencies) {
chomp($_);
if (length($_) > 0) {
if ($_ =~ m/\[\s+\d\]/) {
my $pkgs = $revs{$prev_key};
push(@$pkgs, $_);
} else {
$prev_key = substr $_, 0, length($_)-1
unless substr($_, -1) cmp ":";
my ($pkg, $p, $v) = parse_package_str($prev_key);
$revs{$v} = [];
$prev_key = $v;
}
}
}
# revs dictionary contains as keys versions of the package
# and as values an array ref with list of dependencies + itself
# Ex:
# %revs = (
# '1.8.5' => [
# ' [ 0] dev-lang/spidermonkey-1.8.5-r9 ',
# ' [ 1] dev-libs/nspr-4.22 ',
# ' [ 1] sys-libs/readline-7.0_p5 ',
# ' [ 1] dev-libs/jemalloc-3.6.0 ',
# ' [ 1] dev-lang/python-2.7.16 ',
# ' [ 1] app-arch/zip-3.0-r3 ',
# ' [ 1] virtual/pkgconfig-1 ',
# ' [ 1] app-portage/elt-patches-20170815 ',
# ' [ 1] sys-devel/automake-1.16.1-r1 ',
# ' [ 1] sys-devel/automake-1.15.1-r2 ',
# ' [ 1] sys-devel/autoconf-2.13-r1 ',
# ' [ 1] sys-devel/libtool-2.4.6-r3 '
# ],
# )
$v = parse_package_version($pkg);
if (length($v) > 0 && defined %revs{$v}) {
$version = $v;
} else {
@versions = sort { &Sort::Versions::versioncmp($a,$b) } keys %revs;
$version = $versions[scalar(@versions)-1];
}
$ref = $revs{$version};
loud("For package $pkg use version $version with deps: ", @$ref)
if $verbose;
@dependencies = uniq(
grep {$_}
map {
$_ =~ s/\[.*\]|\s//g;
$_ =~ s/[:]$//g; # drop : at the end
&abs_atom($_) if $atom;
$_
}
@$ref
);
} else {
# Merge all versions dependencies as previous implementation.
#
# If an unversioned atom is given, equery returns results for all versions in the portage tree
# leading to duplicates. The sanest thing to do is dedup the list. This gives the superset of all
# possible dependencies, which isn't perfectly accurate but should be good enough. For completely
# accurate results, pass in a versioned atom.
@dependencies = uniq(
sort
grep {$_}
map {
$_ =~ s/\[.*\]|\s//g;
$_ =~ s/[:]$//g; # drop : at the end
&abs_atom($_) if $atom;
$_
}
@dependencies
);
}
return sort(@dependencies);
}
sub package_deps { sub package_deps {
my $package = shift; my $package = shift;
my $depth = shift // 1; # defaults to 1 level of depthness of the tree my $depth = shift // 1; # defaults to 1 level of depthness of the tree
@@ -178,17 +331,8 @@ sub package_deps {
qx/equery -C -q g --depth=$depth '$package'/; #depth=0 it's all qx/equery -C -q g --depth=$depth '$package'/; #depth=0 it's all
chomp @dependencies; chomp @dependencies;
# If an unversioned atom is given, equery returns results for all versions in the portage tree # Get dependencies only of major version
# leading to duplicates. The sanest thing to do is dedup the list. This gives the superset of all @dependencies = sanitize_deps($package, $atom, \@dependencies);
# possible dependencies, which isn't perfectly accurate but should be good enough. For completely
# accurate results, pass in a versioned atom.
@dependencies = uniq(
sort
grep {$_}
map { $_ =~ s/\[.*\]|\s//g; &abs_atom($_) if $atom; $_ }
@dependencies
);
$package_dep_cache{$cache_key} = \@dependencies; $package_dep_cache{$cache_key} = \@dependencies;
} }
@@ -262,6 +406,12 @@ sub calculate_missing {
return @to_install; return @to_install;
} }
sub portage_perms {
my $dir = shift;
_system("chown -R portage:portage $dir");
_system("chmod -R ug+w,a+rX $dir");
}
# Input : complete gentoo package (sys-fs/foobarfs-1.9.2) # Input : complete gentoo package (sys-fs/foobarfs-1.9.2)
# Output: atom form (sys-fs/foobarfs) # Output: atom form (sys-fs/foobarfs)
sub atom { s/-[0-9]{1,}.*$//; } sub atom { s/-[0-9]{1,}.*$//; }
@@ -331,6 +481,39 @@ sub compile_packs {
return $compiled; return $compiled;
} }
sub fetch_portage_from_git {
my ( $url, $srv, $branch ) = @_;
$url = substr($url, 0, length($url)-1) unless substr($url, -1) cmp "/";
my $uri = URI->new($url);
my $base = ( $uri->path_segments )[-1];
say "==== Fetching $srv Portage for branch $branch ====";
if ( $srv and $srv eq "gitlab" ) {
$url .= "/-/archive/$branch/$base-$branch.tar.gz";
} else {
$url .= "/archive/$branch.tar.gz";
}
_system( "wget -O /tmp/portage.tar.gz $url" );
_system( "mkdir /tmp/portage ; tar xzf /tmp/portage.tar.gz -C /tmp/portage" );
# Avoid to remove /usr/portage for use case where I have already
# files under /usr/portage/distfiles or /usr/portage/packages to use.
my @excluded_dirs = (
"'distfiles'",
"'packages'"
);
my $rsync_opts = "-a --delete --delete-during --recursive -d -A -H";
$rsync_opts .= " --exclude $_" foreach @excluded_dirs;
_system( "rsync $rsync_opts /tmp/portage/$base-$branch/ /usr/portage/" );
_system( "rm -rf /tmp/portage " );
}
sub help { sub help {
say "-> You should feed me with something", "", "Examples:", "", say "-> You should feed me with something", "", "Examples:", "",
"\t$0 app-text/tree", "\t$0 plasma-meta --layman kde", "", "\t$0 app-text/tree", "\t$0 plasma-meta --layman kde", "",
@@ -383,8 +566,7 @@ system("echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen"); #be sure about that.
if ( $remote_conf_portdir ne "" ) { if ( $remote_conf_portdir ne "" ) {
_system("rm -rf /etc/portage"); _system("rm -rf /etc/portage");
_system("git clone $remote_conf_portdir /etc/portage"); _system("git clone $remote_conf_portdir /etc/portage");
_system("chown -R portage:portage /etc/portage"); portage_perms('/etc/portage');
_system("chmod -R ug+w,a+rX /etc/portage");
} }
else { else {
_system("cd /etc/portage/;git checkout master; git stash; git pull"); _system("cd /etc/portage/;git checkout master; git stash; git pull");
@@ -394,9 +576,8 @@ else {
if ( $remote_portdir ne "" ) { if ( $remote_portdir ne "" ) {
_system("rm -rf /usr/portage"); _system("rm -rf /usr/portage");
_system("git clone $remote_portdir /usr/portage"); _system("git clone $remote_portdir /usr/portage");
_system("chown -R portage:portage /usr/portage");
_system("chmod -R ug+w,a+rX /usr/portage");
} }
_system("mkdir /var/lib/layman") if ( !-d "/var/lib/layman" ); _system("mkdir /var/lib/layman") if ( !-d "/var/lib/layman" );
_system("touch /var/lib/layman/make.conf && layman-updater -R") _system("touch /var/lib/layman/make.conf && layman-updater -R")
if ( !-e "/var/lib/layman/make.conf" ); if ( !-e "/var/lib/layman/make.conf" );
@@ -423,8 +604,7 @@ else {
chomp(@FILE); chomp(@FILE);
$reponame = $FILE[0]; $reponame = $FILE[0];
} }
_system("chown -R portage:portage /usr/local/portage"); portage_perms('/usr/local/portage');
_system("chmod -R 755 /usr/local/portage");
qx{ qx{
echo '[$reponame] echo '[$reponame]
@@ -450,16 +630,21 @@ if ( $remove_remote_overlay and $remove_remote_overlay ne "" ) {
} }
_system("mkdir -p /usr/portage/distfiles/git3-src"); _system("mkdir -p /usr/portage/distfiles/git3-src");
portage_perms('/usr/portage');
unless ( $skip_portage_sync == 1 ) { unless ( $skip_portage_sync == 1 ) {
# sync portage and overlays # sync portage and overlays
_system("layman -S"); _system("layman -S");
if ( $webrsync == 1 ) { if ( $portage_git_url ne "" and $portage_git_branch ne "" ) {
fetch_portage_from_git( $portage_git_url, $portage_git_service,
$portage_git_branch );
}
elsif ( $webrsync == 1 ) {
_system("emerge-webrsync"); _system("emerge-webrsync");
} }
else { else {
_system("emerge --sync"); _system("emerge --sync --quiet");
} }
} }
@@ -615,7 +800,7 @@ if ($use_equo) {
say "", "[install] Those dependencies will be installed with equo :", say "", "[install] Those dependencies will be installed with equo :",
@packages_deps, ""; @packages_deps, "";
if ($equo_split_install) { if ($equo_split_install) {
safe_call("equo i $equo_install_args --bdeps '$_'") _system("equo i $equo_install_args --bdeps '$_'")
for ( @packages_deps, @equo_install ) for ( @packages_deps, @equo_install )
; ## bail out here, if installs fails. emerge will compile a LOT of stuff ; ## bail out here, if installs fails. emerge will compile a LOT of stuff
if ( @equo_remove > 0 and !$pretend ) { if ( @equo_remove > 0 and !$pretend ) {
@@ -626,7 +811,7 @@ if ($use_equo) {
else { else {
my @p = map {"'$_'"} ( @packages_deps, @equo_install ); my @p = map {"'$_'"} ( @packages_deps, @equo_install );
my @r = map {"'$_'"} @equo_remove; my @r = map {"'$_'"} @equo_remove;
safe_call("equo i $equo_install_args --bdeps @p") _system("equo i $equo_install_args --bdeps @p")
if ( @p > 0 ) if ( @p > 0 )
; ## bail out here, if installs fails. emerge will compile a LOT of stuff ; ## bail out here, if installs fails. emerge will compile a LOT of stuff
_system("equo rm --nodeps @r") if ( @r > 0 ); _system("equo rm --nodeps @r") if ( @r > 0 );
@@ -638,12 +823,16 @@ loud "Pre-compilation phase start";
_system("emerge --info") _system("emerge --info")
; #always give detailed information about the building environment, helpful to debug ; #always give detailed information about the building environment, helpful to debug
_system("equo repo list")
; #always give list of repo installed to for reproduce conflicts install issues.
if ( $emerge_remove and $emerge_remove ne "" ) { if ( $emerge_remove and $emerge_remove ne "" ) {
say "Removing with emerge: $emerge_remove"; say "Removing with emerge: $emerge_remove";
_system("emerge -C '$_'") for split( / /, $emerge_remove ); _system("emerge -C '$_'") for split( / /, $emerge_remove );
} }
_system("chmod +x /pre-script;./pre-script") if -e "/pre-script"; hook_script("./pre-script");
hook_script("/pre-script");
loud "Compilation phase start"; loud "Compilation phase start";
@@ -668,12 +857,25 @@ else {
$return = $rt >> 8; $return = $rt >> 8;
} }
loud "Compilation phase end"; if ( @injected_packages > 0 ) {
my $res = compile_packs( "injected_targets", @injected_packages );
loud "Compilation summary for injected_targets";
foreach my $k ( keys %{$res} ) {
my $c = $res->{$k} >> 8;
if ( $c != 0 ) {
say "$k : build failed ( Exit: $c )";
$return = 1 unless $keep_going;
}
else {
say "$k : build succeeded";
}
}
}
# best effort -B loud "Compilation phase end (Exit: $return)";
compile_packs( "injected_targets", @injected_packages );
_system("chmod +x /post-script;./post-script") if -e "/post-script"; hook_script("./post-script");
hook_script("/post-script");
if ( $preserved_rebuild and !$pretend ) { if ( $preserved_rebuild and !$pretend ) {
+1 -1
View File
@@ -46,5 +46,5 @@ for cpv in `portageq match $ROOT/ $1`; do
# For each file that belongs to package # For each file that belongs to package
# run dynlink-scanner --linking-deps <file> to obtain its linking dependencies # run dynlink-scanner --linking-deps <file> to obtain its linking dependencies
# Assign all linking deps to packages and print package names # Assign all linking deps to packages and print package names
qfile -eR $ROOT `portageq contents $ROOT/ $cpv | xargs -r -L 1 "$0" --linking-deps` | cut -f1 -d' ' | sort -u qfile -vR $ROOT `portageq contents $ROOT/ $cpv | xargs -r -L 1 "$0" --linking-deps` | cut -f1 -d' ' | sort -u
done done
+462
View File
@@ -0,0 +1,462 @@
#!/bin/bash
# Authors: Sabayon Team 2019
set -e
# Accepted values: x86_64, armv7l
export SAB_ARCH="${SAB_ARCH:-}"
export DRY_RUN=${DRY_RUN:-0}
export DEBUG="${DEBUG:-}"
export FORCE="${FORCE:-0}"
export USE_EQUO="${USE_EQUO:-1}"
declare -a MANUALLY_REMOVED_LINKS
declare -a BROKEN_LINKS2REMOVE
log() {
local with_dashes=$1
shift || true
[ "$with_dashes" != 1 ] || \
echo "==============================================================="
echo "$@"
[ "$with_dashes" != 1 ] || \
echo "==============================================================="
}
summary() {
local msg="SAB_ARCH = ${SAB_ARCH}
EXAMINED_LIBDIRS = ${EXAMINED_LIBDIRS}
DRY_RUN = ${DRY_RUN}
USE_EQUO = ${USE_EQUO}
FORCE = ${FORCE}"
log 1 "$msg"
}
check_arch() {
if [ -z "${SAB_ARCH}" ] ; then
SAB_ARCH=$(uname -m)
fi
[[ "${SAB_ARCH}" != "x86_64" && "${SAB_ARCH}" != "armv7l" ]] && {
log 1 "Unsupported arch ${SAB_ARCH}."
exit 1
}
export SAB_ARCH
}
search_pkg() {
local basename=$1
# passed by reference
local -n p="$2"
local -n libdir="$3"
local lib="$4"
local l=""
local ll=""
# Try to search for package
if [ "${USE_EQUO}" = "0" ] ; then
p=$(equery -N -q -C belongs ${lib}/$basename --early-out || true)
else
p=$(equo q belongs ${lib}/${basename} -q || true)
fi
if [ -z "$p" ] ; then
for l in "/usr/lib64" "/usr/lib32" "/usr/lib" ; do
if [ "$lib" = "$l" ] ; then
ll="${l/\/usr\///}"
break
fi
done
if [ -n "${ll}" ] ; then
if [ "${USE_EQUO}" = "0" ] ; then
p=$(equery -N -q -C belongs ${ll}/$basename --early-out || true)
else
p=$(equo q belongs ${ll}/${basename} -q || true)
fi
fi
fi
if [ -z "$p" ] ; then
libdir=""
fi
}
detect_libs_dir() {
local libs=""
if [ -n "$SCANDIR" ] ; then
libs=$SCANDIR
else
if [ "${SAB_ARCH}" = "x86_64" ] ; then
if [ -d "/usr/lib32" ] ; then
libs="/usr/lib32 /lib32"
fi
if [ -d "/usr/lib64" ] ; then
libs="$libs /usr/lib64 /lib64"
fi
else
if [ -d "/usr/lib" ] ; then
libs="/usr/lib /lib"
fi
fi
if [ -z "$libs" ] ; then
log 0 "Error on detect libraries directories."
exit 1
fi
fi
EXAMINED_LIBDIRS=$libs
export EXAMINED_LIBDIRS
}
examine_libs() {
local lib=""
local file=""
local broken_files=""
log 1 "The exam could be long sorry for the wait."
for lib in ${EXAMINED_LIBDIRS} ; do
broken_files=""
log 1 "Checking directory $lib..."
broken_files=$(find $lib -type l -and -xtype l -and -name *.so* -or -name *.a -and -type l -and -xtype l 2>/dev/null || true )
[ -z "$DEBUG" ] || {
find $lib -type l -and -xtype l -and -name *.so* -or -name *.a -and -type l -and -xtype l || true
}
for file in ${broken_files} ; do
examine_file "${file}" "${lib}"
done
done
}
examine_file() {
local f=$1
local res=""
local libdir=$2
local is_present_pkg=1
local pkg=""
[ -z "$DEBUG" ] || log 1 "Analyze file $f"
local base=$(basename $1)
local targetlink=$(readlink $f)
local link2remove=false
local link2fix=false
local newlibdir=""
local tmp=""
local current_link=""
log 1 "Broken link $f => $targetlink"
# Check if file is without revision (es. libudev.so)
res=$(perl -e "if ('$base' =~ /(.so|.a$)/) { print '1' }")
if [ -n "$res" ] ; then
#
#echo "BASE = $base"
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
MANUALLY_REMOVED_LINKS+=( "$f" )
return
else
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
fi
fi
if [ "${USE_EQUO}" = "0" ] ; then
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
else
res=$(equo q files $pkg -q | grep $f | wc -l)
fi
if [ "$res" = 1 ] ; then
link2fix=true
echo "Link $f related to existing package. Try to reinstall $pkg."
else
MANUALLY_REMOVED_LINKS+=( "$f" )
fi
log 0 "Link $f of the package $pkg"
else
# Check if file has only one revision number (es. libudev.so.0)
res=$(perl -e "if ('$base' =~ /(.so[.][\d]+$)/) { print '1' }")
if [ -n "$res" ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
# Try to search package with .so
base=$(echo "$base" | awk 'match($0, /.so/) { print substr($0, 0, RSTART+2) }')
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
log 0 "No package found for link $f."
MANUALLY_REMOVED_LINKS+=( "$f" )
return
fi
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# POST: we have a broken link or old link
current_link=$(readlink $lib/$base)
log 0 "Link $f related to package $pkg (with an updated version $current_link). I remove it."
link2remove=true
fi
else
log 0 "Link $f of the package $pkg"
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# Check new
if [ "${USE_EQUO}" = "0" ] ; then
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
else
res=$(equo q files $pkg -q | grep $f | wc -l)
fi
if [ "$res" = 1 ] ; then
link2fix=true
echo "Link $f related to existing package. Try to reinstall $pkg."
else
MANUALLY_REMOVED_LINKS+=( "$f" )
fi
fi
fi
else
# Check if file has only one revision number (es. libudev.so.0.63)
res=$(perl -e "if ('$base' =~ /(.so[.][\d]+[.][\d]+$)/) { print '1' }")
if [ -n "$res" ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
base=$(echo "$base" | awk 'match($0, /.so[.][0-9]+/) { print substr($0, 0, RSTART+RLENGTH-1) }')
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
log 0 "No package found for link $f."
MANUALLY_REMOVED_LINKS+=( "$f" )
return
fi
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
current_link=$(readlink $lib/$base)
log 0 "Link $f related to package $pkg (with an updated version $current_link). I remove it."
link2remove=true
fi
else
log 0 "Link $f of the package $pkg"
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# Check new
if [ "${USE_EQUO}" = "0" ] ; then
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
else
res=$(equo q files $pkg -q | grep $f | wc -l)
fi
if [ "$res" = 1 ] ; then
link2fix=true
echo "Link $f related to existing package. Try to reinstall $pkg."
else
MANUALLY_REMOVED_LINKS+=( "$f" )
fi
fi
fi
else
echo "Link $f not supported".
MANUALLY_REMOVED_LINKS+=( "$f" )
fi
fi
fi
if [ $link2remove = true ] ; then
BROKEN_LINKS2REMOVE+=( "$f" )
fi
}
rm_broken_links() {
for l in ${BROKEN_LINKS2REMOVE[@]} ; do
if [ "$DRY_RUN" = 0 ]; then
rm -vf ${l}
else
echo "rm -vf ${l}"
fi
done
}
print_links2remove() {
for l in ${MANUALLY_REMOVED_LINKS[@]} ; do
if [ "$FORCE" = 1 ] ; then
if [ "$DRY_RUN" = 0 ] ; then
rm -vf ${l}
else
echo "force: rm -vf ${l}"
fi
else
echo "rm -vf ${l}"
fi
done
}
parse_args() {
help_message() {
echo "Sabayon Broken Links analyzer.
Sabayon Team (2019)
$0 [opts]
Available options:
-h|--help This message.
--dry-run Dry run execution.
--force Force remove of the links to remove manually.
--scandir Define a specific directory to analyze
--gentoo Use gentoo tool instead of equo.
-d|--debug Enable debug stuff.
Environment variables:
DRY_RUN To use instead of --dry-run option. Values: 0 or 1.
DEBUG Enable debug output.
USE_EQUO To use instead of --gentoo option.
FORCE To use instead of --force.
"
}
local short_opts="hd"
local long_opts="help dry-run force debug scandir: gentoo"
$(set -- $(getopt -u -q -a -o "$short_opts" -l "$long_opts" -- "$@"))
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
help_message
exit 1
;;
-d|--debug)
DEBUG=1
;;
--force)
FORCE=1
;;
--dry-run)
DRY_RUN=1
;;
--scandir)
SCANDIR="$2"
shift
;;
--gentoo)
USE_EQUO=0
;;
--)
;;
*)
echo "Invalid parameter $1."
exit 1
;;
esac
shift
done
unset -f help_message
}
main() {
parse_args "$@"
log 1 "sabayon-brokenlinks: Examine system broken links"
check_arch
detect_libs_dir
summary
if [[ "$(id -u)" != "0" && "${DRY_RUN}" != "1" ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
parse_args
unset -f parse_args
if [ "${USE_EQUO}" = "0" ] ; then
which equery 2>&1 >/dev/null || {
echo "equery tool is needed. Please install app-portage/gentoolkit."
exit 1
}
which qlist 2>&1 >/dev/null || {
echo "qlist tool is needed. Please install app-portage/portage-utils."
exit 1
}
fi
examine_libs
if [ ${#BROKEN_LINKS2REMOVE[@]} -gt 0 ] ; then
log 1 "Remove Broken Links!"
rm_broken_links
fi
if [ ${#MANUALLY_REMOVED_LINKS[@]} -gt 0 ] ; then
if [ "${FORCE}" = 1 ] ; then
log 1 "Hereinafter, links removed with force:"
else
log 1 "Hereinafter, links to manually remove:"
fi
print_links2remove
fi
echo "All Done."
}
main $@
+1 -1
View File
@@ -8,7 +8,7 @@ check_docker_requirements(){
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
groups | grep -q docker || echo "--> If you are not running the script as root, your user should be in the docker group to use it. (sudo gpasswd -a $USER docker)" groups | grep -q docker || echo "--> If you are not running the script as root, your user should be in the docker group to use it. (sudo gpasswd -a $USER docker)"
fi fi
ps aux | grep -q '[d]ocker' || echo "--> Be sure to have the docker daemon running (sudo systemctl start docker) of configure it to run on boot (sudo systemctl enable docker). Trying to start it anyway" && systemctl start docker || true ps aux | grep -q '[d]ocker' || echo "--> Be sure to have the docker daemon running (sudo systemctl start docker) or configure it to run on boot (sudo systemctl enable docker). Trying to start it anyway" && systemctl start docker || true
} }
die() { echo "$@" 1>&2 ; exit 1; } die() { echo "$@" 1>&2 ; exit 1; }