Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.