Autocafeijao

Publicado por Perfil removido (última atualização em 04/06/2011)

[ Hits: 5.024 ]

Download autocafeijao.tar.gz




Autocafeijao é um script para instalar os pacotes Java e NetBeans IDE.
Copyright © 2011 Cesar Augustus Silva
GNU GPL v.3

http://blog.cesar.augustus.nom.br/

  



Esconder código-fonte

#!/bin/bash

# Autocafeijao is a script to install Java packages and NetBeans IDE.
# Copyright (C) 2011 Cesar Augustus Silva
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

cmdname=$(basename $0)
pid=$$

license()
{
    echo "Autocafeijao  Copyright (C) 2011  Cesar A. Silva"
    echo "This program comes with ABSOLUTELY NO WARRANTY."
    echo "This is free software, and you are welcome to"
    echo "redistribute it under certain conditions."
    echo ""
}

usage()
{
    echo "Uso: ${cmdname} [OPÇÃO]..."
    echo "Baixa e instala os pacotes do Java (JDK) e NetBeans IDE"
    echo ""
    echo "  OPÇÕES:"
    echo ""
    echo "    -t tipo                 Define o tipo de exibição."
    echo "    --type tipo             (tipos: text e zenity)"
    echo ""
    echo "    -j endereço             Define o link do pacote Java (JDK). Usado em"
    echo "    --jdk endereço          diversas distr. exceto as que usa 'apt-get'"
    echo ""
    echo "    --no-check-conn         Não verifica se está conectado a internet"
    echo ""
    echo "    --no-install-jdk        Não baixa os pacotes do Java (JDK) para instalar."
    echo ""
    echo "    --no-install-netbeans   Não baixa o pacote NetBeans IDE para instalar."
    echo ""
    echo "  Exemplos:"
    echo ""
    echo "  Rodar no modo texto (terminal)"
    echo ""
    echo "    ${cmdname} -t text"
    echo ""
    echo "  Rodar com o zenity (caixa de diálogo)"
    echo ""
    echo "    ${cmdname} -t zenity"
    echo ""
    echo "Relatos de problemas e sugestões para <cesaraugustussilva@linuxmail.org>."
}

error_msg()
{
    if [ $view = "text" ]
    then
        echo -e "$1"
    else
        zenity $2 --text "$1"
        [ "$3" = "--kill" ] && kill -6 $pid
    fi
    exit 1
}

check_perm()
{
    [ $(whoami) != "root" ] && error_msg "Precisa de privilégios administrativos! \nExecute com o usuário root." --warning
}

check_conn()
{
    if [ $view = "text" ]
    then
        echo -n "Verificando a conexão..."
        ping -c3 www.google.com 1> /dev/null 2> /dev/null && echo "OK" || error_msg "ERRO\nPrecisa está conectado a internet! "
    else
        (
            echo "#Verificando a conexão"
            ping -c3 www.google.com 1> /dev/null 2> /dev/null || error_msg "Precisa está conectado a internet! " --warning --kill
        ) | zenity --progress --title "Aguarde" --pulsate --auto-close --auto-kill
    fi
}

check_dist()
{
    if [ ! -z $(which apt-get 2> /dev/null) ]
    then
        dist="debian"
    else
        if [ ! -z $(which yum 2> /dev/null) ]
        then
            dist="redhat"
        else
            dist="other"
        fi
    fi
}

check_jdk()
{
    if [ -z $jdk ]
    then
        if [ $dist = "redhat" ]
        then
            jdk="http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u23-linux-i586-rpm.bin?BundledLineItemUUID=PVeJ_hCvS0IAAAEtGrApHvbU&OrderID=1V6J_hCvLLcAAAEtArApHvbU&ProductID=QhOJ_hCw.dUAAAEsFIMcKluK&FileName=/jdk-6u23-linux-i586-rpm.bin"
        else
            jdk="http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u23-linux-i586.bin?BundledLineItemUUID=UwCJ_hCwbi8AAAEtSHgAHOh5&OrderID=RleJ_hCwX4cAAAEtOngAHOh5&ProductID=QhOJ_hCw.dUAAAEsFIMcKluK&FileName=/jdk-6u23-linux-i586.bin"
        fi
    fi
}

install_jdk()
{
    if [ -z $(which javac 2> /dev/null) ]
    then
        if [ $dist = "debian" ]
        then
            if [ $view = "text" ]
            then
                echo "Instalando o Java (JDK)"
                apt-get install -y sun-java6-jdk || error_msg "\nOs pacotes do Java (JDK) não estão disponíveis! Verifique se os repositórios necessários estão habilitados."
            else
                (
                    echo "#Baixando os pacotes do Java (JDK)"
                    apt-get install -d -y sun-java6-jdk || error_msg "Os pacotes do Java (JDK) não estão disponíveis! \nVerifique se os repositórios necessários estão habilitados." --error --kill
                ) | zenity --progress --title "Aguarde" --pulsate --auto-close --auto-kill
                xterm -T "Instalando o Java (JDK)" -e "apt-get install -y sun-java6-jdk"
            fi
        else
            if [ $dist = "redhat" ]
            then
                if [ $view = "text" ]
                then
                    if [ -z $(which wget 2> /dev/null) ]
                    then
                        echo "Instalando o wget"
                        yum install -y wget
                    fi
                    echo "Baixando os pacotes do Java (JDK)"
                    wget -c $jdk -O java-jdk-rpm.bin || error_msg "O link dos pacotes do Java (JDK) parece está quebrado! \nUse a opção '--jdk' para definir um novo link."
                    chmod +x java-jdk-rpm.bin
                    echo "Instalando o Java (JDK)"
                    ./java-jdk-rpm.bin
                else
                    (
                    echo "1"
                    echo "#Verificando os pacotes"
                    sleep 3s
                    if [ -z $(which wget 2> /dev/null) ]
                    then
                        echo "#Instalando o 'wget'"
                        yum install -y wget
                    fi
                    if [ -z $(which xterm 2> /dev/null) ]
                    then
                        echo "#Instalando o 'xterm'"
                        yum install -y xterm
                    fi
                    ) | zenity --progress --title "Aguarde" --pulsate --auto-close --auto-kill
                    (
                        echo "#Baixando os pacotes do Java (JDK)"
                        cat <(wget -c $jdk -O java-jdk-rpm.bin 2>&1 || error_msg "O link dos pacotes do Java (JDK) parece está quebrado! \nUse a opção '--jdk' para definir um novo link." --error --kill) | sed -u 's/.*\ \(.*\)\+%\ .*/\1/'
                    ) | zenity --progress --title "Aguarde" --percentage=0 --auto-close --auto-kill
                    chmod +x java-jdk-rpm.bin
                    xterm -T "Instalando o Java (JDK)" -e "./java-jdk-rpm.bin"
                fi
                rm -f sun-javadb-*.rpm
                rm -f jdk-*.rpm
            else
                if [ $view = "text" ]
                then
                    echo "Baixando os pacotes do Java (JDK)"
                    wget -c $jdk -O java-jdk.bin || error_msg "O link dos pacotes do Java (JDK) parece está quebrado! Use a opção '--jdk' para definir um novo link."
                    chmod +x java-jdk.bin
                    echo "Instalando o Java (JDK)..."
                    ./java-jdk.bin
                else
                    (
                        echo "#Baixando os pacotes do Java (JDK)"
                        cat <(wget -c $jdk -O java-jdk.bin 2>&1 || error_msg "O link dos pacotes do Java (JDK) parece está quebrado! \nUse a opção '--jdk' para definir um novo link." --error --kill) | sed -u 's/.*\ \(.*\)\+%\ .*/\1/'
                    ) | zenity --progress --title "Aguarde" --percentage=0 --auto-close --auto-kill
                    chmod +x java-jdk.bin
                    xterm -T "Instalando o Java (JDK)" -e "./java-jdk.bin"
                fi
                jdkdir=$(ls | grep jdk)
                mv $jdkdir /usr/lib/
                [ -L /usr/lib/java ] && rm /usr/lib/java
                ln -s /usr/lib/$jdkdir /usr/lib/java
                cat  > /etc/profile.d/java.sh <<- fim
#!/bin/sh
export JAVA_HOME=/usr/lib/java
export CLASSPATH=\$JAVA_HOME/lib
export MANPATH=\$MANPATH:\$JAVA_HOME/man
export PATH=\$PATH:\$JAVA_HOME/bin
fim
                chmod +x /etc/profile.d/java.sh
                . /etc/profile.d/java.sh
            fi
        fi
    else
        if [ $view = "text" ]
        then
            echo "O Java (JDK) já está instalado."
        else
            zenity --info --title "Informação" --text "O Java (JDK) já está instalado."
        fi
    fi
}

check_version()
{
    ver=( "" "6.9.1" "6.9" "6.8" "6.7.1" "6.7" "6.5.1" "6.5" "6.1" "6.0.1" "6.0" )
    versions="6.9.1\n6.9\n6.8\n6.7.1\n6.7\n6.5.1\n6.5\n6.1\n6.0.1\n6.0"
    op=0
    if [ $view = "text" ]
    then
        until [ $op -ge 1 -a $op -le 10 ]
        do
            echo "NetBeans IDE (Versões)"
            paste <(seq -w 10) <(echo -e "$versions") | sed 's/\t/ -- /'
            read op
        done
    else
        ver[0]=$(zenity --list --radiolist --title "Versão do NetBeans IDE" --text "Selecione a versão do NetBeans IDE:" --height "400" --column "Opção" --column "Versão" TRUE 6.9.1 $(echo -e $versions | grep -v '6.9.1' | xargs -n1 echo FALSE))
        [[ $? != 0 ]] && exit 0
    fi
}

install_netbeans()
{
    if [ ! -e /usr/local/netbeans-${ver[$op]}/bin/netbeans ]
    then
        url="http://dlc.sun.com.edgesuite.net/netbeans/${ver[$op]}/final/bundles/netbeans-${ver[$op]}-ml-javase-linux.sh"
        if [ $view = "text" ]
        then
            echo "Baixando o pacote NetBeans IDE ${ver[$op]}"
            wget -c $url || error_msg "\nO link do pacote NetBeans IDE ${ver[$op]} parece está\nquebrado ou você está desconectado a internet! "
        else
            (
                echo "#Baixando o pacote NetBeans IDE ${ver[$op]}"
                cat <(wget -c $url 2>&1 || error_msg "O link do pacote NetBeans IDE ${ver[$op]} parece está\nquebrado ou você está desconectado a internet! " --error --kill) | sed -u 's/.*\ \(.*\)\+%\ .*/\1/'
            ) | zenity --progress --title "Aguarde" --percentage=0 --auto-close --auto-kill
        fi
        chmod +x netbeans-${ver[$op]}-ml-javase-linux.sh
        ./netbeans-${ver[$op]}-ml-javase-linux.sh
    else
        error_msg "O NetBeans IDE ${ver[$op]} já está instalado." --info
    fi
}

while [ $# -gt 0 ]
do
    case $1 in
        -t | --type)
            if [ ! -z $2 ]
            then
                view=$2
                if [ $view = "text" ] || [ $view = "zenity" ]
                then
                   shift 2
                else
                    view="text" && error_msg "${cmdname}: valor inválido da opção '$1': $2"
               fi
            else
                view="text" && error_msg "${cmdname}: opção '$1' requer um argumento\nExperimente \"${cmdname} --help\" para mais informações."
            fi
            ;;
        -j | --jdk)
            if [ ! -z $2 ]
            then
                jdk=$2
                shift 2
            else
                view="text" && error_msg "${cmdname}: opção '$1' requer um argumento\nExperimente \"${cmdname} --help\" para mais informações."
            fi
            ;;
        --no-check-conn)
            checkconn="false"
            shift
            ;;
        --no-install-jdk)
            installjdk="false"
            shift
            ;;
        --no-install-netbeans)
            installnetbeans="false"
            shift
            ;;
        --help)
            usage
            exit 0
            ;;
        *)
            view="text" && error_msg "${cmdname}: opção não reconhecida '$1'\nExperimente \"${cmdname} --help\" para mais informações."
            ;;
    esac
done

if [ -z $view ]
then
    if [[ $(tty) = /dev/tty[1-6] ]] || [[ $(tty) = /dev/vc/[1-6] ]]
    then
        view="text"
    else
        if [ ! -z $(which zenity 2> /dev/null) ]
        then
            view="zenity"
        else
            view="text"
        fi
    fi
else
    if [ $view = "zenity" ]
    then
        if [[ $(tty) = /dev/tty[1-6] ]] || [[ $(tty) = /dev/vc/[1-6] ]]
        then
            view="text" && error_msg "${cmdname}: o modo '$view' não pode ser usada num console"
        else
            if [ -z $(which zenity 2> /dev/null) ]
            then
                view="text" && error_msg "Você não possui o comando 'zenity' instalado"
            fi
        fi
    fi
fi

license
check_perm
[ -z $checkconn ] && check_conn
check_dist
[ -z $installjdk ] && {
    check_jdk
    install_jdk
}
[ -z $installnetbeans ] && {
    check_version
    install_netbeans
}

exit 0

Scripts recomendados

Racha-cuca (jogo)

Prova 1.0

Sysinfo 2.01 - Infos do Sistema

Gerador de senhas aleatórias

Criar pacote Debian o firefox de br.mozdev.org


  

Comentários
[1] Comentário enviado por killerbean em 06/06/2011 - 16:27h

Interessante, mas em distros com gerenciador de pacotes o certo não seria adicionar os repositorios do desenvolvedor e instalar pelo gerenciador ?
...
e eu bem que gostaria de conhecer melhor shell-script.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts