Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/local/bin/ruby
- # Written by Dean Strelau 2006.10.31
- # This script creates a new svn repository
- # and optionally sets up some useful attributes of it.
- USAGE = "usage: #{$0} [options] name\n"
- HELP = <<HELP_TEXT
- #{USAGE}
- Available options are:
- -i <path> - Automatically import a folder's contents into the repo upon creation
- -u <user> - `chown` the repository to given user
- -g <group> - `chown` the repository to given group
- -m <mode> - `chmod` the repository to a given string (default 770)
- HELP_TEXT
- # If we want help, print & exit
- if ARGV.first == 'help' then
- print HELP
- exit 1
- end
- # Process options
- while a = ARGV.shift
- case a
- when '-i': import=ARGV.shift.to_s.chomp
- when '-u': user=ARGV.shift.to_s.chomp
- when '-g': group=ARGV.shift.to_s.chomp
- when '-m': mode=ARGV.shift.to_s.chomp
- when /-(.*)/
- print "illegal option -- #{$1}\n" <<
- "use `#{$0} help` for help "
- exit 1
- else repo = a.to_s.chomp
- end
- end
- # Need a name to do something
- unless repo
- print "must specify repository name\n"<< USAGE
- exit 1
- end
- absolute = ( repo =~ /^\//)
- cmds = Array.new
- cmds << "mkdir #{repo}"
- cmds << "svnadmin create #{repo}"
- if import # needs to be run as single command so the `cd` works
- pwd = `pwd`.chomp
- import_cmd = "cd #{import};"
- path = absolute ? repo : "#{pwd}/#{repo}"
- import_cmd << "svn import . file://#{path} -m \"Initial repository layout\""
- cmds << import_cmd
- end
- mode ||= '770'
- cmds << "chmod -R #{mode} #{repo}"
- ug = (user || '') + ':' + (group || '')
- cmds << "chown -R #{ug} #{repo}" unless ug == ':'
- cmds.each do |c|
- puts "Executing: #{c}"
- unless system(c) then # if system(c) returns false
- puts $?
- exit 1
- end
- end
- print "Success!\n"
Add Comment
Please, Sign In to add comment