-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_package
More file actions
executable file
·91 lines (74 loc) · 1.73 KB
/
Copy pathmake_package
File metadata and controls
executable file
·91 lines (74 loc) · 1.73 KB
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
#!/usr/bin/perl -w
use strict;
use JSON::PP;
use Archive::Tar;
use File::Find;
use Digest::SHA;
use Digest::MD5;
use Cwd 'abs_path';
my $info = read_JSON_file("control.json");
my $name = ${$info}{"Package"};
my $version = ${$info}{"Version"};
my $filename = "${name}_${version}.tar.gz";
my @files = ("control.json");
find({wanted => \&findstuff, no_chdir=> 1}, "files");
Archive::Tar->create_archive($filename,COMPRESS_GZIP, @files);
${$info}{"SHA1"} = shasum(1,$filename);
${$info}{"SHA256"} = shasum(256,$filename);
${$info}{"MD5sum"} = md5sum($filename);
my $json = JSON::PP->new;
$json->indent();
my $json_text = $json->utf8->encode($info,1);
print "$json_text";
sub shasum
{
my $arg = shift;
my $filename = shift;
my $fh;
unless (open $fh,$filename) {
print STDERR "$0: open $filename: $!";
exit(1);
}
my $sha1 = Digest::SHA->new($arg);
$sha1->addfile($fh);
my $digest = $sha1->hexdigest;
close $fh;
return $digest;
}
sub md5sum
{
my $filename = shift;
my $fh;
unless (open $fh,$filename) {
print STDERR "$0: open $filename: $!";
exit(1);
}
my $md5 = Digest::MD5->new();
$md5->addfile($fh);
my $digest = $md5->hexdigest;
close $fh;
return $digest;
}
sub findstuff
{
my $file = $File::Find::name;
my $d = Cwd::cwd();
my $dir = $File::Find::dir;
return unless -f "$file";
return if (-d "$file");
return if ($file =~ /.*flymake.*/);
return if ($file =~ /\~$/);
push @files,$file;
}
sub read_JSON_file
{
my $filename = shift;
my $json;
{
local $/; # Enable 'slurp' mode
open my $fh, "<", $filename or error_exit("Can't open \"$filename\": $!");
$json = <$fh>;
close $fh;
};
return decode_json($json);
}