You are not logged in.
I am writing a script where I need to check the existence of ruby-gtk2., If it is installed, I start the gui version of the program and if not, then I want to start the CLI version of the program.
How would I check this in a script?
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
maybe something like this?
#!/bin/bash
x=`pacman -Qs ruby-gtk2`
if [ -n "$x" ]
then echo "Installed"
else echo "Not Installed"
fi
Offline
if (pacman -Q ruby-gtk2 >/dev/null) ; then echo "ruby-gtk2 is installed"; fi
But I'd probably simply check for the existance of a file:
if [ -f /usr/lib/ruby/site_ruby/1.8/gtk2.rb ]; then...
1000
Offline
Thanks guys. evr your answer seems obvious -- now why didn't I think of that, but of course it only applies to Arch.
byte, your 2nd option of checking for the existence of the file seems logical, but what if ruby upgrades to 1.9, I would have to refactor the script, correct?
I think using pacman would be the best bet here.
Last edited by Inxsible (2009-03-03 06:43:21)
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
begin
require 'gtk2'
rescue LoadError
puts 'ruby-gtk2 not installed'
end
It's simple enough to use ruby to test if ruby-gtk2 is installed or not.
Another option would be to check if the gui app returns a specific value or piece or text when ruby-gtk2 is missing that you could check for.
Offline
if you know exactly how the binaries should be named, you don't need to even know where they are , you don't need pacman , and you're not bound to Arch.
which $PROGRAM_NAME >/dev/null && echo "program installed"
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
begin require 'gtk2' rescue LoadError puts 'ruby-gtk2 not installed' end
It's simple enough to use ruby to test if ruby-gtk2 is installed or not.
Another option would be to check if the gui app returns a specific value or piece or text when ruby-gtk2 is missing that you could check for.
yes. I know how to do that with ruby. The code actually does check for this. But I wanted to put it in a shell script, so that I could use the same PKGBUILD for the CLI version and the gtk version.
The author's code simply spits out an error message when you start up the gtk version without having ruby-gtk installed. So I just created a script which checks this beforehand and accordingly starts either the command line app or the gtk app.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
if you know exactly how the binaries should be named, you don't need to even know where they are , you don't need pacman , and you're not bound to Arch.
which $PROGRAM_NAME >/dev/null && echo "program installed"
That seems even better. However, the PKGBUILD is for Arch and on top of that, the program name also differs according to the distro. For eg. Debian has that package as libgtk2-ruby. So when I search for ruby-gtk2 using the 'which' command, I am pretty much restricting to Arch again (or any other distro which uses the ruby-gtk2 as the package name)
But yeah, using which is better I guess, since that is a built in function.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
winch wrote:begin require 'gtk2' rescue LoadError puts 'ruby-gtk2 not installed' end
It's simple enough to use ruby to test if ruby-gtk2 is installed or not.
Another option would be to check if the gui app returns a specific value or piece or text when ruby-gtk2 is missing that you could check for.
yes. I know how to do that with ruby. The code actually does check for this. But I wanted to put it in a shell script, so that I could use the same PKGBUILD for the CLI version and the gtk version.
The author's code simply spits out an error message when you start up the gtk version without having ruby-gtk installed. So I just created a script which checks this beforehand and accordingly starts either the command line app or the gtk app.
Perhaps it would be better to explain what you're trying to do. It seems that what you really want is to simply specify ruby-gtk2 in optdepends in the PKGBUILD. If you really need the script solution, and this is for an Archlinux package, then the lack of portability is a non-issue, so the pacman solution is fine.
Offline
Perhaps it would be better to explain what you're trying to do. It seems that what you really want is to simply specify ruby-gtk2 in optdepends in the PKGBUILD. If you really need the script solution, and this is for an Archlinux package, then the lack of portability is a non-issue, so the pacman solution is fine.
I just got this software which can be used via CLI or GTK. The author checks for ruby-gtk2 and then puts an error message saying that you do not have ruby-gtk2 installed.
However, I wanted to build just 1 PKGBUILD for the CLI version as well as the GTK version, that's why I decided to build an sh script which will check for ruby-gtk2 and then if available start the GUI version or else start the CLI version. Of course if you do have ruby-gtk2 installed and still want to start the CLI version, you will have to create a different script. Maybe later down the line, I will put in two PKGBUILDS - one for CLI and the other for GTK
But its all done, Here's the app that I submitted to AUR.
Last edited by Inxsible (2009-03-06 16:20:53)
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Looking at the pkgbuild I don't understand why this script is needed. Upstream provides two separate programs so why try to merge them into one? There isn't any reason why a package can't put more than one file in /usr/bin.
Offline
Looking at the pkgbuild I don't understand why this script is needed. Upstream provides two separate programs so why try to merge them into one? There isn't any reason why a package can't put more than one file in /usr/bin.
you are absolutely right. There is no need for it. I did that because I didn't want to put 2 PKGBUILDs for the same app and still allow users who did not want to install ruby-gtk2, to be able to use the package. As of now ruby-gtk2 is in optdepends.
But I guess I have come around that and as I mentioned in my earlier post, I will be changing it and submitting two PKGBUILDS to AUR, so users can either download the CLI version or the gtk version.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline