Skip to content

Instantly share code, notes, and snippets.

@RichGuk
Forked from namelessjon/gist:342496
Created March 24, 2010 17:05
Show Gist options
  • Save RichGuk/342500 to your computer and use it in GitHub Desktop.
Save RichGuk/342500 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# cpioxz.rb
# Jonathan D. Stott <jonathan.stott@gmail.com>
if ARGV.empty?
warn "Usage: #{$0} directory [directories+]"
exit 1
end
ARGV.each do |dir|
next unless File.directory?(dir)
directory = dir.sub(/\/$/,'')
xz = "#{directory}.cpio.xz"
system("find #{directory} -type f -print0 | xargs -0 sha1sum >#{directory}.sha1")
system("find #{directory} #{directory}.sha1 -type f -print0 | cpio --create --quiet --null --format=crc | xz --best -Csha256 >#{xz}") || abort("Failed to write cpio")
system("xzcat #{xz} | cpio --quiet --extract --only-verify-crc") || abort("failed to verify crc")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment