Skip to content

Instantly share code, notes, and snippets.

@nmussy
Created July 25, 2013 19:52
Show Gist options
  • Save nmussy/6083148 to your computer and use it in GitHub Desktop.
Save nmussy/6083148 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to [http://unlicense.org]
#
# Contact:
# Martin "Zironid" (Programmer): zironid@lavabit.com
# David "dfas98" (Translator): dfas98@gmail.com
#
# We have no relationship with Firefox(mozilla.org/firefox) or Mozilla(mozilla.org).
ROOT_UID=0
len=$(echo $LANG | cut -d '_' -f 1)
arq=$(getconf LONG_BIT)
code=(ach af sq ar hy-AM as ast eu be bn-BD bs br bg ca zh-CN zh-TW hr cs da nl en-GB en-ZA en-US eo et fi fr fy-NL ff gd gl de el gu-IN he hi-IN hu is id ga-IE it ja kn csb kk km ko lv lij lt mk mai ml mr nso nb-NO nn-NO or fa pl pt-BR pt-PT pa-IN ro rm ru sr si sk sl son es-AR es-CL es-MX es-ES sv-SE ta te th tr uk vi cy zu)
name=(Acholi Afrikaans Albanian Arabic Armenian\ (Հայերեն) Assamese Asturian Basque Belarusian Bengali\ (Bangladesh) Bosnian Breton Bulgarian Catalan Chinese\ (Simplified) Chinese\ (Traditional) Croatian Czech Danish Dutch English\ (British) English\ (South\ African) English\ (US) Esperanto Estonian Finnish French Frisian\ (Frysk) Fulah\ (Pulaar-Fulfulde) Gaelic Galician German Greek Gujarati\ (ગુજરાતી) Hebrew Hindi\ (India) Hungarian Icelandic Indonesian Irish\ (Gaeilge) Italian Japanese Kannada Kashubian Kazakh Khmer Korean Latvian Ligurian Lithuanian Macedonian Maithili Malayalam Marathi Northern\ Sotho Norwegian\ (Bokmål) Norwegian\ (Nynorsk) Oriya Persian Polish Portuguese\ (Brazilian) Portuguese\ (Portugal) Punjabi\ (ਪੰਜਾਬੀ) Romanian Romansh Russian Serbian Sinhala Slovak Slovenian Songhai Spanish\ (Argentina) Spanish\ (Chile) Spanish\ (Mexico) Spanish\ (Spain) Swedish\ (Svenska) Tamil Telugu Thai Turkish Ukrainian Vietnamese Welsh Zulu)
clear
echo "Hallo! And welcome to Firefox Installer, a script designed to make the Firefox installation easier on Debian."
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "To run this script you must run it like super user (root)."
sleep 5
exit
else
echo "Remember that just root can run this script."
fi
read -p "Firefox installer will create the folder .firefox-installer in $HOME. This is ok? (yes/no) : " resd
case $resd in
[Yy]* ) cwd=$HOME;;
* ) read -p "Do you want to introduce the directory manually? (yes/no) : " resdd
case $resdd in
[Yy]* ) read -p "Directory: (Example: /home/foo) :" cwd;;
* ) echo "Exiting from the script..."
exit;;
esac
esac
if [ $(ls -a $cwd | grep ".firefox-installer" | wc -l) == 1 ]
then
read -p "the directory $cwd/.firefox-installer alredy exist, do you want to delete it to continue? (yes/no) :" resb
case $resb in
[Yy]* ) echo "$cwd/.firefox-installer deleted.";;
* ) echo "Exiting from the script..."
exit;;
esac
rm -rf $cwd/.firefox-installer
fi
mkdir $cwd/.firefox-installer
echo "Directory $cwd/.firefox-installer created."
cd $cwd/.firefox-installer
echo "System information:"
echo "Language: $len"
echo "Architecture: $arq ($arqd)"
if [ "$len" == "en" ]; then
len=en-US
elif [ "$len" == "es" ]; then
len=es-ES
else
len=$len
fi
read -p "Is this ok? (yes/no) : " res
case $res in
[Yy]* ) echo "So, let's continue.";;
* )
echo "Please, introduce the information manually:"
#${string^^}
#${string,,}
while true
do
read -p "Select a language (en-US/es-ES/fr/it), type help for a list of all the available languages: " len
if [ "$len" == "help" -o "$len" == "?" ]; then
for index in ${!name[@]}; do
echo "$name[$index]: $code[$index]"
done
continue
fi
isAvailable = isAvailableLanguage len
if [ "$isAvailable" -eq "1" ]; then
name = getNameFromCode len
echo "You selected $name"
break
elif [ "$isAvailable" -eq "2" ]; then
if [ "$len" == "es" ]; then
read -p "Select a region (US/GB/ZA) : " reg
elif [ "$len" == "en" ]; then
read -p "Select a region (US/GB/ZA) : " reg
elif [ "$len" == "pt"]; then
read -p "Select a region (US/GB/ZA) : " reg
else
# zh
read -p "Select a region (US/GB/ZA) : " reg
fi
elif [ "$isAvailable" -eq "0" ]; then
echo "This language isn't supported by Firefox"
else
read -p "Did you mean (yes/no) : " cor
if [ $cor ]
break
fi
continue
fi
done
isAvailable = isAvailableLanguage len
if []
case $len in
[Ee][Nn] ) len=en
read -p "Select a region (US/GB/ZA) : " reg
case $reg in
[Uu][Ss] ) len
[Gg][Bb]
[Zz][Aa]
;;
[Ee][Ss]* ) len=es-ES ;;
[Ff][Rr]* ) len=fr ;;
[Ii][Tt]* ) len=it ;;
[Dd][Ee]* ) len=de ;;
* ) read -p "Language not suported by the script. Do you want to use the English version? (yes/no) : " resi
case $resd in
[Yy]* ) len=en;;
* ) echo "Exiting from the script..."
exit;;
esac
esac
read -p "Architecture (32/64) : " arq
case $arq in
3* ) arq=32
arqd=i686 ;;
6* ) arq=64
arqd=x86_64 ;;
* ) echo "Unknown architecture. We are going to use the 32 bit version for security."
arq=32
arqd=i686 ;;
esac
esac
if [ "$arqd" == i*86 ]
then
arqd=i686
fi
echo "Starting download..."
wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-$arqd/$len/firefox-*.tar.bz2
archi=$(ls | grep firefox-*.tar.bz2)
echo "Extracting $archi..."
tar -jxf firefox-*.tar.bz2
echo "Starting instalation..."
echo "Copying \"firefox\" to /opt..."
cp -rf firefox /opt
echo "Creating the symbolic link in /usr/bin..."
if [ $(ls /usr/bin | grep firefox | wc -l) == 1 ]
then
rm /usr/bin/firefox
fi
ln -s /opt/firefox/firefox /usr/bin/firefox
cp /opt/firefox/browser/icons/mozicon128.png /usr/share/pixmaps/firefox.png
echo "Adding Firefox to menu"
touch /usr/share/applications/firefox.desktop
echo -e "\n[Desktop Entry]\nName=Mozilla Firefox\nComment=Firefox-Browser\nExec=/usr/bin/firefox\nIcon=/usr/share/pixmaps/firefox.png\nTerminal=false" > /usr/share/applications/firefox.desktop
echo -e "Type=Application\nCategories=Network;\nStartupNotify=false;\nName[en_US]=Mozilla Firefox" >> /usr/share/applications/firefox.desktop
update-menus
echo "Installation finished."
function isAvailableLanguage() {
aliasedLanguages=(hy bn fy gu hi ga nb nn pt pa sv)
equivalentLanguage=(hy-AM bn-BD fy-NL gu-IN hi-IN ga-IE nb-NO nn-NO pt-PT pa-IN sv-SE)
regionedLanguages=(zh en pt es)
for value in ${code[@]}; do
if [ "$value" == "$1" ]; then
return 1
fi
done
for index in ${!aliasedLanguages[@]}; do
if [ "$index" == "$1" ]; then
return "$aliasedLanguages[$index]"
fi
done
for value in ${regionedLanguages[@]}; do
if [ "$value" == "$1" ]; then
return 2
fi
done
return 0
}
function getNameFromCode() {
for index in ${!code[@]}; do
if [ "$code[$index]" == "$1" ]; then
return $name["$index"]
fi
done
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment