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 File::Temp;
5 kx use Fcntl ':flock';
5 kx use _kxLab;
5 kx
5 kx my $distro = _kxLab::distro_name();
5 kx
5 kx # Global variables
5 kx my $header_printed = 0;
5 kx
5 kx my $rootfs_dest_dir;
5 kx my ($toolchain, $hardware, $flavour);
5 kx my $target_build_dir;
5 kx
5 kx my $cleanup = $ENV{DO_CREATE_DIST_FILES} ? 0 : 1;
5 kx my ($tempfd, $tempname);
5 kx
5 kx sub usage
5 kx {
5 kx print <<EOF;
5 kx
5 kx Usage: update_pkgs [options] package[ package]
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
5 kx # cleanpath( path )
5 kx sub cleanpath
5 kx {
5 kx my $path = shift;
5 kx $path =~ s!/{2,}!/!g;
5 kx $path =~ s!^.*dist/!!;
5 kx return $path;
5 kx }
5 kx
5 kx # rootfs( rootfs_dest_dir, pkg )
5 kx sub rootfs
5 kx {
5 kx my $dest_dir = cleanpath( shift );
5 kx my $target = shift;
5 kx
5 kx my $group = dirname( $target ); # extract GROUP if present:
5 kx $group =~ s!$target_build_dir/!!;
5 kx
5 kx my $file = basename( $target, ".txz" );
5 kx print $tempfd "$dest_dir/var/log/$distro/packages/$group/$file\n";
5 kx }
5 kx
5 kx # update( updatepkg, rootfs_dest_dir, verbose, targets )
5 kx sub update
5 kx {
5 kx my $updatepkg = shift;
5 kx my $rootfs_dest_dir = shift;
5 kx my $verbose = shift;
5 kx my $targets = shift;
5 kx
5 kx foreach my $target ( @{$targets} )
5 kx {
5 kx my $pkg = basename( $target );
5 kx my $cdir = dirname( $target );
5 kx if( !$header_printed )
5 kx {
5 kx print "\n======= Update packages =======\n";
5 kx $header_printed = 1;
5 kx }
5 kx print "Update $target ...\n" if ( $verbose );
5 kx _kxLab::system( "mkdir -p $rootfs_dest_dir" );
35 kx _kxLab::system( "cd $cdir; $updatepkg --reinstall --ignore-chrefs-errors --root=$rootfs_dest_dir $pkg" );
5 kx rootfs( $rootfs_dest_dir, $target );
5 kx }
5 kx }
5 kx
5 kx my @targets;
5 kx my $verbose = $ENV{VERBOSE};
5 kx my $curdir = $ENV{CWD};
5 kx my $updatepkg = $ENV{UPDATE_PACKAGE};
5 kx my $fname = "";
5 kx my $dest_fname = "";
5 kx
5 kx foreach ( @ARGV )
5 kx {
5 kx if( /--destination=(\S*)/ )
5 kx {
5 kx $rootfs_dest_dir = $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 else
5 kx {
5 kx push @targets, $_;
5 kx }
5 kx }
5 kx
5 kx if( ! defined $rootfs_dest_dir or $rootfs_dest_dir 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.XXXXXX";
5 kx $dest_fname = "$curdir/" . $target_build_dir . "/.rootfs";
5 kx }
5 kx else
5 kx {
5 kx $fname = $target_build_dir . "/.rootfs.XXXXXX";
5 kx $dest_fname = $target_build_dir . "/.rootfs";
5 kx }
5 kx
5 kx ($tempfd, $tempname) = File::Temp::tempfile( $fname, UNLINK => $cleanup );
5 kx
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
5 kx update( $updatepkg, $rootfs_dest_dir, $verbose, \@targets );
5 kx
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
5 kx # reverse file line by line:
5 kx _kxLab::system( "tac $tempname >> $dest_fname" );
5 kx _kxLab::system( "rm -f $tempname" );