5 kx #!/bin/env perl
5 kx
5 kx use FindBin;
5 kx use lib $FindBin::Bin;
5 kx
5 kx use strict;
5 kx use warnings FATAL => 'all';
5 kx
5 kx use File::Basename;
5 kx use Fcntl ':flock';
5 kx use _kxLab;
5 kx
5 kx my $distro = _kxLab::distro_name();
5 kx
5 kx my @arguments;
5 kx my ( $base, $toolchain, $hardware, $flavour );
5 kx my $target_build_dir;
5 kx
5 kx my $curdir = $ENV{CWD};
5 kx my $removepkg = $ENV{REMOVE_PACKAGE};
5 kx my $fname = "";
5 kx my $pkg = "";
5 kx
5 kx my $pkg_name = "";
5 kx my $pkg_group = "";
5 kx my $pkg_dir = "";
5 kx my $rootfs_dir = "";
5 kx
5 kx sub usage
5 kx {
5 kx print <<EOF;
5 kx
5 kx Usage: rootfs_clean [options]
5 kx Options:
5 kx --destination=ROOTFS - where ROOTFS is a destination directory.
5 kx --toolchain=TOOLCHAIN - where TOOLCHAIN ia a toolchain name;
5 kx --hardware=HARDWARE - where HARDWARE ia a HARDWARE name;
5 kx --flavour=FLAVOUR - where FLAVOUR ia a FLAVOUR name.
5 kx
5 kx EOF
5 kx exit;
5 kx }
5 kx
5 kx foreach ( @ARGV )
5 kx {
5 kx if( /--destination=(\S*)/ )
5 kx {
5 kx $base = $1;
5 kx }
5 kx elsif( /--toolchain=(\S*)/ )
5 kx {
5 kx $toolchain = $1;
5 kx }
5 kx elsif( /--hardware=(\S*)/ )
5 kx {
5 kx $hardware = $1;
5 kx }
5 kx elsif( /--flavour=(\S*)/ )
5 kx {
5 kx $flavour = $1;
5 kx }
5 kx elsif( /--help/ )
5 kx {
5 kx usage;
5 kx }
5 kx }
5 kx
5 kx if( ! defined $base or $base eq "" ) { usage; }
5 kx if( ! defined $toolchain or $toolchain eq "" ) { usage; }
5 kx if( ! defined $hardware or $hardware eq "" ) { usage; }
5 kx if( ! defined $flavour or $flavour eq "" )
5 kx {
5 kx $flavour = "";
5 kx $target_build_dir = "." . $toolchain . "/" . $hardware;
5 kx }
5 kx else
5 kx {
5 kx $target_build_dir = "." . $toolchain . "/" . $hardware . "/" . $flavour;
5 kx }
5 kx
5 kx if ( $curdir )
5 kx {
5 kx $fname = "$curdir/" . $target_build_dir . "/.rootfs";
5 kx }
5 kx else
5 kx {
5 kx $fname = $target_build_dir . "/.rootfs";
5 kx }
5 kx
5 kx
5 kx open( F, '<', $fname ) or die "Could not open '$fname'";
5 kx
5 kx
5 kx while( <F> )
5 kx {
5 kx chomp;
5 kx
5 kx $pkg = "$base/$_";
5 kx $pkg_group = dirname( $pkg ); # extract GROUP if present:
5 kx $pkg_group =~ s!/.+/var/log/$distro/packages/!!;
5 kx $pkg_name = basename( $pkg );
5 kx $pkg_dir = dirname( $pkg );
5 kx $rootfs_dir = $pkg_dir;
5 kx $rootfs_dir =~ s!/var/log/$distro/packages.*$!!;
5 kx
5 kx #####################
5 kx # LOCK procedure:
5 kx #
5 kx #my $lock_fname = _kxLab::build_system_tmpdir() . "/." . $hardware . ".pkgtool-lock";
5 kx #open( my $lock_fh, '+>', $lock_fname ) or
5 kx # _kxLab::error( "$0: Could not open $lock_fname file: $!" );
5 kx #flock( $lock_fh, LOCK_EX ) or
5 kx # _kxLab::error( "$0: Cannot lock $lock_fname file: $!" );
5 kx
5 kx _kxLab::system( "$removepkg --ignore-chrefs-errors --root=$rootfs_dir $pkg" );
5 kx
5 kx #flock( $lock_fh, LOCK_UN ) or
5 kx # _kxLab::error( "$0: Cannot unlock $lock_fname file: $!" );
5 kx #close( $lock_fh );
5 kx #
5 kx # UN LOCK procedure.
5 kx #####################
5 kx }