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