blob: ab0dcc94f914bc1c355f9c5b17bbf57586827945 (
plain)
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
|
#!/usr/bin/env ruby
RST="[0m"
RED="[31m"
GRN="[32m"
YLW="[33m"
BLU="[34m"
def usage
$stderr.puts <<EOT
Usage:
dehat ARCHIVE [OPTIONS]
Dehat will attempt to astound you by pulling a filetree (or rabbit)
from an archive (or hat) in a sensibleish manner.
EOT
exit 1
end
archive = ARGV.shift
usage if archive.nil?
usage unless File.exist?(archive)
zip = File.extname(archive) == '.zip'
if zip
if `unzip -t #{archive}`.lines[1].split[1][-1] == ?/
$stderr.puts "Found a #{GRN}good#{RST} #{YLW}zip#{RST}"
`unzip #{archive} #{ARGV.join(?\s)}`
else
$stderr.puts "Found a #{RED}bad#{RST} #{YLW}zip#{RST}"
dirname = File.basename(archive, File.extname(archive))
if Dir.exist?(dirname)
exit 1
else
Dir.mkdir(dirname)
`unzip -d #{dirname} #{archive} #{ARGV.join(?\s)}`
end
end
else
if `tar -t -a -f #{archive}`.lines[0].strip[-1] == ?/
$stderr.puts "Found a #{GRN}good#{RST} #{BLU}tape archive#{RST}"
`tar -x -a -f #{archive} #{ARGV.join(?\s)}`
else
$stderr.puts "Found a #{RED}bad#{RST} #{BLU}tape archive#{RST}"
dirname = File.basename(archive, File.extname(archive))
if Dir.exist?(dirname)
exit 1
else
Dir.mkdir(dirname)
`tar -x -a -C #{dirname} -f #{archive} #{ARGV.join(?\s)}`
end
end
end
|