-
Notifications
You must be signed in to change notification settings - Fork 89
/
mkfiles.pl
executable file
·106 lines (83 loc) · 2.29 KB
/
mkfiles.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
#use Time::localtime;
use POSIX qw(strftime);
my $url="/trurl/";
sub getdl {
my ($dir)=@_; # where the download files are
opendir(DIR, $dir) || return "";
my @files = readdir(DIR);
closedir DIR;
return @files;
}
sub filetime {
my ($filename)=@_;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
return $mtime;
}
sub filesize {
my ($filename)=@_;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
return $size;
}
sub checksum {
my ($f) = @_;
my @o = `sha256sum $f 2>/dev/null`;
my $sh = $o[0];
$sh =~ s/([^ ]*).*/$1/;
chomp $sh;
return $sh;
}
my $dl = "dl";
my @files = getdl($dl);
for(@files) {
my $file = $_;
if($file =~ /^trurl-([0-9.-]+)\.(tar\.gz)$/) {
my ($version, $ext)=($1, $2);
$file{$version}=$file;
my $fsize = filesize("$dl/$file");
$size{$version}=sprintf("%.1f KB", $fsize/1024);
my $when = filetime("$dl/$file");
my $d = strftime "%Y-%m-%d", gmtime($when);
$date{$version}=$d;
$versions{$version}++;
if(-e "$dl/$file.asc") {
# a GPG signature
$gpg{$version}="$dl/$file.asc";
}
}
}
sub num {
my ($t)=@_;
return $t;
}
my %video = (
'0.15' => 'https://youtu.be/ETxhkW2SsfU',
'0.16' => 'https://youtu.be/X8auKKxgFpw',
);
my $gen=0;
for my $version (reverse sort { num($a) <=> num($b) } keys %versions) {
my $build = 1;
my $officialver = $version;
if($officialver =~ s/-(\d)\z//g) {
$build = $1;
}
my $link = $officialver;
print "#define TRURL_VER $officialver\n";
print "#define TRURL_VER_LINK trurl-$officialver\n\n";
printf("#define TRURL_FILENAME dl/%s\n", $file{$version});
printf("#define TRURL_SIZE %s\n", $size{$version});
printf("#define TRURL_DATE %s\n", $date{$version});
if($gpg{$version}) {
printf("#define TRURL_SIG %s\n", $gpg{$version});
}
my $sha = checksum("$dl/$file{$version}");
printf("#define TRURL_SHA256 %s\n", $sha);
if($video{$officialver}) {
printf("#define TRURL_VIDEO %s\n", $video{$officialver});
}
last;
}