Skip to content

Instantly share code, notes, and snippets.

@hetima
Created December 28, 2014 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hetima/c145eabb6c55a3c8c8d9 to your computer and use it in GitHub Desktop.
Save hetima/c145eabb6c55a3c8c8d9 to your computer and use it in GitHub Desktop.
pkg を解凍するスクリプト。新旧対応、ついでに rar も
#!/usr/bin/env ruby
require "tmpdir"
def proccess_rar(file)
param=["x", file]
system(["unrar", "unrar"], *param)
end
def proccess_flat_pkg(file)
tmpDir="./tmp"
Dir.mktmpdir("pkg_extract_", "./"){|dir|
tmpDir=dir
}
param=["--expand", file, tmpDir]
system(["pkgutil", "pkgutil"], *param)
end
def proccess_old_pkg(file)
param=["-rzf", file+"/Contents/Archive.pax.gz"]
system(["pax", "pax"], *param)
end
def proccess_new_pkg(file)
bomPath=file+"/Bom"
payloadPath=file+"/Payload"
param=["-x", "--bom", bomPath, payloadPath, "./"]
system(["ditto", "ditto"], *param)
end
def proccess_pkg_pkg(file)
if FileTest::exist?(file+"/Contents/Archive.pax.gz") then
proccess_old_pkg(file)
elsif FileTest::exist?(file+"/Bom") then
proccess_new_pkg(file)
end
end
def proccess_pkg(file)
if FileTest::directory?(file) then
proccess_pkg_pkg(file)
else
proccess_flat_pkg(file)
end
end
file=ARGV[0]
if file.end_with?(".pkg") then
proccess_pkg(file)
elsif file.end_with?(".rar") then
proccess_rar(file)
else
p "wrong param"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment