Can Ruby interact with my root privileges? - ruby

This is my first question here, please tell me if I can in some way tag it better or make a better question :)
I'm trying to make a ruby script to install some packages and edit some configurations after I format a computer. I use Manjaro Linux, and my script can already install the official Arch packages, but when it comes to AUR (with Yay) I sometimes receive an error message, saying that Yay can't run as sudo. Also I saw that some people can integrate their Shell with other scripting languages, I started this, but still need to type my Root password more than I want to.
I searched for help on this and found that Python have a library called Pexpct, but didn't found any Ruby alternatives to it. I saw somethings related to Ruby's Expect and IO, but couldn't understand how and when to use it.
programs = [
"zsh",
"zathura",
"zathura-cb",
"zathura-djvu",
"zathura-pdf-mupdf",
"zathura-ps",
"texlive-most",
"texlive-lang",
"geogebra",
"vim",
"yay",
"adobe-source-code-pro-fonts",
"firefox-developer-edition"
]
#Array iteration to install Arch official repo's packages
programs.each do |name|
system ("pacman -Sq #{name} --noconfirm")
end
I want to know if in some way can this code inside the programs block insert my password. I know it has a lot of security problems, but is on this case for this one snippet of code and study cases. I won't use it on other scripts.

Related

How to get Processing to work on Cloud9 using Ruby language?

I am currently working on a personal project using the Ruby language in Cloud9 IDE. Recently, I came across an environment/programming language called Processing. My goals is to make Processing available for my use in Cloud9 IDE.
I am a complete novice and have no clue what I am doing. I followed directions from the following website: Directions for setting up Processing
I entered the following commands into Cloud9's terminal:
rvm install jruby
rvm use jruby
gem install ruby-processing
PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"
Entering in PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"
outputted message bash: PROCESSING_ROOT:: command not found
I wasn't too surprised by this, since the last entry probably needs information specific to my setup. Here are my questions:
1.) Are these directions correct for what I am trying to do? (get Processing to work in Cloud9 IDE). If they are not correct, can someone please point me to the correct directions, or give me directions?
2.) If these directions are correct, how can I successfully finish the last step? I tried running DrawRuby.rb, a simple program copied from the internet that supposedly made use of Processing. When I ran the code, the message "You need to set PROCESSING_ROOT in ~/.rpsrc" appeared. I am not sure if this piece of information is relevant or not, but I figured I would add it.
This is where I am at, and I am completely stuck. If someone could give me some help, I would be very grateful. Also, please make your explanation easy to understand. I am relatively new to the programming world, and may not necessarily understand terminology or how things should work.
Cheers!
*** Edit: I created a new workspace in Cloud9 IDE and tried Jed's suggestion. This is what happened:echo 'PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"' > ~/.rpsrc
:~/workspace $ rp5 run Draw.rb
WARNING: you need to set PROCESSING_ROOT in ~/.rp5rc
NameError: uninitialized constant Processing::RP_CONFIG
Did you mean? Config
RbConfig
const_missing at org/jruby/RubyModule.java:3344
spin_up at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:188
run at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:105
execute! at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:67
execute at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:61
<main> at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/bin/rp5:10
load at org/jruby/RubyKernel.java:979
<eval> at /usr/local/rvm/gems/jruby-9.1.7.0/bin/rp5:1
eval at org/jruby/RubyKernel.java:1000
<main> at /usr/local/rvm/gems/jruby-9.1.7.0/bin/jruby_executable_hooks:15
You need to add a file to your home directory (~/) called .rpsrc and then add that environmental setting (PROCESSING_ROOT) to your file. The following should work from the command line in your cloud9 environment:
echo 'PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"' > ~/.rpsrc
I know it might be a bit late for you but ruby-processing is now deprecated, and will only work with processing-2.2.1. For processing-3.3.7 use either JRubyArt or propane latter does not even require processing install.

Tensorflow object detection: ImportError: No module named nets

I am currently attempting to install the tensorflow object detection app on Windows 7 (employer requirement) and I am failing at a few steps from the end.
Basically I get the following error when I run the installation test command:
ImportError: No module named nets.
I have read some solutions on the subject:
https://github.com/tensorflow/models/issues/729
https://github.com/tensorflow/models/issues/1842
which looks like this:
export PYTHONPATH="$PYTHONPATH:"somepath"/tensorflow/models/slim"
basically meaning that I must set the right path in the PYTHONPATH environmental variable.
Working with Windows, I tried calling this:
SET PYTHONPATH="$PYTHONPATH:C:tensorflow/models/slim
And when it didn't work, I created a PYTHONPATH variable in system-> environmental variables.
I'm still getting the error so I suppose that I am still missing something but due to my lack of knowledge I still can't figure out what.
Would someone familiar with Windows be able to point out what's missing?
Thanks
in linux:
add export export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim to ~/.bashrc
attention:you should keep single quote mark
if you work with windows, i guess it should like this:PYTHONPATH=$PYTHONPATH:'C:/tensorflow/models':'C:/tensorflow/models'/slim
just my guess, you can take a try.
good luck!
If you run the setup.py it will install all the relevant modules for object detection. The other option is download the git directory. cd to the folder and try to run the module from there. You might face protubuf issue. Try to install it before running the code. It's bit complicated to install protobuf in windows. But if you are not using ".pb" file, then you don't need to.
I figured out a way to make it work. I am not writing this as a final answer as it is mostly a workaround and due to lack of understanding from my part I cannot guarantee it will work (and also it might not be best good practice).
Anyway here it is:
As Beta previously suggested, you have to run setup.py, however running it from models folder did not do it for me, I also had to run it from object detection folder.
However there was a problem there, it generated an error saying the BUILD already existed (which was correct) so I had to delete the BUILD file from inside of model.
After that it worked, turns out the path I had set was working fine.
Now if some experts would look into this and explain how and why this workaround worked it might make this a valid solution.

