duoan / notes

Classtag's Notebooks
https://github.com/classtag/notebook/issues
9 stars 3 forks source link

JDK自动安装脚本 #21

Open duoan opened 7 years ago

duoan commented 7 years ago

#!/bin/csh
# shell script to install jdk
# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install JDK"
    exit 1
fi
clear
function installJDK(){
    # unzip
    cd /usr/lib/
    tar -xvf /tmp/jdk-8u101-linux-x64.tar.gz -C /usr/lib
    ln -s /usr/lib/jdk1.8.0_101 /usr/lib/jdk

    ## config jdk
    rm -rf /tmp/jdk.sh
    touch /tmp/jdk.sh
    echo 'export JAVA_HOME=/usr/lib/jdk' >> /tmp/jdk.sh
    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /tmp/jdk.sh
    echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /tmp/jdk.sh
    rm -rf /etc/profile.d/jdk.sh
    cp /tmp/jdk.sh /etc/profile.d/
    source /etc/profile
    update-alternatives --remove  java /usr/lib/jvm/jre-1.5.0-gcj/bin/java
    update-alternatives --install /usr/bin/java java /usr/jdk/bin/java 300
    update-alternatives --install /usr/bin/javac javac /usr/jdk/bin/javac 300
    echo "jdk is installed !"
}

installJDK 2>&1 | tee -a /root/jdk-install.log