Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: un.rb
#
[0] Fix | Delete
# = un.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Copyright (c) 2003 WATANABE Hirofumi <eban@ruby-lang.org>
[3] Fix | Delete
#
[4] Fix | Delete
# This program is free software.
[5] Fix | Delete
# You can distribute/modify this program under the same terms of Ruby.
[6] Fix | Delete
#
[7] Fix | Delete
# == Utilities to replace common UNIX commands in Makefiles etc
[8] Fix | Delete
#
[9] Fix | Delete
# == SYNOPSIS
[10] Fix | Delete
#
[11] Fix | Delete
# ruby -run -e cp -- [OPTION] SOURCE DEST
[12] Fix | Delete
# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
[13] Fix | Delete
# ruby -run -e mv -- [OPTION] SOURCE DEST
[14] Fix | Delete
# ruby -run -e rm -- [OPTION] FILE
[15] Fix | Delete
# ruby -run -e mkdir -- [OPTION] DIRS
[16] Fix | Delete
# ruby -run -e rmdir -- [OPTION] DIRS
[17] Fix | Delete
# ruby -run -e install -- [OPTION] SOURCE DEST
[18] Fix | Delete
# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
[19] Fix | Delete
# ruby -run -e touch -- [OPTION] FILE
[20] Fix | Delete
# ruby -run -e wait_writable -- [OPTION] FILE
[21] Fix | Delete
# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
[22] Fix | Delete
# ruby -run -e httpd -- [OPTION] DocumentRoot
[23] Fix | Delete
# ruby -run -e help [COMMAND]
[24] Fix | Delete
[25] Fix | Delete
require "fileutils"
[26] Fix | Delete
require "optparse"
[27] Fix | Delete
[28] Fix | Delete
module FileUtils
[29] Fix | Delete
# @fileutils_label = ""
[30] Fix | Delete
@fileutils_output = $stdout
[31] Fix | Delete
end
[32] Fix | Delete
[33] Fix | Delete
# :nodoc:
[34] Fix | Delete
def setup(options = "", *long_options)
[35] Fix | Delete
caller = caller_locations(1, 1)[0].label
[36] Fix | Delete
opt_hash = {}
[37] Fix | Delete
argv = []
[38] Fix | Delete
OptionParser.new do |o|
[39] Fix | Delete
options.scan(/.:?/) do |s|
[40] Fix | Delete
opt_name = s.delete(":").intern
[41] Fix | Delete
o.on("-" + s.tr(":", " ")) do |val|
[42] Fix | Delete
opt_hash[opt_name] = val
[43] Fix | Delete
end
[44] Fix | Delete
end
[45] Fix | Delete
long_options.each do |s|
[46] Fix | Delete
opt_name, arg_name = s.split(/(?=[\s=])/, 2)
[47] Fix | Delete
opt_name.sub!(/\A--/, '')
[48] Fix | Delete
s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}"
[49] Fix | Delete
puts "#{opt_name}=>#{s}" if $DEBUG
[50] Fix | Delete
opt_name = opt_name.intern
[51] Fix | Delete
o.on(s) do |val|
[52] Fix | Delete
opt_hash[opt_name] = val
[53] Fix | Delete
end
[54] Fix | Delete
end
[55] Fix | Delete
o.on("-v") do opt_hash[:verbose] = true end
[56] Fix | Delete
o.on("--help") do
[57] Fix | Delete
UN.help([caller])
[58] Fix | Delete
exit
[59] Fix | Delete
end
[60] Fix | Delete
o.order!(ARGV) do |x|
[61] Fix | Delete
if /[*?\[{]/ =~ x
[62] Fix | Delete
argv.concat(Dir[x])
[63] Fix | Delete
else
[64] Fix | Delete
argv << x
[65] Fix | Delete
end
[66] Fix | Delete
end
[67] Fix | Delete
end
[68] Fix | Delete
yield argv, opt_hash
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
##
[72] Fix | Delete
# Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
[73] Fix | Delete
#
[74] Fix | Delete
# ruby -run -e cp -- [OPTION] SOURCE DEST
[75] Fix | Delete
#
[76] Fix | Delete
# -p preserve file attributes if possible
[77] Fix | Delete
# -r copy recursively
[78] Fix | Delete
# -v verbose
[79] Fix | Delete
#
[80] Fix | Delete
[81] Fix | Delete
def cp
[82] Fix | Delete
setup("pr") do |argv, options|
[83] Fix | Delete
cmd = "cp"
[84] Fix | Delete
cmd += "_r" if options.delete :r
[85] Fix | Delete
options[:preserve] = true if options.delete :p
[86] Fix | Delete
dest = argv.pop
[87] Fix | Delete
argv = argv[0] if argv.size == 1
[88] Fix | Delete
FileUtils.send cmd, argv, dest, options
[89] Fix | Delete
end
[90] Fix | Delete
end
[91] Fix | Delete
[92] Fix | Delete
##
[93] Fix | Delete
# Create a link to the specified TARGET with LINK_NAME.
[94] Fix | Delete
#
[95] Fix | Delete
# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
[96] Fix | Delete
#
[97] Fix | Delete
# -s make symbolic links instead of hard links
[98] Fix | Delete
# -f remove existing destination files
[99] Fix | Delete
# -v verbose
[100] Fix | Delete
#
[101] Fix | Delete
[102] Fix | Delete
def ln
[103] Fix | Delete
setup("sf") do |argv, options|
[104] Fix | Delete
cmd = "ln"
[105] Fix | Delete
cmd += "_s" if options.delete :s
[106] Fix | Delete
options[:force] = true if options.delete :f
[107] Fix | Delete
dest = argv.pop
[108] Fix | Delete
argv = argv[0] if argv.size == 1
[109] Fix | Delete
FileUtils.send cmd, argv, dest, options
[110] Fix | Delete
end
[111] Fix | Delete
end
[112] Fix | Delete
[113] Fix | Delete
##
[114] Fix | Delete
# Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
[115] Fix | Delete
#
[116] Fix | Delete
# ruby -run -e mv -- [OPTION] SOURCE DEST
[117] Fix | Delete
#
[118] Fix | Delete
# -v verbose
[119] Fix | Delete
#
[120] Fix | Delete
[121] Fix | Delete
def mv
[122] Fix | Delete
setup do |argv, options|
[123] Fix | Delete
dest = argv.pop
[124] Fix | Delete
argv = argv[0] if argv.size == 1
[125] Fix | Delete
FileUtils.mv argv, dest, options
[126] Fix | Delete
end
[127] Fix | Delete
end
[128] Fix | Delete
[129] Fix | Delete
##
[130] Fix | Delete
# Remove the FILE
[131] Fix | Delete
#
[132] Fix | Delete
# ruby -run -e rm -- [OPTION] FILE
[133] Fix | Delete
#
[134] Fix | Delete
# -f ignore nonexistent files
[135] Fix | Delete
# -r remove the contents of directories recursively
[136] Fix | Delete
# -v verbose
[137] Fix | Delete
#
[138] Fix | Delete
[139] Fix | Delete
def rm
[140] Fix | Delete
setup("fr") do |argv, options|
[141] Fix | Delete
cmd = "rm"
[142] Fix | Delete
cmd += "_r" if options.delete :r
[143] Fix | Delete
options[:force] = true if options.delete :f
[144] Fix | Delete
FileUtils.send cmd, argv, options
[145] Fix | Delete
end
[146] Fix | Delete
end
[147] Fix | Delete
[148] Fix | Delete
##
[149] Fix | Delete
# Create the DIR, if they do not already exist.
[150] Fix | Delete
#
[151] Fix | Delete
# ruby -run -e mkdir -- [OPTION] DIR
[152] Fix | Delete
#
[153] Fix | Delete
# -p no error if existing, make parent directories as needed
[154] Fix | Delete
# -v verbose
[155] Fix | Delete
#
[156] Fix | Delete
[157] Fix | Delete
def mkdir
[158] Fix | Delete
setup("p") do |argv, options|
[159] Fix | Delete
cmd = "mkdir"
[160] Fix | Delete
cmd += "_p" if options.delete :p
[161] Fix | Delete
FileUtils.send cmd, argv, options
[162] Fix | Delete
end
[163] Fix | Delete
end
[164] Fix | Delete
[165] Fix | Delete
##
[166] Fix | Delete
# Remove the DIR.
[167] Fix | Delete
#
[168] Fix | Delete
# ruby -run -e rmdir -- [OPTION] DIR
[169] Fix | Delete
#
[170] Fix | Delete
# -p remove DIRECTORY and its ancestors.
[171] Fix | Delete
# -v verbose
[172] Fix | Delete
#
[173] Fix | Delete
[174] Fix | Delete
def rmdir
[175] Fix | Delete
setup("p") do |argv, options|
[176] Fix | Delete
options[:parents] = true if options.delete :p
[177] Fix | Delete
FileUtils.rmdir argv, options
[178] Fix | Delete
end
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
##
[182] Fix | Delete
# Copy SOURCE to DEST.
[183] Fix | Delete
#
[184] Fix | Delete
# ruby -run -e install -- [OPTION] SOURCE DEST
[185] Fix | Delete
#
[186] Fix | Delete
# -p apply access/modification times of SOURCE files to
[187] Fix | Delete
# corresponding destination files
[188] Fix | Delete
# -m set permission mode (as in chmod), instead of 0755
[189] Fix | Delete
# -v verbose
[190] Fix | Delete
#
[191] Fix | Delete
[192] Fix | Delete
def install
[193] Fix | Delete
setup("pm:") do |argv, options|
[194] Fix | Delete
options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
[195] Fix | Delete
options[:preserve] = true if options.delete :p
[196] Fix | Delete
dest = argv.pop
[197] Fix | Delete
argv = argv[0] if argv.size == 1
[198] Fix | Delete
FileUtils.install argv, dest, options
[199] Fix | Delete
end
[200] Fix | Delete
end
[201] Fix | Delete
[202] Fix | Delete
##
[203] Fix | Delete
# Change the mode of each FILE to OCTAL-MODE.
[204] Fix | Delete
#
[205] Fix | Delete
# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
[206] Fix | Delete
#
[207] Fix | Delete
# -v verbose
[208] Fix | Delete
#
[209] Fix | Delete
[210] Fix | Delete
def chmod
[211] Fix | Delete
setup do |argv, options|
[212] Fix | Delete
mode = argv.shift.oct
[213] Fix | Delete
FileUtils.chmod mode, argv, options
[214] Fix | Delete
end
[215] Fix | Delete
end
[216] Fix | Delete
[217] Fix | Delete
##
[218] Fix | Delete
# Update the access and modification times of each FILE to the current time.
[219] Fix | Delete
#
[220] Fix | Delete
# ruby -run -e touch -- [OPTION] FILE
[221] Fix | Delete
#
[222] Fix | Delete
# -v verbose
[223] Fix | Delete
#
[224] Fix | Delete
[225] Fix | Delete
def touch
[226] Fix | Delete
setup do |argv, options|
[227] Fix | Delete
FileUtils.touch argv, options
[228] Fix | Delete
end
[229] Fix | Delete
end
[230] Fix | Delete
[231] Fix | Delete
##
[232] Fix | Delete
# Wait until the file becomes writable.
[233] Fix | Delete
#
[234] Fix | Delete
# ruby -run -e wait_writable -- [OPTION] FILE
[235] Fix | Delete
#
[236] Fix | Delete
# -n RETRY count to retry
[237] Fix | Delete
# -w SEC each wait time in seconds
[238] Fix | Delete
# -v verbose
[239] Fix | Delete
#
[240] Fix | Delete
[241] Fix | Delete
def wait_writable
[242] Fix | Delete
setup("n:w:v") do |argv, options|
[243] Fix | Delete
verbose = options[:verbose]
[244] Fix | Delete
n = options[:n] and n = Integer(n)
[245] Fix | Delete
wait = (wait = options[:w]) ? Float(wait) : 0.2
[246] Fix | Delete
argv.each do |file|
[247] Fix | Delete
begin
[248] Fix | Delete
open(file, "r+b")
[249] Fix | Delete
rescue Errno::ENOENT
[250] Fix | Delete
break
[251] Fix | Delete
rescue Errno::EACCES => e
[252] Fix | Delete
raise if n and (n -= 1) <= 0
[253] Fix | Delete
if verbose
[254] Fix | Delete
puts e
[255] Fix | Delete
STDOUT.flush
[256] Fix | Delete
end
[257] Fix | Delete
sleep wait
[258] Fix | Delete
retry
[259] Fix | Delete
end
[260] Fix | Delete
end
[261] Fix | Delete
end
[262] Fix | Delete
end
[263] Fix | Delete
[264] Fix | Delete
##
[265] Fix | Delete
# Create makefile using mkmf.
[266] Fix | Delete
#
[267] Fix | Delete
# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
[268] Fix | Delete
#
[269] Fix | Delete
# -d ARGS run dir_config
[270] Fix | Delete
# -h ARGS run have_header
[271] Fix | Delete
# -l ARGS run have_library
[272] Fix | Delete
# -f ARGS run have_func
[273] Fix | Delete
# -v ARGS run have_var
[274] Fix | Delete
# -t ARGS run have_type
[275] Fix | Delete
# -m ARGS run have_macro
[276] Fix | Delete
# -c ARGS run have_const
[277] Fix | Delete
# --vendor install to vendor_ruby
[278] Fix | Delete
#
[279] Fix | Delete
[280] Fix | Delete
def mkmf
[281] Fix | Delete
setup("d:h:l:f:v:t:m:c:", "vendor") do |argv, options|
[282] Fix | Delete
require 'mkmf'
[283] Fix | Delete
opt = options[:d] and opt.split(/:/).each {|n| dir_config(*n.split(/,/))}
[284] Fix | Delete
opt = options[:h] and opt.split(/:/).each {|n| have_header(*n.split(/,/))}
[285] Fix | Delete
opt = options[:l] and opt.split(/:/).each {|n| have_library(*n.split(/,/))}
[286] Fix | Delete
opt = options[:f] and opt.split(/:/).each {|n| have_func(*n.split(/,/))}
[287] Fix | Delete
opt = options[:v] and opt.split(/:/).each {|n| have_var(*n.split(/,/))}
[288] Fix | Delete
opt = options[:t] and opt.split(/:/).each {|n| have_type(*n.split(/,/))}
[289] Fix | Delete
opt = options[:m] and opt.split(/:/).each {|n| have_macro(*n.split(/,/))}
[290] Fix | Delete
opt = options[:c] and opt.split(/:/).each {|n| have_const(*n.split(/,/))}
[291] Fix | Delete
$configure_args["--vendor"] = true if options[:vendor]
[292] Fix | Delete
create_makefile(*argv)
[293] Fix | Delete
end
[294] Fix | Delete
end
[295] Fix | Delete
[296] Fix | Delete
##
[297] Fix | Delete
# Run WEBrick HTTP server.
[298] Fix | Delete
#
[299] Fix | Delete
# ruby -run -e httpd -- [OPTION] DocumentRoot
[300] Fix | Delete
#
[301] Fix | Delete
# --bind-address=ADDR address to bind
[302] Fix | Delete
# --port=NUM listening port number
[303] Fix | Delete
# --max-clients=MAX max number of simultaneous clients
[304] Fix | Delete
# --temp-dir=DIR temporary directory
[305] Fix | Delete
# --do-not-reverse-lookup disable reverse lookup
[306] Fix | Delete
# --request-timeout=SECOND request timeout in seconds
[307] Fix | Delete
# --http-version=VERSION HTTP version
[308] Fix | Delete
# -v verbose
[309] Fix | Delete
#
[310] Fix | Delete
[311] Fix | Delete
def httpd
[312] Fix | Delete
setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
[313] Fix | Delete
"DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
[314] Fix | Delete
|argv, options|
[315] Fix | Delete
require 'webrick'
[316] Fix | Delete
opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
[317] Fix | Delete
[:Port, :MaxClients].each do |name|
[318] Fix | Delete
opt = options[name] and (options[name] = Integer(opt)) rescue nil
[319] Fix | Delete
end
[320] Fix | Delete
unless argv.size == 1
[321] Fix | Delete
raise ArgumentError, "DocumentRoot is mandatory"
[322] Fix | Delete
end
[323] Fix | Delete
options[:DocumentRoot] = argv.shift
[324] Fix | Delete
s = WEBrick::HTTPServer.new(options)
[325] Fix | Delete
shut = proc {s.shutdown}
[326] Fix | Delete
siglist = %w"TERM QUIT"
[327] Fix | Delete
siglist.concat(%w"HUP INT") if STDIN.tty?
[328] Fix | Delete
siglist &= Signal.list.keys
[329] Fix | Delete
siglist.each do |sig|
[330] Fix | Delete
Signal.trap(sig, shut)
[331] Fix | Delete
end
[332] Fix | Delete
s.start
[333] Fix | Delete
end
[334] Fix | Delete
end
[335] Fix | Delete
[336] Fix | Delete
##
[337] Fix | Delete
# Display help message.
[338] Fix | Delete
#
[339] Fix | Delete
# ruby -run -e help [COMMAND]
[340] Fix | Delete
#
[341] Fix | Delete
[342] Fix | Delete
def help
[343] Fix | Delete
setup do |argv,|
[344] Fix | Delete
UN.help(argv)
[345] Fix | Delete
end
[346] Fix | Delete
end
[347] Fix | Delete
[348] Fix | Delete
module UN # :nodoc:
[349] Fix | Delete
module_function
[350] Fix | Delete
def help(argv, output: $stdout)
[351] Fix | Delete
all = argv.empty?
[352] Fix | Delete
cmd = nil
[353] Fix | Delete
if all
[354] Fix | Delete
store = proc {|msg| output << msg}
[355] Fix | Delete
else
[356] Fix | Delete
messages = {}
[357] Fix | Delete
store = proc {|msg| messages[cmd] = msg}
[358] Fix | Delete
end
[359] Fix | Delete
open(__FILE__) do |me|
[360] Fix | Delete
while me.gets("##\n")
[361] Fix | Delete
if help = me.gets("\n\n")
[362] Fix | Delete
if all or argv.include?(cmd = help[/^#\s*ruby\s.*-e\s+(\w+)/, 1])
[363] Fix | Delete
store[help.gsub(/^# ?/, "")]
[364] Fix | Delete
break unless all or argv.size > messages.size
[365] Fix | Delete
end
[366] Fix | Delete
end
[367] Fix | Delete
end
[368] Fix | Delete
end
[369] Fix | Delete
if messages
[370] Fix | Delete
argv.each {|cmd| output << messages[cmd]}
[371] Fix | Delete
end
[372] Fix | Delete
end
[373] Fix | Delete
end
[374] Fix | Delete
[375] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function