vagrant-provisioning.sh 6.26 KB
Newer Older
1 2 3 4 5
#!/bin/bash -e
#
# Copyright (C) 2013 edX <info@edx.org>
#
# Authors: Xavier Antoviaque <xavier@antoviaque.org>
6
#          David Baumgold <david@davidbaumgold.com>
Yarko Tymciurak committed
7
#          Yarko Tymciurak <yarkot1@gmail.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.


###############################################################################

# vagrant-provisioning.sh:
#
# Script to setup base environment on Vagrant, based on `precise32` image
# Runs ./scripts/create-dev-env.sh for the actual setup
#
# This script is ran by `$ vagrant up`, see the README for more explanations

Yarko Tymciurak committed
34 35 36
on_create()
{
    # APT - Packages ##############################################################
37

Yarko Tymciurak committed
38 39
    apt-get update
    apt-get install -y python-software-properties vim
40 41


Yarko Tymciurak committed
42
    # Curl - No progress bar ######################################################
43

Yarko Tymciurak committed
44 45
    [[ -f ~vagrant/.curlrc ]] || echo "silent show-error" > ~vagrant/.curlrc
    chown vagrant.vagrant ~vagrant/.curlrc
46 47


Yarko Tymciurak committed
48
    # SSH - Known hosts ###########################################################
49

Yarko Tymciurak committed
50 51 52 53 54 55 56 57
    # Github
    ([[ -f ~vagrant/.ssh/known_hosts ]] && grep "zBX7bKA= ssh" ~vagrant/.ssh/known_hosts) || {
	echo "|1|4DtBcMsTM4zgl/jTS7h3ZkmS/Vc=|XkRnn2xEhr8ixOxeskJAzBX7bKA= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~vagrant/.ssh/known_hosts
    }
    ([[ -f ~vagrant/.ssh/known_hosts ]] && grep "jO3J5bvw= ssh" ~vagrant/.ssh/known_hosts) || {
	echo "|1|9rANf/qOAPgKH/TXpGuZCAgGxMs=|x9VYWEDI8kiotbhhNXqjO3J5bvw= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~vagrant/.ssh/known_hosts
    }
    chown vagrant.vagrant ~vagrant/.ssh/known_hosts
58 59


Yarko Tymciurak committed
60
    # edX - Development environment ###############################################
61

Yarko Tymciurak committed
62 63 64 65 66 67 68 69 70 71
    # Node modules require a filesystem with symlinks (Windows support)
    mkdir -p /opt/edx/node_modules /opt/edx/edx-platform/node_modules
    ([[ -f /etc/fstab ]] && grep '/opt/edx/node_modules' /etc/fstab) || {
        echo '/opt/edx/node_modules /opt/edx/edx-platform/node_modules none bind,noauto 0 0' >> /etc/fstab
        mount /opt/edx/node_modules
    }
    # Must be mounted *after* the NFS mount, made manually by Vagrant
    ([[ -f /etc/cron.d/nodemodules ]] && grep '/opt/edx/node_modules' /etc/cron.d/nodemodules) || {
        echo '@reboot root until [ -n "`mount |grep "/opt/edx/edx-platform type"`" ]; do sleep 1; done; mount /opt/edx/node_modules' > /etc/cron.d/nodemodules
    }
72

Yarko Tymciurak committed
73 74
    # Force rechecking all prerequisites (could have been fetched outside of the VM)
    rm -rf /opt/edx/edx-platform/.prereqs_cache
75

Yarko Tymciurak committed
76 77
    # Permissions
    chown vagrant.vagrant /opt/edx /opt/edx/node_modules /opt/edx/edx-platform/node_modules
78

Yarko Tymciurak committed
79 80 81 82 83 84 85
    # For convenience with `vagrant ssh`, the `edx-platform` virtualenv is always
    # loaded after the first run, so we need to deactivate that behavior to run
    # `create-dev-env.sh`.
    [[ -f ~vagrant/.bash_profile ]] && {
	mv ~vagrant/.bash_profile ~vagrant/.bash_profile.bak
    }
    sudo -u vagrant -i bash -c "cd /opt/edx/edx-platform && PROJECT_HOME=/opt/edx ./scripts/create-dev-env.sh -ynq"
86

Yarko Tymciurak committed
87 88 89 90
    # Load .bashrc ################################################################
    ([[ -f ~vagrant/.bash_profile ]] && grep ".bashrc" ~vagrant/.bash_profile) || {
	echo ". /home/vagrant/.bashrc" >> ~vagrant/.bash_profile
    }
91

92

Yarko Tymciurak committed
93
    # Virtualenv - Always load ####################################################
94

Yarko Tymciurak committed
95 96 97
    ([[ -f ~vagrant/.bash_profile ]] && grep "edx-platform/bin/activate" ~vagrant/.bash_profile) || {
	echo ". /home/vagrant/.virtualenvs/edx-platform/bin/activate" >> ~vagrant/.bash_profile
    }
98 99


Yarko Tymciurak committed
100
    # Directory ###################################################################
101

Yarko Tymciurak committed
102 103 104
    grep "cd /opt/edx/edx-platform" ~vagrant/.bash_profile || {
	echo "cd /opt/edx/edx-platform" >> ~vagrant/.bash_profile
    }
105

Yarko Tymciurak committed
106 107
    # Permissions
    chown vagrant.vagrant ~vagrant/.bash_profile
108

109 110 111
    # Install completed entirely & successfully - set flag to skip in future runs
    touch /opt/edx/.install_succeeded

Yarko Tymciurak committed
112
    cat << EOF
113
==============================================================================
Yarko Tymciurak committed
114
Success - Created your development environment!
115 116
==============================================================================

Yarko Tymciurak committed
117 118
EOF
}    # End on_create() ########################################################
119

120 121
## only initialize / setup the development environment once: 
[[ -f /opt/edx/.install_succeeded ]] || on_create
122

Yarko Tymciurak committed
123 124 125 126 127 128
# grab what the Vagrantfile spec'd our IP to be:
#  expecting:
#  - relevant ip on eth1;
#  - line of interest to look like:
#    inet 192.168.20.40/24 brd 192.168.20.255 scope global eth1
MY_IP=$(ip addr show dev eth1 | sed -n '/inet /{s/.*[ ]\(.*\)\/.*/\1/;p}')
129

Yarko Tymciurak committed
130 131 132
cat << EOF
Connect to your virtual machine with "vagrant ssh".
Some examples you can use from your virtual machine:
133

Yarko Tymciurak committed
134 135 136
- Start Learning management system (LMS):
    $ rake lms[cms.dev,0.0.0.0:8000]
    =>  http://${MY_IP}:8000/
137

Yarko Tymciurak committed
138 139 140
- Start Studio:
    $ rake cms[dev,0.0.0.0:8001]
    => http://${MY_IP}:8001/
141

Yarko Tymciurak committed
142
See the README for more.
143 144

EOF