-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloctree2data
executable file
·110 lines (76 loc) · 3.21 KB
/
loctree2data
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
#!/usr/bin/perl -w
use strict;
use warnings;
use Carp qw| cluck :DEFAULT |;
use Getopt::Long qw(:config gnu_getopt auto_version auto_help);
use Pod::Usage;
BEGIN { our $VERSION = "__VERSION__"; }
our $opt;
my $Lok = GetOptions( $opt = { debug => 0, datadir => '/usr/share/loctree2-data', 'data-version' => '1.0.2' }, 'debug!', 'datadir=s', 'data-version=s', 'keep-data-tar!', 'man!', 'quiet!' );
if( !$Lok ){ die("Invalid arguments, please check man page.\n"); }
my $dbg = $opt->{debug};
if( $opt->{man} ){ pod2usage(-verbose => 2); }
# Does version in $opt->{datadir}/dataversion.txt match package version?
my $pkg_data_ver = undef;
if( -f "$opt->{datadir}/dataversion.txt" )
{
open( my $fh, '<', "$opt->{datadir}/dataversion.txt" ) || confess("Failed to open '$opt->{datadir}/dataversion.txt': $!");
$pkg_data_ver = <$fh>; chomp($pkg_data_ver);
}
if( !$pkg_data_ver || $pkg_data_ver ne $opt->{'data-version'} )
{
my $data_tar = "loctree2-data-$opt->{'data-version'}.tar.gz";
my $data_url = "https://rostlab.org/public/free/$data_tar";
my @sudo = ();
eval {
# wget it from $data_url
{ my @cmd = ( "/usr/bin/wget", $opt->{quiet} ? ('--quiet') : (), '--continue', '-O', "/tmp/$data_tar", $data_url ); if($dbg){warn("@cmd");} system(@cmd) && confess("Failed to execute @cmd: ".($?>>8)); }
# create target directory
{
my @cmd = ( "/bin/mkdir", "-p", $opt->{datadir} );
if($dbg){warn("@cmd");}
if( system(@cmd) && $> != 0 )
{
@sudo = ('/usr/bin/sudo'); @cmd = ( @sudo, @cmd );
if($dbg){warn("@cmd");}
system(@cmd) && confess("Failed to execute @cmd: ".($?>>8));
}
if( !-w $opt->{datadir} && $> != 0 ){ @sudo = ('/usr/bin/sudo'); }
}
# untar
{ my @cmd = ( @sudo, "/bin/tar", "-xzf", "/tmp/$data_tar", $opt->{quiet} ? () : ('--verbose'), '--no-same-owner', '--no-same-permissions', "--strip-components=1", '-C', $opt->{datadir}, "--wildcards", 'loctree2-data-*/*.txt', '--exclude', 'Makefile*', 'loctree2-data-*/COPYING', 'loctree2-data-*/*_model' ); if($dbg){warn("@cmd");} system(@cmd) && confess("Failed to execute @cmd: ".($?>>8)); }
# remove
if( !$opt->{'keep-data-tar'} ){ system( @sudo, '/bin/rm', '-f', "/tmp/$data_tar" ); }
};
if($@)
{
warn("loctree2 package data is missing from $opt->{datadir} and automatic retrieval failed. Please download it from $data_url and untar it to $opt->{datadir}.\n");
warn("Since the download is restartable, you also can re-run this command '".join(' ', $0, @ARGV)."' to reattempt data download. The incomplete data file is in /tmp/$data_tar.\n");
exit(1);
}
}
exit(0);
=pod
=head1 NAME
loctree2data - tool to download data files needed by loctree2
=head1 SYNOPSIS
__pkgdatadir__/loctree2data [OPTIONS]
__pkgdatadir__/loctree2data --man
=head1 DESCRIPTION
loctree2data is a tool to download data files needed by loctree2(1).
=head1 OPTIONS
=over
=item --datadir
=item --data-version
=item --debug
=item --nodebug
=item --help
=item --keep-data-tar
=item --man
=item --quiet
=item --version
=back
=head1 AUTHOR
Laszlo Kajan <[email protected]>
=cut
# vim:et:ts=4: