Enviado em 29/07/2017 - 22:39h
Olá, boa noite.#!/bin/bash
# Script by Patrick Costa da Silva
# Vars
callifirefox=0
callijava=0
pwdscript=$PWD
# Functions
validroot(){
if [ $UID != 0 ]; then
msgrootpriv #Message Function
exit
fi
}
ijava() {
if mkdir /opt/java &> /dev/null || test -d /opt/java ; then
cd /opt/java
if ! tar -xvf "$javatar" >> temp.txt ; then
msgtarfail $javatar #Message Function
return 1
fi
fjava=$(head -n1 temp.txt | sed "s/\///")
rm temp.txt
if ! ./$fjava/bin/java -version ; then # Test if the binary works
msgrunfail "/opt/java/$fjava/bin/java" #Message Function
return 1
fi
if ! ln -sf /opt/java/$fjava/lib/*/libnpjp2.so /usr/lib/mozilla/plugins/libnpjp2.$(./$fjava/bin/java -version 2>&1 | grep "version" | sed "s/java version //;s/\"//g").so &> /dev/null ; then
msgunsymlink '"/usr/lib/mozilla/plugins/"' #Message Function
return 1
fi
else
msgundir '"/opt/java"' #Message Function
return 1
fi
}
ifirefox() {
if mkdir /opt/firefox &> /dev/null || test -d /opt/firefox ; then
cd /opt/firefox
if ! tar -xvf "$firefoxtar" >> temp.txt ; then
msgtarfail $firefoxtar #Message Function
return 1
fi
ffirefox=$(head -n1 temp.txt)
rm temp.txt
if ! /opt/firefox/$ffirefox/firefox -V ; then # Test if the binary works
msgrunfail "/opt/firefox/$ffirefox/firefox" #Message Function
return 1
fi
vfirefox=$(/opt/firefox/$ffirefox/firefox -V | cut -d" " -f3)
mv /opt/firefox/$ffirefox /opt/firefox/Firefox$vfirefox
if [ -f /usr/share/applications/firefox.desktop ] ; then # Check the gnome launcher and tune it.
sed -i "s/Actions=.*/&Firefox$vfirefox\;/" /usr/share/applications/firefox.desktop
echo -e "\n[Desktop Action Firefox$vfirefox]\nName=Firefox$vfirefox\nExec=/opt/firefox/Firefox$vfirefox/firefox" >> /usr/share/applications/firefox.desktop
fi
else
msgundir '"/opt/firefox"' #Message Function
return 1
fi
}
## Messages functions
msgsyntaxerror() {
echo $LANG | grep pt_BR > /dev/null && echo "Erro de sintaxe. Use $0 -h para obter ajuda." && return
echo "Syntax error. Use $0 -h for help."; return
}
msghelp() {
echo $LANG | grep pt_BR > /dev/null && echo "Aqui está sua ajuda"
echo $LANG | grep pt_BR > /dev/null && echo "-f | --firefox caminho/para/arquivo.tar Instala o firefox usando o arquivo informado"
echo $LANG | grep pt_BR > /dev/null && echo "-j | --java caminho/para/arquivo.tar Instala o java usando o arquivo informado"
echo $LANG | grep pt_BR > /dev/null && echo "-J | --download-java | -F | --download-firefox Abre seu navegador padrão na página de download do Java ou Firefox"
echo $LANG | grep pt_BR > /dev/null && echo -e "\nExemplos\n"
echo $LANG | grep pt_BR > /dev/null && echo "$0 -f $HOME/Download/firefox.tar.bz2 -j Download/jre-8u141-linux-i586.tar.gz" && return
echo "Here is your help..."
echo "-f | --firefox path/to/file.tar Install firefox using the given file"
echo "-j | --java path/to/file.tar Install java using the given file"
echo "-J | --download-java | -F | --download-firefox Open your default browser at the download page of Java or Firefox"
echo -e "\nExamples\n"
echo "$0 -f $HOME/Download/firefox.tar.bz2 -j Download/jre-8u141-linux-i586.tar.gz"
}
msgunsymlink() {
echo $LANG | grep pt_BR > /dev/null && echo "Nao foi possivel criar um link simbolico em $@" && return
echo "Unable to create a symlink at $@"
}
msgundir() {
echo $LANG | grep pt_BR > /dev/null && echo "Nao foi possivel criar um diretorio em $@" && return
echo "Unable to create a directory at $@"
}
msgrootpriv() {
echo $LANG | grep pt_BR > /dev/null && echo "Você precisa de privilégios de root para executar esse script" && return
echo "You need root privileges to run this script"
}
msgsuccess() {
echo $LANG | grep pt_BR > /dev/null && echo "$1 - instalado com sucesso!" && return
echo "$1 - successfully installed!"
}
msgfailure() {
echo $LANG | grep pt_BR > /dev/null && echo "$1 - falha na instalação!" && return
echo "$1 - installation failure!"
}
msgfnexist() {
echo $LANG | grep pt_BR > /dev/null && echo "$1 - Não foi possível acessar esse arquivo" && return
echo "$1 - Can't reach that file"
}
msgtarfail() {
echo $LANG | grep pt_BR > /dev/null && echo "Tar falho ao tentar descompactar $1" && return
echo "Tar has failed to uncompress the $1"
}
msgrunfail() {
echo $LANG | grep pt_BR > /dev/null && echo "Falha ao tentar executar o binário $1" && return
echo "Fail while trying to run the exec $1"
}
###############
### MAIN
###############
if [ $# -ne 1 -a $# -ne 2 -a $# -ne 4 ]; then
msgsyntaxerror #Message Function
exit 1
fi
while true; do
[ $# -eq 0 ] && break
case $1 in
-f|--firefox)
validroot #Function
echo $2 | grep -e "^/" > /dev/null && firefoxtar=$2 || firefoxtar="$pwdscript/$2" #Absolute or relativ path
if test -r "$firefoxtar" ; then
callifirefox=1 # to do list
shift 2
else
msgfnexist $firefoxtar; exit #Message Function
fi
;;
-F|--download-firefox)
browse https://ftp.mozilla.org/pub/firefox/releases/ &
shift 1
;;
-j|--java)
validroot #Function
echo $2 | grep -e "^/" > /dev/null && javatar=$2 || javatar="$pwdscript/$2" # Absolute or relative path
if test -r "$javatar" ; then
callijava=1 # to do list
shift 2
else
msgfnexist $javatar; exit #Message Function
fi
;;
-J|--download-java)
browse http://www.oracle.com/technetwork/java/archive-139210.html &
shift 1
;;
-h|--help)
msghelp #Message Function
exit
;;
*)
msgsyntaxerror #Message Function
exit 1
;;
esac
done
# to do list
if [ $callifirefox = 1 ]; then
ifirefox && msgsuccess firefox || msgfailure firefox
fi
if [ $callijava = 1 ]; then
ijava && msgsuccess java || msgfailure java
fi