Shoes Command Line

Did you know that Shoes has a command line? It’s very useful. While this posting is about Shoes 3.2 (Federales) on Linux, It’s there for Windows and OSX users of any version of Shoes if you know the path of the installed Shoes app. There are several ways to get Shoes for your Linux system. The simple way is to
download a binary distribution, a .run from here.

I’m going to use the Raspberry Pi version of Shoes 3.2b4 on a newly created Raspbian sdhc card. The only changes I’ve made to the basic installed Raspbian is to replace the ‘pi’ user with ‘ccoupe’ and get ssh working. Shoes is a GUI application so you should startx and open a LxTerminal. First, download the run file and make it executable.
ccoupe@pi ~ $ wget http://shoes.mvmanila.com/public/shoes/shoes-3.2b4-gtk2-armhf.run
ccoupe@pi ~ $ chmod +x shoes-3.2b4-gtk2-armhf.run

Raspbian has a cute little feature-bug with ‘su’ which is used by the installion script because not all systems have sudo installed. There are two ways to handle the bug. One way is to set a password for ‘root’ like this:

ccoupe@pi ~ $ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Or you can just hand edit the and copy the file that needed su used for. I also show that method below because it also shows how to create menus for Linux desktop menus.

ccoupe@pi ~ $ ./shoes-3.2b4-gtk2-armhf.run
Verifying archive integrity... All good.
Uncompressing Shoes....................................................................................................................................................................................................................................................
Shoes has been copied to /home/ccoupe/.shoes/federales. Need root password
to copy Shoes.desktop to /usr/share/applications
Password:
su: Authentication failure

Oops. We’ll work around that failure. It’s obvious what it wanted to do. Shoes was installed in ~./shoes/federales. Lets go there and poke around.
ccoupe@pi ~/.shoes/federales $ ls
CHANGELOG.txt libcurl.so.4 libshoes.so shoes
COPYING.txt libgif.so.4 libssl.so.1.0.0 shoes-bin
debug libjpeg.so.8 libungif.so.4 Shoes.desktop.tmpl
fonts libruby.so libyaml.so shoes-install.sh
lib libruby.so.2.0 README.txt static
libcrypto.so.1.0.0 libruby.so.2.0.0 samples
ccoupe@pi ~/.shoes/federales $ more shoes-install.sh
#!/bin/bash
#pwd
ddir=$HOME/.shoes/federales
#echo $ddir
mkdir -p $ddir
cp -r * $ddir/
sed -e "s@{hdir}@$HOME@" Shoes.desktop
echo "Shoes has been copied to $ddir. Need root password"
echo 'to copy Shoes.desktop to /usr/share/applications'
su root -c 'cp Shoes.desktop /usr/share/applications'

That’s the script the install process ran at the end. It justs rewrites a template with sed and copies that. I’ll do that by hand.
ccoupe@pi ~/.shoes/federales $ sed -e "s@{hdir}@$HOME@" Shoes.desktop
ccoupe@pi ~/.shoes/federales $ sudo cp Shoes.desktop /usr/share/applications/

Verify there is a Shoes entry in the Programming menu. Since Shoes is not installed in the system directories (except for the .desktop file), you can’t hurt the system by redoing the install. So Lets get to the commandline.

./shoes -h
Usage: shoes [options] (app.rb or app.shy)
-m, --manual Open the built-in manual.
-p, --package Package a Shoes app for Windows, OS X and Linux.
-g, --gem Passes commands to RubyGems.
--manual-html DIRECTORY Saves the manual to a directory as HTML.
--install MODE SRC DEST Installs a file.
--nolayered No WS_EX_LAYERED style option.
-v, --version Display the version info.
-h, --help Show this message

-p and -m are the same as the Shoes splash screen links. You could Make a ‘Shoes Manual’ menu entry with what I’ve shown you. Just copy and modify that .desktop file. That’s how Windows gets Three menu entries for Shoes.

Shoes has it’s own private Ruby interpreter and gem handling. -g or --gem is what I really want to explore but there is a an undocumented --ruby option you should know about first. Everything after –ruby is passed on just like a normal Ruby command line.
ccoupe@pi ~/.shoes/federales $ ./shoes --ruby -e "puts RUBY_PLATFORM"
armv7l-linux-eabihf

You won’t see it on a fast system but calling ruby that way can be slow. Useful but limited. Your chances of processing a rake script that way is very low. I only bring that up because Shoes will start another copy of itself just that way in order to compile some gems. That gets us back to gems, -g or –gems

Gem are Ruby Libraries or Extensions that are downloaded from the net and installed into your Ruby and when your script needs that, you can require 'gem-name'. Python has something similar as does Perl. There are lots of gems that Shoes users might want to use. Older versions of Shoes used to include a couple of gems, Hpricot for parsing xml and Sqlite. Shoes 3.2 does not include them currently. It’s OK. I’ll explain a better way in a minute.

Gems are pure Ruby code or a mixure of Ruby & C source code. If you get one with C source code, it needs to compiled before in can be installed. Note: newer gems may have precompiled C but you can’t depend on that being true for the gem you want. To compile ‘C’ you need the compiler and build tools. On the Raspberry, these are already installed.

Lets see what the Gem environment looks like with -g env.
ccoupe@pi ~ $ ./.shoes/federales/shoes -g env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [armv7l-linux-eabihf]
- INSTALLATION DIRECTORY: /home/ccoupe/.shoes/+gem
- RUBY EXECUTABLE: /home/ccoupe/.shoes/federales/shoes --ruby
- EXECUTABLE DIRECTORY: /home/ccoupe/.shoes/+gem/bin
- SPEC CACHE DIRECTORY: /home/ccoupe/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- armv7l-linux
- GEM PATHS:
- /home/ccoupe/.shoes/+gem
- /home/ccoupe/.gem/ruby/2.0.0
- /home/ccoupe/.shoes/federales/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/local/games
- /usr/games

Right off, we see some interesting things. The version of RUBYGEMS is pretty current as is the Ruby Version. Don’t worry that armv7l-linux-eabihf doesn’t match anything you think is raspberry like. It’s just Ruby being ‘different’. Gems will be installed in ~/.shoes/+gem .

Let’s see if we have any gems:
ccoupe@pi ~/.shoes/federales $ ./shoes -g list --local

*** LOCAL GEMS ***

bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)

Those gems are included in Ruby 2.0. They aren’t in ~/.shoes/+gems. Notice that there a multiple GEM_PATHS.
Ruby is flexibile that way — there always two or more correct ways to get things done. Let’s install a pure ruby gem ‘metaid’. I don’t remember what the gem does, just that it’s small and pure ruby -its only a example. Be patient, Shoes on Pi + downloading can take a while.
ccoupe@pi ~/.shoes/federales $ ./shoes -g install metaid
Fetching: metaid-1.0.gem (100%)
Successfully installed metaid-1.0
Parsing documentation for metaid-1.0
Installing ri documentation for metaid-1.0
1 gem installed
Exiting RubyGems with exit_code 0

Try the -g list –local again. There it is:
...
json (1.7.7)
metaid (1.0)
minitest (4.3.2)
...

How about a gem that has ‘C’ code to be compiled. Serialport is something Raspberry pi folk might be interesting in using. It allows to you read/write from a /dev/ttyxxx. Again this only an example for this post. I’m not claiming it’s what you want.

ccoupe@pi ~/.shoes/federales $ ./shoes -g install serialport
Fetching: serialport-1.3.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed serialport-1.3.0
Parsing documentation for serialport-1.3.0
Installing ri documentation for serialport-1.3.0
1 gem installed
Exiting RubyGems with exit_code 0

Note that ‘Building native extensions’ line. Depending on the gem, it can take a long time on the Raspberry pi. Gems can also fail to build if you don’t have the dependent libraries and header files. Want to see that? Let’s go, we can learn from out experiments. First we’ll get a list of possible sqlite gems to install:
ccoupe@pi ~/.shoes/federales $ ./shoes -g list --remote sqlite

*** REMOTE GEMS ***
....
sqlite3 (1.3.9 ruby x64-mingw32 x86-mingw32 x86-mswin32-60)
sqlite3-dotnet (3.7.2.1)
sqlite3-ironruby (0.1.1)
sqlite3-ruby (1.3.3, 1.3.2 x86-mingw32 x86-mswin32-60, 1.2.5 x86-mswin32, 1.2.3 mswin32)
....

There is a great example of gems with multiple precompiled binaries inside and more that one choice that Ruby allows. I want the sqlite3. Houston, we have a failure!
ccoupe@pi ~/.shoes/federales $ ./shoes --gem install sqlite3
Fetching: sqlite3-1.3.9.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.

/home/ccoupe/.shoes/federales/shoes --ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
....
extconf failed, exit code 1

Gem files will remain installed in /home/ccoupe/.shoes/+gem/gems/sqlite3-1.3.9 for inspection.
Results logged to /home/ccoupe/.shoes/+gem/extensions/armv7l-linux/2.0.0/sqlite3-1.3.9/gem_make.out
Exiting RubyGems with exit_code 1

That’s almost too easy. It even tells us to we don’t have sqlite3.h and to ‘apt-get install libsqlite3-dev’ on the pi. More difficult errors might require looking the /home/ccoupe/.shoes/+gem/extensions/armv7l-linux/2.0.0/sqlite3-1.3.9/gem_make.out

Let install sqlite3-dev
ccoupe@pi ~/.shoes/federales $ sudo apt-get install libsqlite3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
sqlite3-doc
The following NEW packages will be installed:
libsqlite3-dev
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 537 kB of archives.
After this operation, 1,175 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libsqlite3-dev armhf 3.7.13-1+deb7u1 [537 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libsqlite3-dev armhf 3.7.13-1+deb7u1 [537 kB]
Fetched 83.0 kB in 2min 2s (680 B/s)
Selecting previously unselected package libsqlite3-dev.
(Reading database ... 62359 files and directories currently installed.)
Unpacking libsqlite3-dev (from .../libsqlite3-dev_3.7.13-1+deb7u1_armhf.deb) ...
Setting up libsqlite3-dev (3.7.13-1+deb7u1) ...

and try to install that gem again.
ccoupe@pi ~/.shoes/federales $ ./shoes --gem install sqlite3
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.9
Parsing documentation for sqlite3-1.3.9
Installing ri documentation for sqlite3-1.3.9
1 gem installed
Exiting RubyGems with exit_code 0

There you go! No magic required. In true Ruby fashion there is another way to install gems from inside a Shoes script (see sample/simple-rubygems.rb) but it won’t install or compile what you don’t have so you’d end up confused about the errors and end up doing what I just demonstrated.

Perhaps you’re not using a Pi. It’s the same for for 32bit or 64 bit Linux (Suse, Fedora, Debian, Ubuntu…) The only difference is which Shoes you download and what commands you need to install the compiler and build tools – port,yum,apt-get and what is the name of the package that has what you want. Sadly. That’s more difficult than I can write up on a Shoes post. I will mention in passing that a bare Ubuntu needs ‘build-essential’ – search for it – it might be build-essentials.

Good Luck and enjoy your Shoes!

Leave a Reply

Your email address will not be published. Required fields are marked *