#!/usr/bin/bash

#Tate:2022.3.26
#Author:Yingjian
#Function：一键安装node

#判断是否重复安装
if [ -d "/usr/local/node" ];then
echo "node 已安装" 
exit 2
fi
#判断网络是否正常
ping -c 1 www.baidu.com &> /dev/null
if [ ! $? -eq 0 ];then
echo "请检测网络是否正常"
exit 2
fi
#安装
if [ ! -f "/usr/local/src/node-v16.14.2-linux-x64.tar.xz" ];then
curl -o /usr/local/src/node-v16.14.2-linux-x64.tar.xz -s http://8.210.62.122/node/node-v16.14.2-linux-x64.tar.xz
else
echo "node包已安装"
fi
#解压
tar xf /usr/local/src/node-v16.14.2-linux-x64.tar.xz -C /usr/local
mv /usr/local/node-v16.14.2-linux-x64 /usr/local/node
#环境变量
cat > /etc/profile.d/node.sh <<EOF
export NODE_HOME=/usr/local/node
export PATH=\$NODE_HOME/bin:\$PATH
EOF

source /etc/profile.d/node.sh
