Fortune program in other languages

Some times I like to see what the ‘fortune’ program says. Unfortunately,
openSUSE only distributes the English version, whereas debian has
several languages.

I downloaded the debian package “fortunes-es_1.32_all.deb”. Each data
“pack” or whatever, is made of two files and a link, like this:

amistad.fortunes
amistad.fortunes.dat
amistad.fortunes.u8 -> amistad.fortune

I tried copying this to the appropriate location in openSUSE,
/usr/share/fortune/.

However, when I try:



> cer@Telcontar:~> fortune amistad.fortunes
> Tómate tiempo en escoger un amigo, pero sé mas lento aún en cambiarlo.
>                 -- Benjamin Franklin. (1706-1790) Estadista y científico
>                 estadounidense.
> %
> El amor sin admiración solo es amistad.
>                 -- Aurore Dupín. (George Sand). (1804-1876) Novelista francesa.
> %
> Mis amigos me dicen que soy muy agresivo, pero me lo dicen a gritos.
>                 -- Jaume Perich.
> %
> El futuro es ese periodo de tiempo en el que prosperan nuestros
> negocios, nuestros amigos son verdaderos y nuestra felicidad segura.
>                 -- Ambrose Bierce. (1842-1914) Escritor estadounidense.
> %
> Amigo verdadero es el amigo de las horas difíciles.
>                 -- Jorge Piejanou.
> %
> Guarda a tu amigo bajo la llave de tu propia vida.
>                 -- William Shakespeare. (1564-1616) Escritor británico.
> %
> Los animales son buenos amigos, no hacen preguntas y tampoco critican.
>                 -- Mary Anne Evans 'George Elliot'. (1819-1880) Novelista
>                 británica.



See? I do not get a single saying, but all of them.

The format of the “amistad.fortunes” file is correct, the same as the
English ones, so it must be the control or “amistad.fortunes.dat” file
which is wrong.

I have some old fortune files, obtained from debian in 2006, that worked
then, but now fail in the same manner.

Thus I assume that something has changed in the way that openSUSE
creates that .dat file.

I can not use the debian makefile because it would do the same mistake -
how should I “susify” this, how can I create the correct data file?

Hints?


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-05-12 18:08, Carlos E. R. wrote:

> I can not use the debian makefile because it would do the same mistake -
> how should I “susify” this, how can I create the correct data file?
>
> Hints?

Of course I have looked at the openSUSE source rpm. I see some patches,
the code for the fortune program, the English fortune data files… but
no Makefile, so no hint of how they create the control files. There is a
spec file from which I deduce that make is invoked, but there is no
Makefile anywhere.

My guess is that they are created with this:



> NAME
>      strfile, unstr -- create a random access file for storing strings
>
> SYNOPSIS
>      strfile -iorsx] -c char] source_file [output_file]
>      unstr source_file
>
> DESCRIPTION
>      Strfile reads a file containing groups of lines separated by a line con-
>      taining a single percent `%' sign and creates a data file which contains
>      a header structure and a table of file offsets for each group of lines.
>      This allows random access of the strings.
>

....


But I have no idea what options they have used :frowning:


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-05-12 18:23, Carlos E. R. wrote:

>
> But I have no idea what options they have used :frowning:

Got it working. I’ll document the procedure, because it may be useful to
others.

First, get the debian package for your language, if it exists. I have
seen, I think Italian, French, German…


http://packages.debian.org/es/wheezy/fortunes-es

You can download the .deb package or the tar.gz, we only need the data
files. Copy these to any empty directory. Create a listing of it:


ls > lista_de_fortunes

which in my case it contains:


amistad.fortunes
arte.fortunes
asimov.fortunes
ciencia.fortunes
deprimente.fortunes
familia.fortunes
famosos.fortunes
filosofia.fortunes
humanos.fortunes
informatica.fortunes
lao-tse.fortunes
leydemurphy.fortunes
libertad.fortunes
nietzsche.fortunes
pintadas.fortunes
poder.fortunes
proverbios.fortunes
refranes.fortunes
sabiduria.fortunes
schopenhauer.fortunes
sentimientos.fortunes
varios.fortunes
verdad.fortunes
vida.fortunes

Run this script - adapt it to your language (the .es):


#!/bin/bash

rm *.es
rm *.dat

while read FILES  ; do
echo "----- tratando: $FILES"
NOMBRE=`basename $FILES .fortunes`
ln $FILES "$NOMBRE".es
/usr/sbin/strfile  "$NOMBRE".es "$NOMBRE".es.dat
done < lista_de_fortunes


This produces pairs of files like something.es and something.es.dat. All
those files (*.es and *.es.dat) you now copy to /usr/share/fortune/ so
that the system can use them. I do not copy the files named like
something.fortunes, that must be a debian naming convention.

(Note: “strfile” is in “/usr/sbin/”, but it does not require root
privileges at all).

Now you create another script; in my case it is
/usr/local/bin/fortune_es:


> /usr/bin/fortune $* amistad.es asimov.es deprimente.es famosos.es humanos.es lao-tse.es libertad.es pintadas.es \
>     proverbios.es sabiduria.es sentimientos.es verdad.es arte.es ciencia.es familia.es filosofia.es informatica.es \
>     leydemurphy.es nietzsche.es poder.es refranes.es schopenhauer.es varios.es vida.es


It simply calls ‘fortune’ with the list of fortune files I want to use.
Of course, you have to write your own list.

Fortune is an old program, there is no parameter you can use to tell it
the language to use; however, you can tell it a list of files to use.

Also, I do not know what options the openSUSE packager has used to
create the control files with ‘strfile’: there are sort options,
randomization options… However, with none at all, it works.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

I would have liked to have been there to watch how you did that!

Thanks for the documentation!

Bart

On 2013-05-15 07:06, montana suse user wrote:
>
> I would have liked to have been there to watch how you did that!
>
> Thanks for the documentation!

Welcome :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)