nodejs.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Nodejs() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. tar xzf node-v${nodejs_ver}-linux-${SYS_ARCH_n}.tar.gz
  13. /bin/mv node-v${nodejs_ver}-linux-${SYS_ARCH_n} ${nodejs_install_dir}
  14. if [ -e "${nodejs_install_dir}/bin/node" ]; then
  15. cat > /etc/profile.d/nodejs.sh << EOF
  16. export NODE_HOME=${nodejs_install_dir}
  17. export PATH=\$NODE_HOME/bin:\$PATH
  18. EOF
  19. . /etc/profile
  20. echo "${CSUCCESS}Nodejs installed successfully! ${CEND}"
  21. else
  22. echo "${CFAILURE}Nodejs install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  23. kill -9 $$; exit 1;
  24. fi
  25. popd > /dev/null
  26. }
  27. Uninstall_Nodejs() {
  28. if [ -e "${nodejs_install_dir}" ]; then
  29. rm -rf ${nodejs_install_dir} /etc/profile.d/nodejs.sh
  30. echo "${CMSG}Nodejs uninstall completed! ${CEND}"
  31. fi
  32. }