Problems installing Flagmatic

I'm trying to install Flagmatic on Mac OS X Yosemite, a software package used to solve problems in extremal graph theory using the "flag algebras" developed by Razborov. I'd like to use Flagmatic to help with a research problem I'm working on, but I'm finding it very difficult to install. I'm a mathematician and while I've had some experience using Sage and Python through the Terminal I don't really know how to fix the sort of problems that I'm running into here. Here's the most up-to-date user guide so you can follow what I'm trying to do. I can broadly break down the problem as follows:
First, there is a link in the user guide to download the semidefinite programming package CSDP which Flagmatic needs in order to do some calculations. You then need to move CSDP to somewhere Flagmatic can find it, so I typed
sudo cp ~/Downloads/csdp/usr/local/bin/
into Terminal, which seemed to work. Then the user guide says by typing
csdp
into Terminal it should launch CSDP. This doesn't work - I get a permission denied message even though I typed sudo. Can anyone explain why this is happening and how to remedy it?
Secondly, when I run Sage (maths software) in the Terminal, I then want to be able to change directory to the pkg folder where there is a script called setup.py. When I run sage and type
python setup.py install
or
-python setup.py install
while in the pkg directory, I get an invalid syntax message with a pointer to the particular phrase setup.py. This is what the user guide tells you to do. If I instead try to install outside of Sage I get an error message The environment variable SAGE_ROOT must be defined. Can anyone provide some explanation and help with how to fix this?
Wow, this is somewhat dated information that they provide, since for well over a year csdp is an experimental Sage package. You should be able to just do
sage -i csdp
to install it (if you have compiler tools, which you probably do in this case). I guess the old instructions would still work but are a little brittle w.r.t. Sage.
Anyway, to the actual problem. You need to do the exact command given in the instructions:
sage -python setup.py install
However, this assumes (!) that you have a sage command in your PATH. Which you may not!
In this case, I recommend you use whatever command you use to run Sage, but instead of just typing /commmand/for/sage do /command/for/sage -python setup.py install in that directory. It will have all the right environment variables set up so that it installs in the right place, I am guessing.
Now, I'm not sure why flagmatic isn't just having themselves become an upstream package on the Sage servers, but that is a question that is harder to answer.
I might udpate the documentation in the near future. For now, however, you might want to visit this: https://github.com/jsliacan/flagmatic-2.0.git. I keep Emil's copy of Flagmatic 2.0 with updated install info. If you follow the README file, you should be fine.
I just built sage on Yosemite from source (worked fine) and then installed Flagmatic 2.0 (or Flagmatic-dev) without difficulties. It should work for you too.
I hope this helps.

Perform SVN operations through a ruby script on windows/osx

I am a newbie and need to perform some basic SVN operations (like get info of the repository, add, commit, update etc) through a ruby script, on both windows/osx.
I searched the forum and internet, only to find partial and confusing answers related to SWIG ruby-subversion bindings etc, but none of them was well documented or simple enough to use [Also, most of these questions and answers are pretty old].
I am assuming that a simpler way to perform SVN operations through a ruby script should exist by now. Correct me if my assumption is wrong.
Also, is it worth the hassle to install SWIG bindings, understand 'svn/core' library and use it with a gem (like svn_wc) OR better to simply call svn command line commands from ruby? Is there a massive difference in performance for these approaches?
Any help will be much appreciated.
A simple way is to use SVN command line tools from Ruby.
Say you are in a sandbox and you have a script 'svn-get_uuid'.
It could look like this:
$ cat svn-get_uuid
#!/usr/bin/ruby
uuid = `svn info`.lines.grep /^UUID/
uuid = uuid[0].chomp.sub /^.*: (.+)/, '\1'
print "{#{uuid}}\n"
$ ./svn-get_uuid
{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
May be you can do it faster using the svn-bindings, but working this way is OK for my daily work.

Ruby libraries for command-prompt-based applications

I'm looking to create a Ruby application with a command-prompt-based interface. By "command-prompt-interface," I mean something similar to irb, but note that I do not mean actually executing Ruby code. The gems I'm finding via Google seem to be more suited to CLIs like git, not an actual prompt like irb.
I need to be able to define commands and handlers for those commands, so something like:
(prompt) helloworld
Hello World
(prompt)
Validation and a built-in help system would also be good extras, as would the ability to execute a single command from the command line (calling it from the shell cliapp.rb -c helloworld).
I'm able to create this from scratch, but if there are any libraries available I'd prefer to use that rather than reinventing the wheel.
You may want to try Methadone, which was created by David Bryant Copeland, the author of the book "Build Awesome Command-Line Apps in Ruby". You may want to check out the book as well.
See this blog post for more information.

Resources