install-rhel.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #
  3. # Install a VLMCSD service for CentOS/RedHat
  4. #
  5. # Author: Wind4 (puxiaping@gmail.com)
  6. # Date: November 30, 2015
  7. #
  8. check_result() {
  9. if [ $1 -ne 0 ]; then
  10. echo "Error: $2" >&2
  11. exit $1
  12. fi
  13. }
  14. if [ "x$(id -u)" != 'x0' ]; then
  15. echo 'Error: This script can only be executed by root'
  16. exit 1
  17. fi
  18. if [ -f '/etc/init.d/vlmcsd' ]; then
  19. echo 'VLMCSD service has been installed.'
  20. exit 1
  21. fi
  22. if [ ! -f '/usr/bin/wget' ]; then
  23. echo 'Installing wget ...'
  24. yum -q -y install wget
  25. check_result $? "Can't install wget."
  26. echo 'Install wget succeed.'
  27. fi
  28. if [ ! -f '/sbin/service' ]; then
  29. echo 'Installing initscripts ...'
  30. yum -q -y install initscripts
  31. check_result $? "Can't install initscripts."
  32. echo 'Install initscripts succeed.'
  33. fi
  34. TMP_DIR=`mktemp -d`
  35. cd ${TMP_DIR}
  36. echo 'Downloading vlmcsd ...'
  37. wget -q https://github.com/Wind4/vlmcsd/releases/download/svn1099/binaries.tar.gz -O binaries.tar.gz
  38. check_result $? 'Download vlmcsd failed.'
  39. echo 'Downloading startup script ...'
  40. wget -q https://wind4.github.io/vlmcsd/scripts/init.d/vlmcsd-rhel -O vlmcsd.init
  41. check_result $? 'Download startup script failed.'
  42. echo 'Extract vlmcsd ...'
  43. tar zxf binaries.tar.gz
  44. cp binaries/Linux/intel/static/vlmcsd-x86-musl-static /usr/bin/vlmcsd
  45. cp vlmcsd.init /etc/init.d/vlmcsd
  46. echo 'Fix Permissions ...'
  47. chmod 755 /usr/bin/vlmcsd
  48. chown root.root /usr/bin/vlmcsd
  49. chmod 755 /etc/init.d/vlmcsd
  50. chown root.root /etc/init.d/vlmcsd
  51. echo 'Configuring deamon ...'
  52. chkconfig --add vlmcsd
  53. chkconfig vlmcsd on
  54. service vlmcsd start
  55. check_result $? 'Installation failed.'
  56. echo 'Cleaning ...'
  57. rm -rf ${TMP_DIR}
  58. echo 'Installed successfully.'