#!/bin/bash


#wget https://uno.teracloud.jp/v2/api/share/public/116148eb18ae82c4/5ff5f6f339c4 -O jdk-8u271-linux-x64.tar.gz
#wget https://pan.107423.xyz/api/v3/file/download/j8v2CiYppkatcafb?sign=8Z_0Hq9-Fy0UxKiDkchO52YPht8l-dTfi3DTyWSluT4%3D%3A1609922899 -O jdk-8u271-linux-x64.tar.gz

wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/jdk-8u271-linux-x64.tar.gz
mkdir /usr/local/java/
tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/java/

cat >>/etc/profile <<EOF
export JAVA_HOME=/usr/local/java/jdk1.8.0_271
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=${JAVA_HOME}/lib:${JRE_HOME}/lib:${CLASSPATH}
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:${PATH}
EOF
source /etc/profile
ln -s /usr/local/java/jdk1.8.0_271/bin/java /usr/bin/java
java -version

#wget --no-check-certificate https://github.com/alibaba/nacos/releases/download/1.4.0/nacos-server-1.4.0.tar.gz
wget https://objectstorage.ap-seoul-1.oraclecloud.com/n/cnk8d6fazu16/b/seoul/o/nacos-server-1.4.0.tar.gz

tar -zvxf nacos-server-1.4.0.tar.gz -C /usr/local

cat >>/lib/systemd/system/nacos.service<<EOF
[Unit]
Description=nacos
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl start nacos.service
systemctl enable nacos.service

rm -rf /usr/local/nacos
rm -rf /lib/systemd/system/nacos.service