More fortunes for Mint

If you like to see some funny quotes when opening a new shell terminal, you can enable the fortune-mint script that will be launched automatically.
By default, this script only shows non-offensive quotes and only three different types of animals: the moose, the tux and the koala.
But the cowsay package provides a whole bunch of pictures that can be used.
Cow files in /usr/share/cowsay/cows:
apt beavis.zen bong bud-frogs bunny calvin cheese cock cower daemon default
dragon dragon-and-cow duck elephant elephant-in-snake eyes flaming-sheep
ghostbusters gnu head-in hellokitty kiss kitty koala kosh luke-koala
mech-and-cow meow milk moofasa moose mutilated pony pony-smaller ren sheep
skeleton snowman sodomized-sheep stegosaurus stimpy suse three-eyes turkey
turtle tux unipony unipony-smaller vader vader-koala www

The following patch will enable all these that you have installed in your system, as well as all different eye and tongue styles. If you don't like offensive quotes, you'll have to take off the -a parameter from the fortune command in the last line of the patch below.

Install instructions

Paste the following into a textfile, for example mint-fortune.patch
4c4
<     RANGE=3
---
>     declare -a cows=( $(cowsay -l | grep -v "Cow files in") )
6,17c6,7
<     let "number %= $RANGE"
<     case $number in
<         0)
<             cow="moose"
<             ;;
<         1)
<             cow="tux"
<             ;;
<         2)
<             cow="koala"
<             ;; 
<     esac
---
>     let "number %= ${#cows[*]}"
>     cow=${cows[$number]}
19c9
<     RANGE=2
---
>     declare -a says=( say think )
21,30c11,19
<     let "number %= $RANGE"
<     case $number in
<         0)
<             command="/usr/games/cowsay"
<             ;;
<         1)
<             command="/usr/games/cowthink"
<             ;;
<     esac
<     /usr/games/fortune | $command -f $cow
---
>     let "number %= ${#says[*]}"
>     command="/usr/games/cow${says[$number]}"
> 
>     declare -a states=( "" -b -d -g -p -s -t -w -y )
>     number=$RANDOM
>     let "number %= ${#states[*]}"
>     state=${states[$number]}
> 
>     /usr/games/fortune -a | $command $state -f $cow

Then apply this patch to the original script (a backup will be created) and enable the fortune-teller:
sudo patch -b /usr/bin/mint-fortune mint-fortune.patch
gconftool-2 --set /desktop/linuxmint/terminal/show_fortunes true --type bool

Provide your own cows

