install.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  3. clear
  4. # Check if user is root
  5. [ $(id -u) != "0" ] && { echo "Error: You must be root to run this script, please use 'sudo su -' command to change root"; exit 1; }
  6. version(){
  7. echo "version: 0.1"
  8. echo "updated date: 2019-12-30"
  9. }
  10. Show_Help(){
  11. version
  12. echo "Usage: $0 command ...[parameters]...
  13. --help, -h Show this help message
  14. --version, -v Show version info
  15. "
  16. }
  17. echo "Pre-installation is starting, please wait for 1-3 minutes..."
  18. # OracleLinux need install oaclelinux-developer-release-e* oracle-nodejs-release-e* oracle-epel-release-e* in Image before this script
  19. if command -v yum > /dev/null; then
  20. sudo yum install -y epel-release 1>/dev/null 2>&1
  21. sudo yum install yum-utils git libselinux-python python python3 -y 1>/dev/null 2>&1
  22. sudo python3 -m pip install -U --force-reinstall requests docker 1>/dev/null 2>&1
  23. if command -v amazon-linux-extras > /dev/null; then
  24. echo "amazon-linux-extras install ansible2"
  25. sudo amazon-linux-extras install ansible2
  26. else
  27. echo "yum install ansible"
  28. sudo yum install ansible sshpass -y 1>/dev/null 2>&1
  29. fi
  30. fi
  31. if command -v apt > /dev/null; then
  32. sudo apt-get install git python python3 git -y 1>/dev/null 2>&1
  33. sudo apt install software-properties-common -y 1>/dev/null 2>&1
  34. if [[ $(cat /etc/os-release |grep VERSION_CODENAME |cut -d= -f2) == focal ]];then
  35. echo "have ansible pkg"
  36. elif [[ $(cat /etc/os-release |grep VERSION_CODENAME |cut -d= -f2) == bionic ]];then
  37. sudo apt-add-repository --yes --update ppa:ansible/ansible
  38. fi
  39. sudo apt install ansible sshpass -y
  40. fi
  41. sudo echo "Pre-installation has beend completed"
  42. # r:repository; i:init
  43. while getopts ":r:"":i:" opt
  44. do
  45. case $opt in
  46. r)
  47. repo_name=$OPTARG;;
  48. i)
  49. repo_init=$OPTARG
  50. ;;
  51. ?)
  52. echo "no repository"
  53. exit 1;;
  54. esac
  55. done
  56. echo $repo_name
  57. echo $repo_init
  58. cd /tmp
  59. rm -rf StackHub
  60. wget -N https://websoft9.github.io/StackHub/scripts/githubclone.sh && bash githubclone.sh websoft9 StackHub
  61. cd StackHub/apps
  62. sudo echo "localhost" > hosts
  63. ansible-playbook -i hosts application.yml -c local -e init=$repo_init -e appname=$repo_name
  64. if [ $repo_init -ne 0 ]; then
  65. echo "Image build success!"
  66. else
  67. echo "System must restart after 2s, then installation completed"; sleep 2 ; sudo reboot
  68. fi