Guest User

Untitled

a guest
Feb 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/opt/local/bin/ruby
  2. # Written by Dean Strelau 2006.10.31
  3. # This script creates a new svn repository
  4. # and optionally sets up some useful attributes of it.
  5.  
  6. USAGE = "usage: #{$0} [options] name\n"
  7. HELP = <<HELP_TEXT
  8. #{USAGE}
  9. Available options are:
  10. -i <path> - Automatically import a folder's contents into the repo upon creation
  11. -u <user> - `chown` the repository to given user
  12. -g <group> - `chown` the repository to given group
  13. -m <mode> - `chmod` the repository to a given string (default 770)
  14. HELP_TEXT
  15.  
  16.  
  17. # If we want help, print & exit
  18. if ARGV.first == 'help' then
  19. print HELP
  20. exit 1
  21. end
  22.  
  23. # Process options
  24. while a = ARGV.shift
  25. case a
  26. when '-i': import=ARGV.shift.to_s.chomp
  27. when '-u': user=ARGV.shift.to_s.chomp
  28. when '-g': group=ARGV.shift.to_s.chomp
  29. when '-m': mode=ARGV.shift.to_s.chomp
  30. when /-(.*)/
  31. print "illegal option -- #{$1}\n" <<
  32. "use `#{$0} help` for help "
  33. exit 1
  34. else repo = a.to_s.chomp
  35. end
  36. end
  37.  
  38. # Need a name to do something
  39. unless repo
  40. print "must specify repository name\n"<< USAGE
  41. exit 1
  42. end
  43.  
  44. absolute = ( repo =~ /^\//)
  45. cmds = Array.new
  46. cmds << "mkdir #{repo}"
  47. cmds << "svnadmin create #{repo}"
  48. if import # needs to be run as single command so the `cd` works
  49. pwd = `pwd`.chomp
  50. import_cmd = "cd #{import};"
  51. path = absolute ? repo : "#{pwd}/#{repo}"
  52. import_cmd << "svn import . file://#{path} -m \"Initial repository layout\""
  53. cmds << import_cmd
  54. end
  55. mode ||= '770'
  56. cmds << "chmod -R #{mode} #{repo}"
  57. ug = (user || '') + ':' + (group || '')
  58. cmds << "chown -R #{ug} #{repo}" unless ug == ':'
  59.  
  60. cmds.each do |c|
  61. puts "Executing: #{c}"
  62. unless system(c) then # if system(c) returns false
  63. puts $?
  64. exit 1
  65. end
  66. end
  67.  
  68. print "Success!\n"
Add Comment
Please, Sign In to add comment