Instalando a última versão estável do Eclipse com uma única linha

Publicado por William da Costa Canin (última atualização em 27/08/2015)

[ Hits: 2.512 ]

Homepage: https://williamcanin.github.io

Download eclipse.sh




Olá "linuxers", estou aqui para compartilhar com vocês um script (Shell) que criei para descarregar e instalar a SEMPRE a última versão do Eclipse estável, ou seja, o script tem a função de pegar o último codenome e a última release estável do Eclipse, por exemplo: Mars/R.

Resolvi criar esse script, porque o Eclipse é apenas extrair e usar no GNU/Linux, deixando sua "instalação" meio chocho (onde eu tirei essa palavra na minha mente?), sem um atalho em "/usr/share/applications", não cria link simbólico na pasta "bin", e ter aquele "trabalhinho" de ficar entrando no site do Eclipse, para baixar a última versão (caso não queira atualizar a versão que já possuí). Tudo bem, você pode fazer tudo isso manualmente, mas um script que faz isso com apenas uma linha de comando é bem melhor, seja qual for sua distribuição.

O script está armazenado no meu Gist do GitHub, e isso possibilita de utilizar uma única linha para fazer todo processo, através do cURL com opção "L".

Para fazer o download e instalação da última versão do Eclipse com uma única linha de comando, acesse o script no meu Gist (no final do texto) e na descrição do script, tem a forma de instalação utilizando o cURL e outros comentários.

Agora se quer realizar o download do script para rodar localmente, você pode, ele tem essa opção, irei disponibilizar aqui, mas logo aviso: "O SCRIPT PODE FICAR OBSOLETO AQUI", caso eu queira modificá-lo no Gist ou algum amigo dê dicas para modificá-lo, pois eu uso mais Gist.

Se você for baixar e usar o script localmente, você terá que alterar o parâmetro da função "_RUN_OPTION" para "local", assim você terá o menu de instalar (-install) e desinstalar (-uninstall) habilitado no script. Caso deixe como está, ao executar o script ele irá fazer o download e instalar automaticamente e não entrará no menu.

Nota: coloquei essa função "_RUN_OPTION" com opção de usar (ou não) menu do script, porque como o script está armazenado no Gist, o "curl -L" não aceita a utilização de menu. O script usa o "sudo" então seu usuário terá que estar no /etc/sudoers.

Gist do script (link encurtado): http://git.io/v3Fe9

Meu Gist: https://gist.github.com/williamcanin

  



Esconder código-fonte

#!/bin/bash

        # Type script: Shell
        # Program: Eclipse {Lastet version <present>}
        # Description: Installing the latest version of Eclipse on Linux,
        #              as shortcut creations and symbolic links
        # Version: 1.0.1
        #
        #--------------------------------------------------------------------------------------------
        # Author: William C. Canin <http://williamcanin.com, https://github.com/williamcanin>
        # LICENSE: MIT
        # The MIT License (MIT)
        # Copyright (c) 2015 William C. Canin
        #
        # Permission is hereby granted, free of charge, to any person obtaining a copy
        # of this software and associated documentation files (the "Software"), to deal
        # in the Software without restriction, including without limitation the rights
        # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        # copies of the Software, and to permit persons to whom the Software is
        # furnished to do so, subject to the following conditions:

        # The above copyright notice and this permission notice shall be included in all
        # copies or substantial portions of the Software.

        # 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 OR COPYRIGHT HOLDERS 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.
        #--------------------------------------------------------------------------------------------


#====================================================================================================
#   Begin Script
#====================================================================================================
#
#
# ---------------------------------------------------------------------------------------------------
#   Begin variables global
#----------------------------------------------------------------------------------------------------
#
############ Variables changeable
#
# Set the directory where Eclipse is installed.
INSTALLATION_DIR="/opt"
#---------------------------------------------
#
# ------------- BASE MIRRORS -----------------
# Choice base mirror {Only one}
#
# Base mirror - Brazil - C3SL - Federal University of Parana (http)
BASE_MIRROR="http://eclipse.c3sl.ufpr.br"
# Base mirror - United States - Columbia University
# BASE_MIRROR="http://mirror.cc.columbia.edu/pub/software/eclipse"
# Base mirror - Germany - University of Erlangen-Nuremberg
# BASE_MIRROR="http://ftp.fau.de/eclipse"
#
############ Variables NOT changeable
#
#
if [ "$(uname -m)" = "x86_64" ]; then

  ARCHITECTURE="x86_64"
  ARCHITECTURE_PI="x86_64"

else

  ARCHITECTURE=""
  ARCHITECTURE_PI="i386"

fi
DISTRIBUTION="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* 2> /dev/null | grep PRETTY_NAME | awk -F"=" '{print$2}')"
DOWN_ICON_SVG="https://raw.githubusercontent.com/williamcanin/logos/master/logos/eclipse.svg"
DIR_SHORTCUT="/usr/share/applications"
SHORTCUT_NAME="eclipse.desktop"
URL_RELEASE_CODENAME="$BASE_MIRROR/technology/epp/downloads/release/release.xml"
VERIFY_CODENAME="$(curl -s $URL_RELEASE_CODENAME | sed '/<present>/,$!d' | sed 's/<present>//g' | sed 's/<\/present>//g' | sed '/</d' | cut -d'/' -f1)"
VERIFY_CODENAME_CAPITALIZE="$(curl -s $URL_RELEASE_CODENAME | sed '/<present>/,$!d' | sed 's/<present>//g' | sed 's/<\/present>//g' | sed '/</d' | cut -d'/' -f1 | sed -r 's/(^.| .)/\U&/g')"
VERIFY_RELEASE="$(curl -s $URL_RELEASE_CODENAME | sed '/<present>/,$!d' | sed 's/<present>//g' | sed 's/<\/present>//g' | sed '/</d' | cut -d'/' -f2)"
BASE_URL_PKG="$BASE_MIRROR/technology/epp/downloads/release"
NAME_DEFAULT_ECLIPSE="eclipse-jee"
OS="linux"
CONFIG="config.lib"
LIB_MSGS="messages_color.lib"
PROGRESS_PERCENT_LIB="progress_percent.lib"
ACTION_SETTINGS_DIR="$HOME/.eclipse_confs"
ACTION_SETTINGS_FILE_INSTALL="action_settings_install.sh"
ACTION_SETTINGS_FILE_UNINSTALL="action_settings_uninstall.sh"
EXTENSION="tar.gz"
PKGNAME_FULL="$NAME_DEFAULT_ECLIPSE-$VERIFY_CODENAME-$VERIFY_RELEASE-$OS-gtk-$ARCHITECTURE.$EXTENSION"
FOLDER_ECLIPSE_DEFAULT="eclipse"
FOLDER_ECLIPSE_CHANGED="$INSTALLATION_DIR/$NAME_DEFAULT_ECLIPSE-$VERIFY_CODENAME-$VERIFY_RELEASE-$OS-gtk-$ARCHITECTURE"
EXEC="$FOLDER_ECLIPSE_CHANGED/eclipse"
LINK_SIMBOLIC_EXEC="/usr/bin/eclipse"
URLPKG="$BASE_URL_PKG/$VERIFY_CODENAME/$VERIFY_RELEASE/$NAME_DEFAULT_ECLIPSE-$VERIFY_CODENAME-$VERIFY_RELEASE-$OS-gtk-$ARCHITECTURE.$EXTENSION"
#
#
#----------------------------------------------------------------------------------------------------
#   End variables global
#----------------------------------------------------------------------------------------------------


#----------------------------------------------------------------------------------------------------
#   Begin functions
#----------------------------------------------------------------------------------------------------
#


function _CREATE_DIR_ACTION_SETTINGS(){

    if [[ ! -d "$ACTION_SETTINGS_DIR" ]]; then
        mkdir $ACTION_SETTINGS_DIR
    fi

}

function _RUN_OPTION(){

    if [[ "$1" = "gist" ]]; then
        _ACTION_SETTINGS

        _DOWNLOAD_INSTALL

    elif [[ "$1" = "local" ]]; then
        printf "\n"
        printf "Using: $0 { -install | -uninstall }\n"
        printf "\n"
    else
        printf "\n"
        printf "Option invalid!\n"
        printf "\n"
    fi
}

function _CREATE_LIBS(){

_CREATE_DIR_ACTION_SETTINGS

/bin/cat << EOF > $ACTION_SETTINGS_DIR/$LIB_MSGS
NONE='\033[00m'
RED='\033[01;31m'
BLUE='\e[34m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'

WARNING_MSG="\${YELLOW}[ Warning ]\${NONE}"
ERROR_MSG="\${RED}[ Error ]\${NONE}"
INFO_MSG="\${BLUE}[ Info ]\${NONE}"
OK_MSG="\${GREEN}[ Ok ]\${NONE}"
EOF

/bin/cat << EOF > $ACTION_SETTINGS_DIR/$CONFIG
DOWNLOAD_VALUE="uncompleted"
SUDO_VALUE_INSTALL="null"
SUDO_VALUE_UNINSTALL="null"
EOF

/bin/cat << EOF > $ACTION_SETTINGS_DIR/$PROGRESS_PERCENT_LIB
# Colors
NONE='\033[00m'
RED='\033[01;31m'
BLUE='\e[34m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
MOVE_CURSOR_LEFT4="\033[4D"

function _PROGRESS_PERCENT_FUNCTION(){

    BEGIN_PERCENT=\$1
    END_PERCENT=\$2
    SECONDS=\$3
    PROGRESS=\$END_PERCENT/\$SECONDS
    tput civis
    printf "\n"
    printf "\$4\n"
    for (( i=\$BEGIN_PERCENT; i<=\$END_PERCENT ; i=\$i+\$PROGRESS )); do
        printf "\${MOVE_CURSOR_LEFT4}\${YELLOW}\${BOLD}\$i\${NONE}"
        echo -ne "\${YELLOW}%\${NONE}"
        sleep 1
    done
    tput cnorm
    printf "\${MOVE_CURSOR_LEFT4}"
    printf "\${YELLOW}\$END_PERCENT%%\${NONE}"
    printf "\012\012"

}
EOF

}
_CREATE_LIBS


function _LOAD_LIBS_LOCAL(){

    if [[ -f "$ACTION_SETTINGS_DIR/$LIB_MSGS" ]]; then
        source $ACTION_SETTINGS_DIR/$LIB_MSGS
    fi
    if [[ -f "$ACTION_SETTINGS_DIR/$CONFIG" ]]; then
        source $ACTION_SETTINGS_DIR/$CONFIG
    fi
    if [[ -f "$ACTION_SETTINGS_DIR/$CONFIG" ]]; then
        source $ACTION_SETTINGS_DIR/$PROGRESS_PERCENT_LIB
    fi

}

function _CREATE_SHORTCUT(){

/bin/cat << EOF > $ACTION_SETTINGS_DIR/$SHORTCUT_NAME
[Desktop Entry]
Type=Application
Version=1.0
Name=Eclipse
GenericName=Eclipse-IDE-$VERIFY_CODENAME_CAPITALIZE
Comment[pt_BR]=IDE Desenvolvimento Java
Comment[en_GB]=IDE Java Development
Exec=$EXEC
Icon=$FOLDER_ECLIPSE_CHANGED/icon.svg
Terminal=false
Categories=GTK;Development;IDE;
StartupNotify=true
EOF

}

function _ACTION_SETTINGS(){

    _CREATE_DIR_ACTION_SETTINGS
    _CREATE_LIBS

}

function _PERMISSION_FOLDER_FILE_ECLIPSE(){

    if [[ "$INSTALLATION_DIR" = "$HOME" ]]; then
        if [[ ! -d "$FOLDER_ECLIPSE_CHANGED"  ]]; then
            exit 0
        else
            sudo chown -R `logname`. $FOLDER_ECLIPSE_CHANGED
            sudo chmod -R 777 $FOLDER_ECLIPSE_CHANGED
        fi
    fi

}

function _DOWNLOAD_INSTALL(){
    reset
    _LOAD_LIBS_LOCAL

    if [[ -d "$FOLDER_ECLIPSE_CHANGED" ]]; then

        printf "\n"
        printf "$WARNING_MSG The Eclipse $VERIFY_CODENAME_CAPITALIZE is already installed\n"
        printf "See where: "
        cd $FOLDER_ECLIPSE_CHANGED && pwd
        printf "\n"

    else

        for (( i = 0; i < 2; i++ )); do
            _LOAD_LIBS_LOCAL
            if [[ "$DOWNLOAD_VALUE" = "completed" ]]; then

                printf "\n"
                printf "============================================================\n"
                printf "    Installing Eclipse $VERIFY_CODENAME_CAPITALIZE in $INSTALLATION_DIR.\n"
                printf "============================================================\n"
                printf "\n"
                printf "You must be ${BLUE}ROOT${NONE} to perform the installation. You need sudo.\n"
                printf "\n\n"

                _CREATE_SHORTCUT
                _PROGRESS_PERCENT_FUNCTION "0" "20" "2" "Starting installation..."
                sudo -k
                sudo sed -i "s|^SUDO_VALUE_INSTALL=.*|SUDO_VALUE_INSTALL=\"true\"|g" $ACTION_SETTINGS_DIR/$CONFIG
                _LOAD_LIBS_LOCAL
                if [[ "$SUDO_VALUE_INSTALL" != "true"  ]]; then
                    printf "$ERROR_MSG Installation error because you canceled the sudo process or typed incorrect password.\n"
                    printf "Sorryy :(\n"
                    printf "\n"
                    exit 0
                else

                    sudo tar -xzf $HOME/$PKGNAME_FULL -C $INSTALLATION_DIR
                    sudo mv $INSTALLATION_DIR/$FOLDER_ECLIPSE_DEFAULT $FOLDER_ECLIPSE_CHANGED
                    sudo curl -so $FOLDER_ECLIPSE_CHANGED/icon.svg $DOWN_ICON_SVG
                    sudo chmod -R 755 $FOLDER_ECLIPSE_CHANGED
                    sudo ln -s $EXEC $LINK_SIMBOLIC_EXEC
                    sudo chmod +x $LINK_SIMBOLIC_EXEC
                    sudo mv $ACTION_SETTINGS_DIR/$SHORTCUT_NAME $DIR_SHORTCUT/$SHORTCUT_NAME
                    _PROGRESS_PERCENT_FUNCTION "21" "100" "4" "Finishing installation..."

                    printf "\n"
                    printf "$WARNING_MSG Complete install Eclipse $VERIFY_CODENAME_CAPITALIZE.\n"
                    printf "Bye! :)\n"
                    printf "\n"
                fi

                _PERMISSION_FOLDER_FILE_ECLIPSE

                _CLEAR
                break

            else
                printf "\n"
                printf "===================================\n"
                printf "    Process Information\n"
                printf "===================================\n"
                printf "\n"
                printf "${BLUE} Package:${NONE} $PKGNAME_FULL\n"
                printf "${BLUE} Download directory:${NONE} $BASE_URL_PKG\n"
                printf "${BLUE} Architecture:${NONE} $ARCHITECTURE_PI\n"
                printf "${BLUE} Maintainer:${NONE} The Eclipse Foundation\n"
                printf "${BLUE} Operational system:${NONE} $OS\n"
                printf "${BLUE} Distribution:${NONE} $DISTRIBUTION\n"
                printf "${BLUE}${BOLD} Download saving on:${NONE} $HOME\n"
                printf "\n"
                printf "\n"
                printf "===================================\n"
                printf "    Download Eclipse $VERIFY_CODENAME_CAPITALIZE.\n"
                printf "===================================\n"
                printf "$WARNING_MSG Wait ...\n"
                printf "\n"
                curl -C - -o $HOME/$PKGNAME_FULL $URLPKG
                sed -i "s|^DOWNLOAD_VALUE=.*|DOWNLOAD_VALUE=\"completed\"|g" $ACTION_SETTINGS_DIR/$CONFIG

            fi

        done
    fi
}

function _CLEAR(){
    # rm -f  $HOME/$PKGNAME_FULL
    rm -rf $ACTION_SETTINGS_DIR
    sudo -k
}

function _UNINSTALL(){
    reset
    _LOAD_LIBS_LOCAL

    if [[ ! -d "$FOLDER_ECLIPSE_CHANGED" ]]; then
        printf "\n"
        printf "$WARNING_MSG The Eclipse is not installed.\n"
        printf "It was not installed with this script.\n"
        printf "\n"

    else

        printf "\n"
        printf "============================================================\n"
        printf "    Uninstall Eclipse $VERIFY_CODENAME_CAPITALIZE.\n"
        printf "============================================================\n"
        printf "\n"
        printf "$INFO_MSG This will be an irreversible action! You need sudo.\n"
        printf "\n"

                sudo -k
                sudo sed -i "s|^SUDO_VALUE_UNINSTALL=.*|SUDO_VALUE_UNINSTALL=\"true\"|g" $ACTION_SETTINGS_DIR/$CONFIG
                _LOAD_LIBS_LOCAL
                if [[ "$SUDO_VALUE_UNINSTALL" != "true" ]]; then
                    printf "\n"
                    printf "$ERROR_MSG Uninstall error because you canceled the sudo process or typed incorrect password.\n"
                    printf "Sorry :(\n"
                    printf "\n"
                    exit 0
                else
                    sudo rm -rf  $FOLDER_ECLIPSE_CHANGED
                    sudo rm -f  $LINK_SIMBOLIC_EXEC
                    sudo rm -f  $DIR_SHORTCUT/$SHORTCUT_NAME
                    _PROGRESS_PERCENT_FUNCTION "0" "100" "2" "Uninstall process: "
                    printf "\n"
                    printf "$WARNING_MSG Complete uninstall Eclipse $VERIFY_CODENAME_CAPITALIZE.\n"
                    printf "Bye! :)\n"
                    printf "\n"
                fi

    _CLEAR
    fi


}
#
#----------------------------------------------------------------------------------------------------
#   End functions
#----------------------------------------------------------------------------------------------------


case "$1" in
      -uninstall)

        _ACTION_SETTINGS

        _UNINSTALL
      ;;
      -install)

        _ACTION_SETTINGS

        _DOWNLOAD_INSTALL
      ;;
      *)

        #-----------------------------------------------------------------------
        # Configuration script to run locally
        #-----------------------------------------------------------------------
        #
        # Use the parameter "local" if you want to use this script locally.
        # The advantage of using locally is that you can use the option to
        # install and uninstall.
        #
        #-----------------------------------------------------------------------
        # Configuration to run script via web "Gist" (Curl -L)
        #-----------------------------------------------------------------------
        #
        # Use the parameter "gist" if you want to use this script by Gist.
        # This option will not download the script, however, only porerá
        # use the option to install. The option to uninstall is not available.
        #
        #-----------------------------------------------------------------------
        #
        _RUN_OPTION "gist"


      ;;
esac
#
#
#----------------------------------------------------------------------------------------------------
#   End Script  -   Copyright (c) Script 2015 - William C. Canin <http://github.com/williamcanin>
#====================================================================================================

Scripts recomendados

Busca de arquivos nas ports FreeBSD

SlackelsPKG 1.0 - uma réplica de gerenciador de pacotes para o Slackware Current

Compartilhando a Internet com Iptables

Script de backup para Gravador CD-R ou CD-Rw

Remover kernels antigos com zenity


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts