bootstrap.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env bash
  2. #
  3. # Prepares a virtual machine for running TFB
  4. #
  5. # Intentionally uses ~, $HOME, and $USER so that the
  6. # same script can work for VirtualBox (username vagrant)
  7. # and Amazon (username ubuntu)
  8. # Add everything passed in the first argument to our
  9. # local environment. This is a hack to let us use
  10. # environment variables defined on the host inside the
  11. # guest machine
  12. while read -r line; do
  13. export $line;
  14. done <<< "$1"
  15. # Store any custom variables used at launch, in case someone forgets
  16. # what this instance is (e.g. SSD or HDD, etc)
  17. echo "$1" > ~/.tfb_launch_options
  18. # Are we installing the server machine, the client machine,
  19. # the database machine, or all machines?
  20. # Valid values:
  21. # - all (we are setting up a development environment)
  22. # - database (we are setting up the database machine)
  23. # - client (we are setting up the client machine for load generation)
  24. # - server (we are setting up the machine that will host frameworks)
  25. ROLE=${2:-all}
  26. # Set a number of variables by either pulling them from
  27. # the existing environment or using the default values
  28. # I'm renaming them to indicate that (in this script only)
  29. # the values are provisioner agnostic
  30. SERVER_IP=${TFB_AWS_APP_IP:-172.16.0.16}
  31. CLIENT_IP=${TFB_AWS_LOAD_IP:-172.16.0.17}
  32. DATABA_IP=${TFB_AWS_DB_IP:-172.16.0.18}
  33. if [ "$ROLE" == "all" ]; then
  34. SERVER_IP=127.0.0.1
  35. CLIENT_IP=127.0.0.1
  36. DATABA_IP=127.0.0.1
  37. fi
  38. GH_REPO=${TFB_AWS_REPO_SLUG:-TechEmpower/FrameworkBenchmarks}
  39. GH_BRANCH=${TFB_AWS_REPO_BRANCH:-master}
  40. # A shell provisioner is called multiple times
  41. if [ ! -e "~/.firstboot" ]; then
  42. # Setup hosts
  43. echo "Setting up convenience hosts entries"
  44. echo $DATABA_IP TFB-database | sudo tee --append /etc/hosts
  45. echo $CLIENT_IP TFB-client | sudo tee --append /etc/hosts
  46. echo $SERVER_IP TFB-server | sudo tee --append /etc/hosts
  47. # Update hostname to reflect our current role
  48. if [ "$ROLE" != "all" ]; then
  49. echo "Updating hostname"
  50. echo 127.0.0.1 `hostname` | sudo tee --append /etc/hosts
  51. myhost=TFB-${ROLE}
  52. echo $myhost | sudo tee --append /etc/hostname
  53. sudo hostname $myhost
  54. echo Updated /etc/hosts file to be:
  55. cat /etc/hosts
  56. fi
  57. # Update the benchmark.cfg for vagrant
  58. sed -i s/techempower/vagrant/g ~/FrameworkBenchmarks/benchmark.cfg
  59. # Workaround mitchellh/vagrant#289
  60. echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | sudo debconf-set-selections
  61. # Install prerequisite tools
  62. echo "Installing prerequisites"
  63. sudo apt-get update
  64. sudo apt-get install -y git
  65. # Make project available
  66. # If they synced it to /FwBm, just expose it at ~/FwBm
  67. # If they didn't sync, we need to clone it
  68. #if [ -d "/FrameworkBenchmarks" ]; then
  69. #ln -s /FrameworkBenchmarks $FWROOT
  70. #echo "Removing your current results folder to avoid interference"
  71. #rm -rf $FWROOT/installs $FWROOT/results
  72. # vboxfs does not support chown or chmod, which we need.
  73. # We therefore bind-mount a normal linux directory so we can
  74. # use these operations.
  75. #echo "Mounting over your installs folder"
  76. #mkdir -p /tmp/TFB_installs
  77. #mkdir -p /FrameworkBenchmarks/installs
  78. #sudo mount -o bind /tmp/TFB_installs $FWROOT/installs
  79. #else
  80. # If there is no synced folder, clone the project
  81. echo "Cloning project from $GH_REPO $GH_BRANCH"
  82. git config --global core.autocrlf input
  83. git clone -b ${GH_BRANCH} https://github.com/${GH_REPO}.git $FWROOT
  84. source ~/FrameworkBenchmarks/toolset/setup/linux/prerequisites.sh
  85. #fi
  86. # Everyone gets SSH access to localhost
  87. echo "Setting up SSH access to localhost"
  88. ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
  89. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  90. chmod 600 ~/.ssh/authorized_keys
  91. # Enable remote SSH access if we are running production environment
  92. # Note : this is always copied from the local working copy using a
  93. # file provisioner. While they exist in the git clone we just
  94. # created (so we could use those), we want to let the user
  95. # have the option of replacing the keys in their working copy
  96. # and ensuring that only they can ssh into the machines
  97. if [ "$ROLE" == "server" ]; then
  98. # Ensure keys have proper permissions
  99. chmod 600 ~/.ssh/client ~/.ssh/database
  100. elif [ "$ROLE" != "all" ]; then
  101. # Ensure keys can be used to ssh in
  102. echo "Setting up SSH access for the TFB-server"
  103. mykey=~/.ssh/$ROLE.pub
  104. echo "Using key: "
  105. ssh-keygen -lv -f $mykey
  106. cat $mykey >> ~/.ssh/authorized_keys
  107. # Ensure keys have proper permissions
  108. chmod 600 ~/.ssh/client ~/.ssh/database
  109. fi
  110. # Setup a nice welcome message for our guest
  111. echo "Setting up welcome message"
  112. sudo rm -f /etc/update-motd.d/51-cloudguest
  113. sudo rm -f /etc/update-motd.d/98-cloudguest
  114. sudo mv ~/.custom_motd.sh /etc/update-motd.d/55-tfbwelcome
  115. fi