-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompressor.pl
executable file
·78 lines (61 loc) · 1.7 KB
/
decompressor.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
#!/usr/bin/perl -w
use utf8;
use v5.28;
use strict;
use Pod::Usage;
use SVN::Notify;
use Term::ANSIColor;
$| = 1;
binmode STDOUT, ":utf8";
my $file = $ARGV[0];
my ($rst, $rd) = (color('reset'), color('red'));
unless (defined $file && -e $file && -r $file && !-z $file){
pod2usage(1);
}
my %ucomp = (
"7z" => "7z x", zip => "unzip",
dmg => "7z x", jar => "unzip",
z => "gzip -d", war => "unzip",
Z => "gzip -d", apk => "unzip",
xz => "tar xfJ", deb => "dpkg -x",
rz => "rzip -d", lz => "lzip -d",
rar => "unrar x", pkg => "xar -xvf",
tar => "tar xvf", xar => "xar -xvf",
gz => "tar xvzf", tgz => "tar xvzf",
bz2 => "tar xvjf", arj => "arj e -r -y"
);
sub check_util {
unless (SVN::Notify->find_exe($_[0])) {
say($rd."[!] $_[0] is not installed...".$rst);
exit 1;
}
}
sub decompress {
if ($file =~ m/.*[.]([\w]+)$/i){
my @util = split /\s+/, "$ucomp{$1}";
if ($^O eq "darwin" && $util[0] eq "arj") {
&check_util("unarj");
} else {
&check_util($util[0]);
}
if ($1 eq "deb") { `$ucomp{$1} $file $ENV{'PWD'}`; }
elsif ($1 eq "arj") { $^O eq "darwin" ? `unarj e $file` : `$ucomp{$1} $file`; }
elsif ($1 eq "apk") { my @dir = split /\.apk$/, $file; `$ucomp{$1} $file -d $dir[0]`; }
else { `$ucomp{$1} $file`; }
}
else {
say($rd."[!] Couldn't decompress the file...".$rst);
}
}
&decompress($file);
__END__
=head1 NAME
uc - A linux/macOS decompressing utility.
=head1 SYNOPSIS
uc [file]
=head1 DESCRIPTION
A small decompressing utility, for linux and macOS operating systems, able
to decompress a wide range of archive formats with a single command, automatically.
=head1 EXAMPLE
uc test.bz2
=cut