setup.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. set -e
  3. #TODO: Support python virtual environments for now global
  4. COLOR_END='\e[0m'
  5. COLOR_RED='\e[0;31m' # Red
  6. COLOR_YEL='\e[0;33m' # Yellow
  7. # This current directory.
  8. DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
  9. ROOT_DIR=$(cd "$DIR/../../" && pwd)
  10. PYTHON_REQUIREMNTS_FILE="$DIR/python_requirements.txt"
  11. GEMFILE="$ROOT_DIR/Gemfile"
  12. msg_exit() {
  13. printf "$COLOR_RED$@$COLOR_END"
  14. printf "\n"
  15. printf "Exiting...\n"
  16. exit 1
  17. }
  18. msg_warning() {
  19. printf "$COLOR_YEL$@$COLOR_END"
  20. printf "\n"
  21. }
  22. # Check your environment
  23. system=$(uname)
  24. if [ "$system" == "Linux" ]; then
  25. distro=$(lsb_release -i)
  26. if [[ $distro == *"Ubuntu"* ]] || [[ $distro == *"Debian"* ]] ;then
  27. msg_warning "Your running Debian based linux.\n You might need to install 'sudo apt-get install build-essential python-dev\n."
  28. # TODO: check if ubuntu and install build-essential, and python-dev
  29. else
  30. msg_warning "Your linux system was not tested"
  31. fi
  32. fi
  33. # Check if root
  34. # Since we need to make sure paths are okay we need to run as normal user he will use ansible
  35. [[ "$(whoami)" == "root" ]] && msg_exit "Please run as a normal user not root"
  36. # Check python
  37. [[ -z "$(which python)" ]] && msg_exit "Opps python is not installed or not in your path."
  38. # Check pip
  39. [[ -z "$(which pip)" ]] && msg_exit "pip is not installed!\nYou can try'sudo easy_install pip'"
  40. # Check python file
  41. [[ ! -f "$PYTHON_REQUIREMNTS_FILE" ]] && msg_exit "python_requirements '$PYTHON_REQUIREMNTS_FILE' does not exist or permssion issue.\nPlease check and rerun."
  42. # Check for bundler
  43. [[ -z "$(which bundle)" ]] && msg_exit "Oops you need bundler to install ruby dependencies (http://bundler.io/)"
  44. # Install
  45. # By default we upgrade all packges to latest. if we need to pin packages use the python_requirements
  46. echo "This script install python packages defined in '$PYTHON_REQUIREMNTS_FILE' "
  47. echo "Since we only support global packages installation for now we need root password."
  48. echo "You will be asked for your password."
  49. sudo -H pip install --upgrade --requirement "$PYTHON_REQUIREMNTS_FILE"
  50. echo "This script will now install ruby dependencies via bundler"
  51. bundle install --gemfile=$GEMFILE
  52. #Touch vault password file
  53. echo "Touching vault password file"
  54. if [ -w "$ROOT_DIR" ]
  55. then
  56. touch "$ROOT_DIR/.vault-password"
  57. else
  58. sudo touch "$ROOT_DIR/.vault-password"
  59. fi
  60. exit 0