summaryrefslogtreecommitdiff
path: root/dehat
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2020-12-16 20:15:28 +0000
committerNat Lasseter <user@4574.co.uk>2020-12-16 20:15:28 +0000
commit2ce7bb844b96216a797e97e9629624a79fea0584 (patch)
tree991b8c1bac78de8462a809181f7eef7041ea4ce0 /dehat
parent509096c4cee49710c9910668ac45d23e2ec825aa (diff)
Added dehatHEADmaster
Diffstat (limited to 'dehat')
-rwxr-xr-xdehat55
1 files changed, 55 insertions, 0 deletions
diff --git a/dehat b/dehat
new file mode 100755
index 0000000..ab0dcc9
--- /dev/null
+++ b/dehat
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+
+RST=""
+RED=""
+GRN=""
+YLW=""
+BLU=""
+
+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