Advertisement
rockdrilla

aufs-genpatch.rb

May 13th, 2016
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.37 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. if ARGV[0].to_s == ""
  4. then linux_base = "4.5"
  5. else linux_base = ARGV[0]
  6. end
  7.  
  8. if ARGV[1].to_s == ""
  9. then out_dir = File.dirname(File.realpath($0))
  10. else out_dir = ARGV[1]
  11. end
  12.  
  13. require "tempfile"
  14. require "fileutils"
  15.  
  16. GH_user           = "sfjro"
  17. GH_repo           = "aufs4-standalone"
  18. GH_branch         = "aufs#{linux_base}"
  19. GH_tarball        = "https://github.com/#{GH_user}/#{GH_repo}/archive/#{GH_branch}.tar.gz"
  20. GH_tarball_topdir = "#{GH_repo}-#{GH_branch}"
  21.  
  22. aufs_reldate_src = "include/uapi/linux/aufs_type.h"
  23. aufs_reldate_re  = /^[[:space:]]*#define[[:space:]]+AUFS_VERSION[[:space:]]+"(#{linux_base}-([^"]+))"[[:space:]]*$/
  24. aufs_reldate_raw = ""
  25. aufs_reldate     = ""
  26.  
  27. Dir.mktmpdir { |tmpdir_tarball|
  28.     Tempfile.create("aufs") { |tmpfile_tarball|
  29.         `wget -q -O #{tmpfile_tarball.path} #{GH_tarball}`
  30.         `tar -x -f #{tmpfile_tarball.path} -C #{tmpdir_tarball}`
  31.     }
  32.  
  33.     tarball_dir = File.join(tmpdir_tarball, GH_tarball_topdir)
  34.  
  35.     File.open(File.join(tarball_dir, aufs_reldate_src)) { |f|
  36.         f.grep(aufs_reldate_re) { |line|
  37.             aufs_reldate_raw = aufs_reldate_re.match(line)[1]
  38.             aufs_reldate     = aufs_reldate_re.match(line)[2]
  39.         }
  40.     }
  41.  
  42.     break if aufs_reldate == ""
  43.  
  44.     Dir.mktmpdir { |tmpdir_gitrepo|
  45.         Dir.chdir(tmpdir_gitrepo)
  46.         `git init`
  47.         `git commit --allow-empty -m "0"`
  48.  
  49.         tree_mirror = [ "Documentation/", "fs/", "include/uapi/linux/aufs_type.h" ]
  50.  
  51.         Dir.chdir(tarball_dir)
  52.         `tar -cf - #{tree_mirror.join(" ")} | tar -xf - -C #{tmpdir_gitrepo}`
  53.  
  54.         Dir.chdir(tmpdir_gitrepo)
  55.         `git add .`
  56.  
  57.         common_patch = File.join(tarball_dir, "aufs4-common.patch")
  58.  
  59.         File.open(common_patch, 'w') { |f|
  60.             f.puts("#{GH_branch} common files patch")
  61.             f.puts()
  62.         }
  63.         `git diff HEAD >> #{common_patch}`
  64.  
  65.         Dir.chdir(tarball_dir)
  66.     }
  67.  
  68.     file_renames = {
  69.         "aufs4-common.patch"     => "0-common.patch",
  70.         "aufs4-kbuild.patch"     => "1-kbuild.patch",
  71.         "aufs4-base.patch"       => "2-base.patch",
  72.         "aufs4-mmap.patch"       => "3-mmap.patch",
  73.         "aufs4-standalone.patch" => "4-standalone.patch",
  74.         "aufs4-loopback.patch"   => "5-loopback.patch",
  75.         "vfs-ino.patch"          => "6-vfs-ino.patch",
  76.         "tmpfs-idr.patch"        => "7-tmpfs-idr.patch",
  77.     }
  78.  
  79.     file_renames.each_key{ |old_name|
  80.         new_name = "#{linux_base}-#{aufs_reldate}-" + file_renames[old_name]
  81.         new_name = File.join(out_dir, new_name)
  82.  
  83.         FileUtils.mv(old_name, new_name)
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement