#!/bin/sh

filetype="`echo $1 | sed 's,.*\.,,g;s,.*,\L&,g'`"
ICON="/usr/share/icons/gnome/48x48/apps/gnome-settings-default-applications.png"

if [ -s $filetype ]
then
echo "Usage: ubuntu-common-hooker file.ext"
echo "Supported files are MPG, MOV, MP3, AAC, M4A, ZIP, ARJ, RAR, ACE, CHM, CBR, CBZ, WMA, RAM, RM"
fi

if [ "$filetype" = "chm" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing CHM Compiled Help Application" --text $"Installing needed applications to view CHM files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install xchm" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of Compiled Help Application for CHM files finished!"
xchm "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "cbr" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing CBR Comics Application" --text $"Installing needed applications to view CBR files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install unrar comix" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of Comics appliction for CBR files finished!"
comix "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "cbz" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing CBZ Comics Application" --text $"Installing needed applications to view CBZ files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install unzip comix" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of Comics appliction for CBZ files finished!"
comix "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "ace" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing ACE de-compression support" --text $"Installing needed package to view ACE files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install unace" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of de-compression support for ACE files finished!"
file-roller "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "mov" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing MOV Quicktime Movie Codecs" --text $"Installing needed codecs to view MOV files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-bad" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for MOV files finished!"
totem "$1" && kill -s 9 $PID 2> /dev/null 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null 2> /dev/null
fi
)
fi

if [ "$filetype" = "ram" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing RAM Real Media Codecs" --text $"Installing needed codecs to view RAM files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-ugly" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for RAM files finished!"
totem "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "rm" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker ram | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing RM Real Media Codecs" --text $"Installing needed codecs to view RM files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-ugly" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for RM files finished!"
totem "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "zip" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing ZIP compression/decompression support" --text $"Installing needed package to view ZIP files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install zip unzip" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of compression/decompression support for ZIP files finished!"
file-roller "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "rar" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing RAR compression/decompression support" --text $"Installing needed package to view and create RAR files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install rar unrar" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of compression/decompression support for RAR files finished!"
file-roller "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "arj" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing ARJ compression/decompression support" --text $"Installing needed package to view and create ARJ files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install arj" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of compression/decompression support for ARJ files finished!"
file-roller "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "wma" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing WMA Windows Media Audio Codecs" --text $"Installing needed codecs to view WMA files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-ffmpeg" && kill -s 9 $ZENITY_PID 2> /dev/null
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for WMA files finished!"
rhythmbox "$1" && kill -s 9 $PID 2> /dev/null
else
  kill -s 9 $PID 2> /dev/null
  kill -s 9 $ZENITY_PID 2> /dev/null
fi
)
fi

if [ "$filetype" = "aac" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing AAC Apple iTunes Audio Codecs" --text $"Installing needed codecs to view AAC files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-bad-multiverse" && kill -s 9 $ZENITY_PID
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for AAC files finished!"
rhythmbox "$1" && kill -s 9 $PID
else
  kill -s 9 $PID
  kill -s 9 $ZENITY_PID
fi
)
fi

if [ "$filetype" = "m4a" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing M4A Apple iTunes Lossless Audio Codecs" --text $"Installing needed codecs to view M4A files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-bad-multiverse" && kill -s 9 $ZENITY_PID
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for M4A files finished!"
rhythmbox "$1" && kill -s 9 $PID
else
  kill -s 9 $PID
  kill -s 9 $ZENITY_PID
fi
)
fi

if [ "$filetype" = "mpg" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing MPG Mpeg Video Codecs" --text $"Installing needed codecs to view MPG files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-ffmpeg" && kill -s 9 $ZENITY_PID
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for MPG files finished!"
totem "$1" && kill -s 9 $PID
else
  kill -s 9 $PID
  kill -s 9 $ZENITY_PID
fi
)
fi

if [ "$filetype" = "mp3" ] 
then
/usr/lib/ubuntu-common-hooker/common-hooker $filetype | (
PID="$!"
read action
  if [ ! "$action" = "Exit_Signal" ]
    then
zenity --info --window-icon="$ICON"  --text "Please enable your universe/multiverse repository to continue"
gksudo software-properties
zenity --progress --pulsate --window-icon="$ICON"  --title "Installing MP3 Mpeg Layer-3 Audio Codecs" --text $"Installing needed codecs to view MP3 files" & 
ZENITY_PID="$!"	
gksudo "apt-get -y install gstreamer0.10-plugins-ugly" && kill -s 9 $ZENITY_PID
zenity --info --window-icon="$ICON"  --title "Installation Successful!" --text "Installation of codecs for MP3 files finished!"
rhythmbox "$1" && kill -s 9 $PID
else
  kill -s 9 $PID
  kill -s 9 $ZENITY_PID
fi
)
fi

if [ "$2" = "evil" ]
then
zenity --info --window-icon="$ICON"  --text "Converting to Oggish!!"
if [ ! -s /usr/bin/ffmpeg2theora ]
then
wget http://v2v.cc/~j/ffmpeg2theora/ffmpeg2theora-0.16.linux.bin.bz2 -O /tmp/ffmpeg2theora.bz2
bzip2 -d /tmp/ffmpeg2theora.bz2
gksudo "mv /tmp/ffmpeg2theora /usr/bin/ffmpeg2theora"
gksudo "chmod a+x /usr/bin/ffmpeg2theora"
fi
ffmpeg2theora "$1"
fi
