2012-04-03

Installer woes

I'm preparing to release v3.0 of my Multi-tail application Svansprogram. One popular feature request is native launchers. Yeah, OK, so this one guy asked for it but since there are about 3 people in the world using svansprogram that is a substantial part of the user base.
Being a Linux guy I have to jump through a lot of hoops to even begin to create a windows EXE-file or an OS X launcher. I can't even test them properly! Anyway, Launch4j seems nice and might even have some type of integration with maven (and I'm switching back to ant + ivy when I find the strength). There is a GUI and some XML files that you can use to work up an exe-file. The GIMP did let me create an ICO-file also. As soon as I can test this somewhere I might put in the hour or so to try this out.
A pal has promised to build an OS X launcher by using some sort of maven magic and an another launcher-creator-app-thingy.

So I tackled the Linux side. I decided to distribute an installer with the TAR-ball,
disclaimer - Blogger ate the formatting and yes I KNOW there are symlinks and stuff this does not handle, write a bug report or something :-)

And this people is why I LOVE linux: a few lines of BASH and here is your installer.


#! /bin/bash

SVANSPROGRAM_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LOG_FILE=$SVANSPROGRAM_HOME/install.log

log() {
echo "$1" >> $SVANSPROGRAM_HOME/install.log
}

log "`date`"
log "Svansprogram directory: ${SVANSPROGRAM_HOME}"

#######################################
# Create executable file #
#######################################
EXECUTABLE="$SVANSPROGRAM_HOME"/svansprogram.sh
log "Creating shell script: $EXECUTABLE"
cat <<MESSAGEDELIMITER > $EXECUTABLE
java -jar $SVANSPROGRAM_HOME/svansprogram.jar
MESSAGEDELIMITER

log "Setting execute permission"
chmod +x "$EXECUTABLE"

#######################################
# Create desktop file #
#######################################
INSTALL_DIR=~/.local/share/applications
log "Install directory: ${INSTALL_DIR}"


if [ ! -d "$INSTALL_DIR" ]; then
log "Install directory does not exist"
exit 1
fi

log "Creating desktop file"
cat <<MESSAGEDELIMITER > "$SVANSPROGRAM_HOME"/svansprogram.desktop
#!/usr/bin/env xdg-open

[Desktop Entry]
Version=3.0
Type=Application
Terminal=false
Exec=$EXECUTABLE
Name=Svansprogram
Comment=A Multi tail application
Icon=$SVANSPROGRAM_HOME/icon_128x128.png
Categories=Development
MESSAGEDELIMITER

log "Moving desktop file"
mv "$SVANSPROGRAM_HOME"/svansprogram.desktop "$INSTALL_DIR"