#!/bin/sh

# This script will install Microsoft Freecell in Ubuntu
# This script needs to be run as root and have 755 permission
# WINE emulator must be installed for Microsoft Freecell to function
#
# Authored by Bob Nelson  admin@stchman.com
#

script_name="msfreecell.sh"

# Script must run as root 
if [ $USER != "root" ]; then
	echo "You need to run this script as root."
	echo "Use 'sudo ./$script_name' then enter your password when prompted."
	exit 1
fi

# This script will install to the users home folder
# change to the users home folder
cd ~

# download the .tar.gz archive from www.stchman.com
wget http://www.stchman.com/tools/msfreecell/msfreecell.tar.gz

# unzip the archive from the users home folder in the newly created folder
sudo tar -C /opt -zxvf ~/msfreecell.tar.gz

# Create symbolic link to the /usr/bin folder
sudo ln -s /opt/msfreecell/msfreecell /usr/bin/msfreecell

# make menu entry in Application-->Games
# script will do this by creating a msfreecell.desktop text file
# the > creates the file while >> appends to the file
sudo echo "[Desktop Entry]" > /usr/share/applications/msfreecell.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/msfreecell.desktop
sudo echo "Name=Microsoft Freecell" >> /usr/share/applications/msfreecell.desktop
sudo echo "Comment=Play Microsoft Freecell" >> /usr/share/applications/msfreecell.desktop
sudo echo "Categories=GNOME;GTK;Game;CardGame;" >> /usr/share/applications/msfreecell.desktop
sudo echo "Exec=msfreecell" >> /usr/share/applications/msfreecell.desktop
sudo echo "Icon=/opt/msfreecell/msfreecell_icon.png" >> /usr/share/applications/msfreecell.desktop
sudo echo "Terminal=false" >> /usr/share/applications/msfreecell.desktop
sudo echo "Type=Application" >> /usr/share/applications/msfreecell.desktop

# remove the .zip archive as it is no longer needed
rm -f ~/msfreecell.tar.gz


