1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!/usr/bin/env ruby
require "ftools"
require "getoptlong"
$directory = false
$owner = -1
$group = -1
$mode = 0755
parser = GetoptLong.new
parser.set_options(["-c", GetoptLong::NO_ARGUMENT],
["-d", "--directory", GetoptLong::NO_ARGUMENT],
["-g", "--group", GetoptLong::REQUIRED_ARGUMENT],
["-m", "--mode", GetoptLong::REQUIRED_ARGUMENT],
["-o", "--owner", GetoptLong::REQUIRED_ARGUMENT])
begin
parser.each_option do |name, arg|
case name
when "-c"
# ignore
when "-d"
$directory = true
when "-g"
$group = arg.to_i
when "-m"
$mode = arg.oct
when "-o"
$owner = arg.to_i
end
end
rescue
exit(1)
end
unless $src = ARGV.shift
$stderr.printf("%s: no input file specified\n", $0)
exit(1)
end
if $directory
$dst = $src
File.makedirs($dst)
File.chmod($mode)
else
unless $dst = ARGV.shift
$stderr.printf("%s: no destination specified\n", $0)
exit(1)
end
if File.directory?($dst)
$dst = File.expand_path(File.basename($src), $dst)
end
File.install($src, $dst, $mode)
end
if $owner != -1 || $group != -1
File.chown($owner, $group, $dst)
end
|