-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_package_to_repository.pl
executable file
·81 lines (64 loc) · 2.43 KB
/
add_package_to_repository.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use File::Basename;
use File::Copy;
use File::Path qw(make_path);
chdir $FindBin::Bin;
my $configFileName = 'config.pl';
my $config = do $configFileName or die "config file $configFileName not found.";
main();
sub main {
die 'Please specify package name.' if ($#ARGV < 0);
my $packageName = $ARGV[0];
$packageName =~ s|^$config->{pkgbuildDir}/||;
$packageName =~ s|/$||;
chdir "$config->{pkgbuildDir}/$packageName" or die 'No such package exists.';
print "Building package of $packageName...\n";
print "\n";
system "makepkg -s --holdver";
die if ($? != 0);
print "\n";
chdir '../..';
my @packageFiles = glob "$config->{pkgbuildDir}/$packageName/$packageName-*.pkg.tar.xz";
die 'No built package file found.' if ($#packageFiles < 0);
foreach my $packageFile (@packageFiles) {
print "Adding $packageFile to repository...\n";
print "\n";
addPackageToRepository($packageFile);
}
}
sub addPackageToRepository {
my $packagePath = shift;
my $packageFileName = basename($packagePath);
my ($architecture) = $packageFileName =~ /([^-]+).pkg.tar.xz$/;
my @repositoryPaths;
if ($architecture eq 'any') {
push(@repositoryPaths, "$config->{repoDir}/i686");
push(@repositoryPaths, "$config->{repoDir}/x86_64");
} else {
push(@repositoryPaths, "$config->{repoDir}/$architecture");
}
foreach my $repositoryPath (@repositoryPaths) {
unless (-d $repositoryPath) {
make_path $repositoryPath;
}
copy $packagePath, $repositoryPath;
my $repositoryDatabasePath = "$repositoryPath/$config->{repoName}.db.tar.gz";
my $placedPackagePath = "$repositoryPath/$packageFileName";
system "repo-add $repositoryDatabasePath $placedPackagePath";
# repo-add generates REPO_NAME.db.tar.gz and make symlink REPO_NAME.db which refers the former.
# pacman refers REPO_NAME.db via HTTP,
# but web interface of Github returns just path of symlink.
# So we need to replace symlink with copy.
replaceSymlinkWithCopy("$repositoryPath/$config->{repoName}.db")
}
}
sub replaceSymlinkWithCopy {
my $symlinkPath = shift;
return unless (-l $symlinkPath);
my $symlinkDestinationPath = dirname($symlinkPath) . '/' . readlink($symlinkPath);
unlink $symlinkPath;
copy $symlinkDestinationPath, $symlinkPath;
}