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