You can create your own cow files, just have a look at the manual of the cowsay command. Or just copy the ones I prepared from here into any folder you want.
You could just copy them into the system folder /usr/share/cowsay/cows, but if you want to keep them separated, you can instruct cowsay to look for you ones too (for example in your folder ~/Documents/cows:
mycows=~/Documents/cows ; sudo sed -i.orig 's|/usr/bin/mint-fortune|export COWPATH=/usr/share/cowsay/cows:'$mycows'\n\0|' /etc/bash.bashrc

Example of a Star Wars scene as cow

 _____________
< Hello world >
 -------------
          \
           \                .==.
            \              ()oo()-.
             \  .---.       ;--; /
              .'_:___". _..'.  __'.
              |__ --==|'-''' \'...;
              [  ]  :[|       |---\
              |__| I=[|     .'    '.
              / / ____|     :       '._
             |-/.____.'      | :       :
            /___\ /___\      '-'._----' 

SSH key handling

If you have to work with servers, especially with Linux ones, sooner or later you'll have a confrontation with SSH.

I'll give here some tips and tricks I used so far.

Force user and port for certain servers

When you try to login into a server, by default ssh uses your username and port 22 by default.
But maybe you need to use always another user name or another port.
You could specify this always as parameters for ssh:
ssh -p 22022 [notme@]server-ip

But it is much easier to configure your ssh client to these by default.
Therefore, you just add the following to your ~/.ssh/config file:
host server-ip another-server-name
Port 22022
User notme

host *
User root
You can put here as many hosts with different parameters as you want, '*' is also supported for creating regular expressions.

Change order of authentication methods

There's a another very useful parameter that you might want to add to your server configurations:
host *
User root
PreferredAuthentications publickey,password

This would only allow to use keys or passwords and prevents to use other methods which might not work in your setup and slow down connection attempts.
Put this whenever you notice that it take several seconds to log into a server.

Copy your own key to server

This used to be the first step I do, whenever I access a certain server several times.
So I don't have to give the password each time I access the server.
# Copy my machines public key to the server (will prompt for password):
ssh-copy-id [user@]server-ip

# Unfortunately, ssh-copy-id only works with SSH port 22, so if you have to specify another
# one, you might use this instruction:
ssh-add -L | ssh -p22022 [user@]server-ip "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys"

# Verify the granted access (now without password prompt):
ssh [user@]server-ip
# or when copying
scp afile.txt server-ip:test/ 

Fix non-working ssh public keys

Sometimes, the sshd server doesn't accept a previous copied ssh-key (ssh-copy-id). In that case, make sure you have the following configuration in /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

# If it still doesn't work apply the correct permissions to folders and files:
# chmod go-w ~
# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/authorized_keys

# If it still doesn't work, then disable the permissions checking:
StrictModes no
Restart the ssh daemon again after applying this new configuration.

Debugging and sorting out further problems

The permissions of files and folders is crucial. You can get debugging information from both the client and server. if you think you have set it up correctly, yet still get asked for the password, try starting the server with debugging output to the terminal. /usr/sbin/sshd -d
To connect and send information to the client terminal ssh -v ( or -vv) username@host's

Remove authorized keys

If you have hundreds of keys in your machines ~/.ssh/authorized_keys and you're to lasy to edit that by hand, these one-line shell commands maybe handy.
Just use sed to rip out anything which doesn’t match the regex pattern (for example machine names, part of the hash, whatever:
# rip out anything which doesn’t match the regex pattern
sed ‘/your host name/ ! D’ -i.old ~/.ssh/authorized_keys

# or something more complicated
sed ‘/\(host1\|host2\)/ ! D’ -i.old ~/.ssh/authorized_keys

# with many patterns it is easier with this command
cp ~/.ssh/authorized_keys{,.old} && for p in pat1 pat2 pat2 ; do sed '/$pat1/ ! D' ~/.ssh/authorized_keys ; done

Just the ones specified will be maintained, a backup file will be created.
If you want to do the opposite, remove some specific keys and let the rest untouched:
sed ‘/\(host1\|host2\)/ D’ -i.old ~/.ssh/authorized_keys

Music Player Clementine

A few days ago, I discovered another music player which I'm using now daily: Clementine.

Features I like:
  • It's quick and stable.
  • Mood graphics of songs.
  • Dynamic random playlists.
  • Discover song information, covers and lyrics from variety of sites.
  • Cover manager to retrieve from even more sources.
  • Extensive artist information gathered from various sources.
  • Tons of visualization algorithms, random changes.
  • It integrates well with Cinnamons sound gadget.
Unfortunalty, the handling of external devices isn't perfect yet.
At least, I was not able to add songs from my external harddisks to the random playlist, I had to create a new playlist for that purpose.

Install instructions

Use Y-PPA-Manager and search for clementine package to obtain list of repositories or use the following shell commands:

sudo apt-add-repository ppa:me-davidsansome/clementine
sudo apt-get update
sudo apt-get install clementine

# You need to install the developer version for version 1.1, which features mood bars)
sudo apt-add-repository ppa:me-davidsansome/clementine-dev

Change LibreOffice progress bar color

Newest LibreOffice splash screen shows a orange-redish colour bar instead of a green one like it was some versions ago. I guess they changed it to integrate better with Unity default colours. But I'm using Linux Mint, so I liked the green one more. The other day, I just stumbled about the /etc/libreoffice/sofficerc configuration file, which defines some variables for the startup and there it is, the ProgressBarColor parameter.

Install instructions

The following instructions change the color from the shell command line, but you could also just edit the file with your favourite text editor (with root permissions).
# Put the color value into a variable
pbcolor=160,195,124

sudo sed -r -i.bak "s/(ProgressBarColor=)[0-9]{1,3},[0-9]{1,3},[0-9]{1,3}/\1${pbcolor}/" /etc/libreoffice/sofficerc

# Check that everything went fine (otherwise you can restore the backup file).
cat /etc/libreoffice/sofficerc
You can find the right colors for example with the Gimp image editor.

Mint Update Manager does not show Changelogs

If you are using Linux Mint, you might have noticed that the latest versions ship with an Update Manager that is able only to show you Changelogs of the packages from the Mint repositories and often they are cut off.

After searching through bug reports and forums finally I prepared a change of the underlying Python code which resolves the issue.

I hope they will integrate similar changes in the next version.

For more details you can have a look at these bug reports, where I got ideas and copied parts:

Install instructions

You can download the needed difference file from here, or just copy and paste the following into a file named mintUpdate.py.diff:
87c87,91
<                 changelog = source
---
>                 changes = source.split("\n")
>                 for change in changes:
>                     change = change.strip()
>                     if change.startswith("*"):
>                         changelog = changelog + change + "\n"
93c97,101
<                     changelog = source
---
>                     changes = source.split("\n")
>                     for change in changes:
>                         change = change.strip()
>                         if change.startswith("*"):
>                             changelog = changelog + change + "\n"
98,102c106,111
<                 source = commands.getstatusoutput("apt-get changelog " + self.source_package) 
<                 if source[0] != 0 or source[1].startswith("Err Changelog of"):
<                     changelog = _("No changelog available") + "\n" + _("Click on Edit->Software Sources and tick the 'Source code' option to enable access to the changelogs")
<                 else:
<                     changelog = source[1]
---
>                 source = commands.getoutput("aptitude changelog " + self.source_package)                    
>                 changes = source.split("urgency=")[1].split("\n")
>                 for change in changes:
>                     change = change.strip()
>                     if change.startswith("*"):
>                         changelog = changelog + change + "\n"
Then you can apply the patch with this command, it will leave a copy of the original script:
sudo patch -lb /usr/lib/linuxmint/mintUpdate/mintUpdate.py mintUpdate.py.diff
It has been created and checked with version 4.3.8.

Install LibreOffice 3.5

The current version of LibreOffice which ships with Ubuntu Oneiric is 3.4.4.
Lately, I was getting very angry about this version, because it gave me constant trouble:
  • it looses somehow control about its lock-files, therefore I wasn't able to save my open files any longer, neither with the old nor with a new name
  • graphics in calc files suddenly jumped to another sheet when opening the files
I loved LibreOffice so far, but this behaviour really pi.... me of.
So the other day, I read about the new release 3.5, its new features and so I decided to update it by hand.

Below, you can find the update script that I programmed for that task.

After using it for some time, here I list the most interesting stuff about the new version.
  1. No problem with the lock-files any longer.
  2. Graphics stay in their sheets.
  3. Conditional formatting now lets you define more then three conditions, this was really necessary, I use that feature a lot. I'm just missing an easy way for reordering.
  4. Bigger text box for writing formulas.
  5. The import of Microsoft Visio files.
  6. The print preview of all pages.
  7. and lots more

Install instructions

Just save the following lines as InstallLibreOffice.sh and execute it with the -h parameter to see the usage text. You can also download it from here directly.
#! /bin/bash

#
## LibreOffice installation from Debian Packages from website
## @author Sven Rieke
# 

language=en-US
version="3.5.0"

function Usage() {
    cat <<EOF
Usage: ${0##*/} [-h] [-v] [-l lang-id] [p lang-id] [-d version-id] [-u]

  Options:
    -h             Show this help.
    -v             Be verbose about processing steps.
    -l lang-id     Set language for main installer and documentation (default = ${language})
    -p lang-id     Set language for interface translation (not installed by default)
    -d version-id  Specify another package version (default = ${version})
    -u             Start with a clean user-profile
 
EOF
}

function AndOut() {
    popd
    exit
}

trap AndOut ERR

########################################################################
# Interpretation and validation of command line parameters and options #
########################################################################

while getopts :hvl:d:u OPT; do
    case $OPT in
 h|+h) Usage ; exit 0     ;;
 v|+v) VERBOSE=true       ;;
 l|+l) language="$OPTARG" ;;
 p|+p) langpack="$OPTARG" ;;
 d|+d) version="$OPTARG"  ;;
 u|+u) NEWUSER=true       ;;
 *)    Usage
       exit 2
    esac
done

sudo -v

mkdir -p /tmp/LibO.3.5
pushd /tmp/LibO.3.5

#### Download from http://www.libreoffice.org/download/?type=deb-x86
[[ -v VERBOSE ]] && echo "---[ Installing LibreOffice ${version}-${language} ]" >&2
[[ -v VERBOSE ]] && echo "*** Downloading packages ***" >&2

for i in install helppack ; do
    package="LibO_3.5.0_Linux_x86_${i}-deb_${language}.tar.gz"

    if [ ! -f $package ]; then
 [[ -v VERBOSE ]] && echo "*** Downloading new package $package ***" >&2
 wget http://download.documentfoundation.org/libreoffice/stable/${version}/deb/x86/$package
    fi
done

if [ -v langpack ]; then
    package="LibO_3.5.0_Linux_x86_langpack-deb_${language}.tar.gz"
    if [ ! -f $package ]; then
 [[ -v VERBOSE ]] && echo "*** Downloading new package $package ***" >&2
 wget http://download.documentfoundation.org/libreoffice/stable/${version}/deb/x86/$package
    fi
fi

[[ -v VERBOSE ]] && echo "*** Decompressing downloaded archives ***" >&2
for t in LibO_3.5.0_*.tar.gz ; do tar xzf $t ; done

[[ -v VERBOSE ]] && echo "*** Removing old LibreOffice installation ***" >&2
sudo apt-get remove libreoffice-core

for d in $(find -maxdepth 1 -mindepth 1 -type d) ; do
    [[ -v VERBOSE ]] && echo "*** Install packages from $d ***" >&2    
    pushd $d/DEBS
    sudo dpkg -i *.deb

    if [ -d desktop-integration ]; then
 [[ -v VERBOSE ]] && echo "*** Install desktop integration ***" >&2
        cd desktop-integration
        sudo dpkg -i *.deb
        cd ..
    fi
    
    popd
done

if [ -v NEWUSER ]; then
    [[ -v VERBOSE ]] && echo "*** Remove old user profile ***" >&2
    mv ~/.config/libreoffice/3/user ~/.config/libreoffice/3/user_old
    [[ -v VERBOSE ]] && echo "*** Old one can be found in ~/.config/libreoffice/3/user_old ***" >&2
fi

AndOut

From repository

There also exists a repository which gets updated from time to time with the latest versions.
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt-get update
sudo apt-get upgrade

Troubleshooting

In two installations I had trouble with my old user profile. LibreOffice claimed about templates already installed. Therefore, I added the -u switch to my install script which moves the whole user profile to a backup location, so LibreOffice will start with a new profile. Just copy your old templates to the new profile and reapply all your settings again.

Customize boot and startup

Change screen resolution, colors and background image.
Some time ago, I recommended and used StartUp-Manager for tweaking the Grub boot loader and system loader, but this project isn't updated any longer. I found some very valid replacements which work even better.

Grub Customizer


With Grub Customizer you can tweak the new GRUB 2 boot screens, select the default boot entry, change the menu visibility and timeout, set kernel parameters, disable recovery entries.

Install instructions

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

Plymouth Manager

With Plymouth Manager you can change the startup animation, for example, put one which fits with your brand new Linux Mint.
sudo apt-add-repository ppa:mefrio-g/plymouthmanager
sudo apt-get update
sudo apt-get install plymouth-manager

Cinnamon Desktop

Cinnamon is a fork of the GNOME Shell, created by developers of the Linux Mint project.
It recovers the visual aspects of the old GNOME 2 desktops, but is more up-to-day, includes it's own visual effects and contains some details of GNOME 3.

Install instructions

If you are using Linux Mint, you can install Cinnamon directly from their repositories, but if you want to use the latest build and/or you want to install it in another system, use the following PPA repository.
sudo add-apt-repository ppa:merlwiz79/cinnamon-ppa
sudo apt-get update
sudo apt-get install cinnamon

# Install the weather extension
sudo apt-get install cinnamon-extension-weather

# Install some additional themes
sudo apt-get install git-core
cd /tmp && git clone https://github.com/linuxmint/cinnamon-themes.git
cd cinnamon-themes
./test

Troubleshooting

Not every software is perfect, and sometimes it could happen that your desktop manager gets frozen, for example a window gets paint and stays in the same place even if it's already closed.
There're several options to recover full control again:
  1. Use the Troubleshoot menu from the applet Better Cinnamon Settings which offers an entry Restart Cinnamon.
  2. Use Alt-F2 key combination to open Cinnamons internal command terminal and type 'r' followed by return.
  3. If you can't access the above two options (rare cases) you might want to restart Cinnamon from a terminal.
    • At this point, you might not even be able to open a terminal from the desktop, so you'll have to enter a system one with Ctrl-Alt-F1.
    • Make sure you know the display used by Cinnamon (normally it's 0, but you can verify it with 'w' command and the data in the FROM column:
      me~ $ w
       17:43:09 up 20:41,  6 users,  load average: 0.24, 0.23, 0.18
      USER   TTY      FROM             LOGIN@   IDLE   JCPU  PCPU   WHAT
      me     pts/0    :0.0             15:37    2:04m  0.24s 23.88s gnome-terminal
    • Export this value into the DISPLAY variable.
      export DISPLAY=:0.0
    • Finally, restart Cinnamon:
      cinnamon --replace
    • When you switch back to the desktop with Ctrl-Alt-F7 you should see an operative desktop after a while.
  4. The last option, if everything else fails, might be that it's not Cinnamon, but the underlying X system which is wrong, and you can reset this with Ctrl-Alt-Backspace.
    But this way, you'll have to login again into your session, which means, all open programs got closed.

Managing printers from CUPS web interface

Installed printers are listed here.
Recently, I had problems with my printer settings, I wanted to change the duplex setting and wanted to install a new network printer, but without success.
The problem I have is that in Linux Mint the Printers configuration applet fails, crashes and doesn't offer all options.

But finally I found a way. Linux Mint, like other distributions use the CUPS as printing system and it offers a web based administration interface.

Just point your web browser to http://localhost:631/. There you can add and manipulate all kind of printers and manage the print queues as well.

This is a nice workaround, until these options will be supported in the printer settings applet.