Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active June 21, 2016 03:53
Show Gist options
  • Save mamemomonga/e49ce1a37e0ec5d2398aadbd340c7bbd to your computer and use it in GitHub Desktop.
Save mamemomonga/e49ce1a37e0ec5d2398aadbd340c7bbd to your computer and use it in GitHub Desktop.
bzip2で圧縮したディスクイメージを作成する
#!/usr/bin/env ruby
#
# bzip2で圧縮したディスクイメージを作成する
# 追記はできません
#
# dmg-archive.rb -o dmgファイル名 -s ソースディレクトリ [-e]
# -e をつけると暗号化が有功になります
#
trap('INT'){ exit 1 }
if Signal.list.include? 'PIPE'
trap('PIPE', 'EXIT')
end
require 'optparse'
def usage()
executable_name = File.split($0)[1]
print " #{executable_name} -s sourcedir -o output [-e]\n"
end
dmg_file=""
src_dir=""
encryption=false
OptionParser.new do |opts|
opts.on("-o","--output [NAME.EXTENSION]", "output") do |filename|
if ! filename.nil?
dmg_file=filename
end
end
opts.on("-s","--srcdir [NAME.EXTENSION]", "srcdir") do |dirname|
if ! dirname.nil?
src_dir=dirname
end
end
opts.on("-e","--encryption","encryption") do
encryption=true
end
opts.on("-h","--help","usage") do
usage()
puts opts
exit
end
end.parse!
if dmg_file.empty? or src_dir.empty?
usage()
exit
end
cmd=["hdiutil","create","-verbose","-format","UDBZ","-fs","JHFS+X"]
if encryption
cmd.push("-encryption","AES-128","-stdinpass")
end
cmd.push("-srcfolder",src_dir,dmg_file)
#system("echo","[EXEC]",*cmd)
exec(*cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment