CentOS의 biz라는 계정에 java 관련 프로그램(java, tomcat, maven, etc) 설치하는 간단한 bash 쉘 스크립트(install.sh)

해당 내용으로 쉘 파일을 만들고 사용 (디렉토리 먼저 생성 필요)
ex)  install.sh dir 후에 install.sh java

#!/bin/sh

#Enter user account
USER=biz


check_user()
{

    if [ $USER != `/usr/bin/whoami` ] ; then
        echo "=== Error. User is not $USER"
        exit -1;
    fi
}

make_dir()
{   
    echo "=== Install default directory : Start"

    mkdir ~/apps ~/deploy ~/scripts ~/logs ~/logs/nginx ~/src

    echo "=== Install default directory : End"

}

install_java()
{   
    echo "=== Install java : Start"

     #wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz" -O ~/apps/jdk-8u131-linux-x64.tar.gz   
     #tar -xzf ~/apps/jdk-8u131-linux-x64.tar.gz -C ~/apps && rm ~/apps/jdk-8u131-linux-x64.tar.gz && ln -s ~/apps/jdk1.8.0_131 ~/apps/jdk

     wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz" -O ~/apps/jdk-8u144-linux-x64.tar.gz
     tar -xzf ~/apps/jdk-8u144-linux-x64.tar.gz -C ~/apps && rm ~/apps/jdk-8u144-linux-x64.tar.gz && ln -s ~/apps/jdk1.8.0_144 ~/apps/jdk
     

    
    #JAVA DNS TTL Modify
    echo 'networkaddress.cache.ttl=60' >> ~/apps/jdk/jre/lib/security/java.security

    #set java path
    echo 'export JAVA_HOME=~/apps/jdk' >> ~/.bashrc
    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc

    #print java version
    java -version

    echo "=== Install java : End"

}

install_maven()
{   
    echo "=== Install maven : Start"

    wget "http://mirror.navercorp.com/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz" -O ~/apps/apache-maven-3.3.9-bin.tar.gz
    tar -xzf ~/apps/apache-maven-3.3.9-bin.tar.gz -C ~/apps && rm ~/apps/apache-maven-3.3.9-bin.tar.gz && ln -s ~/apps/apache-maven-3.3.9 ~/apps/maven

    #set maven path
    echo 'export M2_HOME=~/apps/maven' >> ~/.bashrc
    echo 'export PATH=$PATH:$M2_HOME/bin' >> ~/.bashrc
    source ~/.bashrc

    #print maven version
    mvn -version

    echo "=== Install maven : End"
}

install_tomcat()
{   
    echo "=== Install tomcat : Start"

    #wget 'http://mirror.apache-kr.org/tomcat/tomcat-8/v8.0.43/bin/apache-tomcat-8.0.43.tar.gz' -O ~/apps/apache-tomcat-8.0.43.tar.gz
    #tar -xzf ~/apps/apache-tomcat-8.0.43.tar.gz -C ~/apps && rm ~/apps/apache-tomcat-8.0.43.tar.gz

     wget 'http://mirror.apache-kr.org/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz' -O ~/apps/apache-tomcat-8.0.45.tar.gz
     tar -xzf ~/apps/apache-tomcat-8.0.45.tar.gz -C ~/apps && rm ~/apps/apache-tomcat-8.0.45.tar.gz


    #remove default tomcat webapps
    #rm -rf ~/apps/apache-tomcat-8.0.43/webapps && mkdir ~/apps/apache-tomcat-8.0.43/webapps
    rm -rf ~/apps/apache-tomcat-8.0.45/webapps && mkdir ~/apps/apache-tomcat-8.0.45/webapps

    echo "=== Install tomcat : End"
}

#check user account
check_user


case "$1" in
dir)
    echo "### Run make default dir ###"
    make_dir
    ;;
java)   
    echo "### Run install java ###"
    install_java
    ;;
maven)
    echo "### Run install maven ###"
    install_maven
    ;;
tomcat)
    echo "### Run install tomcat ###"
    install_tomcat
    ;;
*)
    echo "Usage : $0 {dir|java|maven|tomcat}"
    exit 1
esac



Posted by 고잉고
TAG , ,