#!/bin/bash

# Script to install Firefox on GNU/Linux
# Created by kikee (kikee@mailoo.org)
# Licensed by GPL v.2
# --------------------------------------

# [Variables]

VERSION=23.0.1
# Version of Firefox to install.

LANGUAGE=es-ES
# Language to install, change to en-US for english.

ARCH=linux-i686
# Architecture of your system, change to "linux-x86_64" for 64-bit.

DOWNLOADER=wget
# You also use aria2c and axel to download.

SERVER=ftp://ftp.mozilla.org/pub/firefox/releases/$VERSION/$ARCH/$LANGUAGE/firefox-$VERSION.tar.bz2
# Server to use, alternative server: 
# http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$VERSION/$ARCH/$LANGUAGE/firefox-$VERSION.tar.bz2

# --------------------------------------

# [Download and install]

if [ $USER != root ]; then
  echo "Error: must be root"
  echo "Exiting..."
  exit 0
fi

 clear
 echo "This script will install the following:"
 echo ""
 echo "Package: Mozilla Firefox"
 echo "Version: $VERSION"
 echo "Language: $LANGUAGE"
 echo "Arch: $ARCH"
 echo ""
 echo "Downloader to use: $DOWNLOADER"
 echo ""
 echo -n "Is correct (y/n) " ; read var

 case $var in
 y)
   echo ""
   echo " <-Downloading Mozilla Firefox->"
   cd /tmp/
   $DOWNLOADER $SERVER
   echo " <-Installing Mozilla Firefox->"
   tar jxvf firefox-$VERSION.tar.bz2 -C /opt/
   rm -rf /usr/bin/firefox
   ln -s /opt/firefox/firefox /usr/bin/firefox
   chmod 777 -R /opt/firefox/

  echo "[Desktop Entry]" > /usr/share/applications/firefox.desktop
  echo "Encoding=UTF-8" >> /usr/share/applications/firefox.desktop
  echo "Name=Mozilla Firefox" >> /usr/share/applications/firefox.desktop
  echo "Comment=Browse the World Wide Web" >> /usr/share/applications/firefox.desktop
  echo "GenericName=Web Browser" >> /usr/share/applications/firefox.desktop
  echo "X-GNOME-FullName=Mozilla Firefox" >> /usr/share/applications/firefox.desktop
  echo "Exec=firefox %u" >> /usr/share/applications/firefox.desktop
  echo "Terminal=false" >> /usr/share/applications/firefox.desktop
  echo "X-MultipleArgs=false" >> /usr/share/applications/firefox.desktop
  echo "Type=Application" >> /usr/share/applications/firefox.desktop
  echo "Icon=/opt/firefox/browser/icons/mozicon128.png" >> /usr/share/applications/firefox.desktop
  echo "Categories=Network;WebBrowser;" >> /usr/share/applications/firefox.desktop
  echo "MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;" >> /usr/share/applications/firefox.desktop
  echo "StartupWMClass=Firefox-bin" >> /usr/share/applications/firefox.desktop
  echo "StartupNotify=true" >> /usr/share/applications/firefox.desktop
  rm -rf /tmp/firefox-$VERSION.tar.bz2
  echo " <-Finished->"
 ;;
 n)
  exit
 ;;
 *)
  exit
 esac