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