-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_pkgs
executable file
·164 lines (139 loc) · 3.5 KB
/
install_pkgs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl
use FindBin;
use lib $FindBin::Bin;
use strict;
use warnings FATAL => 'all';
use File::Basename;
use File::Temp;
use Fcntl ':flock';
use _kxLab;
my $distro = _kxLab::distro_name();
# Global variables
my $header_printed = 0;
my $cleanup = $ENV{DO_CREATE_DIST_FILES} ? 0 : 1;
my ($tempfd, $tempname);
sub usage
{
print <<EOF;
Usage: install_pkgs [options] package[ package]
Options:
--destination=ROOTFS - where ROOTFS is a destination directory.
--toolchain=TOOLCHAIN - where TOOLCHAIN ia a toolchain name;
--hardware=HARDWARE - where HARDWARE ia a HARDWARE name;
--flavour=FLAVOUR - where FLAVOUR ia a FLAVOUR name.
EOF
exit;
}
# cleanpath( path )
sub cleanpath
{
my $path = shift;
$path =~ s!/{2,}!/!g;
$path =~ s!^.*dist/!!;
return $path;
}
# rootfs( rootfs_dest_dir, pkg )
sub rootfs
{
my $dest_dir = cleanpath( shift );
my $file = basename( shift, ".txz" );
print $tempfd "$dest_dir/var/log/$distro/packages/$file\n";
}
# install( installpkg, rootfs_dest_dir, verbose, targets )
sub install
{
my $installpkg = shift;
my $rootfs_dest_dir = shift;
my $verbose = shift;
my $targets = shift;
foreach my $target ( @{$targets} )
{
my $pkg = basename( $target );
my $cdir = dirname( $target );
if( !$header_printed )
{
print "\n======= Installing packages =======\n" if ( $verbose );
$header_printed = 1;
}
print "Installing $target ...\n" if ( $verbose );
_kxLab::system( "cd $cdir; $installpkg --root $rootfs_dest_dir $pkg" );
rootfs( $rootfs_dest_dir, $target );
}
}
my $rootfs_dest_dir;
my ($toolchain, $hardware, $flavour);
my $target_build_dir;
my @targets;
my $verbose = $ENV{VERBOSE};
my $curdir = $ENV{CWD};
my $installpkg = $ENV{INSTALL_PACKAGE};
my $fname = "";
my $dest_fname = "";
foreach ( @ARGV )
{
if( /--destination=(\S*)/ )
{
$rootfs_dest_dir = $1;
}
elsif( /--toolchain=(\S*)/ )
{
$toolchain = $1;
}
elsif( /--hardware=(\S*)/ )
{
$hardware = $1;
}
elsif( /--flavour=(\S*)/ )
{
$flavour = $1;
}
elsif( /--help/ )
{
usage;
}
else
{
push @targets, $_;
}
}
if( ! defined $rootfs_dest_dir or $rootfs_dest_dir eq "" ) { usage; }
if( ! defined $toolchain or $toolchain eq "" ) { usage; }
if( ! defined $hardware or $hardware eq "" ) { usage; }
if( ! defined $flavour or $flavour eq "" )
{
$flavour = "";
$target_build_dir = "." . $toolchain . "/" . $hardware;
}
else
{
$target_build_dir = "." . $toolchain . "/" . $hardware . "/" . $flavour;
}
if ( $curdir )
{
$fname = "$curdir/" . $target_build_dir . "/.rootfs.XXXXXX";
$dest_fname = "$curdir/" . $target_build_dir . "/.rootfs";
}
else
{
$fname = $target_build_dir . "/.rootfs.XXXXXX";
$dest_fname = $target_build_dir . "/.rootfs";
}
($tempfd, $tempname) = File::Temp::tempfile( $fname, UNLINK => $cleanup );
#####################
# LOCK procedure:
#
my $lock_fname = _kxLab::build_system_tmpdir() . "/." . $hardware . ".pkgtool-lock";
open( my $lock_fh, '+>', $lock_fname ) or
_kxLab::error( "$0: Could not open $lock_fname file: $!" );
flock( $lock_fh, LOCK_EX ) or
_kxLab::error( "$0: Cannot lock $lock_fname file: $!" );
install( $installpkg, $rootfs_dest_dir, $verbose, \@targets );
flock( $lock_fh, LOCK_UN ) or
_kxLab::error( "$0: Cannot unlock $lock_fname file: $!" );
close( $lock_fh );
#
# UN LOCK procedure.
#####################
# reverse file line by line:
_kxLab::system( "tac $tempname >> $dest_fname" );
_kxLab::system( "rm -f $tempname" );