# -*- mode: ruby -*-
# vi: set ft=ruby :

############### フロントエンド開発用 CentOS i386 版 ############
#  
#  ※※※　目的　※※※
#
#  フロントエンド開発用 vagrantプロビジョニング
#  動作環境 Mac 多分 Windows の gitbash下など
#
#  ※※※　注意　※※※
#
#    一つ上のディレクトリに "../vagrant_www" を作ってvagrant upする。
#    または下の"config.vm.synced_folder"のフォルダ名を書き換えて使用。
#    virtualbox と vagrantをインストールしてコンソールから以下を実行
#
#
#  ※※※　操作　※※※
#  mkdir vagrant(任意)
#  cd vagrant
#  wget http://www.i-elements.net/vagrant_box/Vagrantfile
#  vagrant up
#
#  httpd://192.168.33.12
#
#    うまくいくと上記アドレスで
#    ../vagrant_www/html/
#　  をドキュメントルートとしたwebサーバーが立ち上がる。
#
#
#  ※※※　proxy環境下での注意（そうでない場合読む必要無）　※※※
#
#  この他にもproxy環境下ではそれぞれのproxyに応じた処理が必要なので対応が必要
#　
#  WindowsでVargentを使う場合のプロキシ設定（windows環境変数に指定）
#  http://weblabo.oscasierra.net/windows-vargent-proxy/
#  set http_proxy="proxy.mycompany.co.jp:8080"
#  set https_proxy="proxy.mycompany.co.jp:8080"
#  「システムの詳細設定」から環境変数の設定から変数設定
#  
#  Vagrantで作成するゲストOS側にProxy設定をする手順
#  http://qiita.com/shouta-dev/items/7b8a462504f7d6c91e99
#
#
#  wgetでproxyを指定する方法
#  $wget -e HTTP_PROXY=proxy.co.jp:8080 'http://www.goo.ne.jp/'
#
#
#  wgetをプロキシ経由で使う
#  http://d.hatena.ne.jp/taiyo/20080401/p2
#  ~/.wgetrc に、以下の設定を記述
#
#  use_proxy = on
#  proxy_user = 4000000
#  proxy_passwd = PassWord
#  http_proxy = http://abcproxy.examlple.com:8080
#  https_proxy = http://abcproxy.examlple.com:8080
#  ftp_proxy = http://abcproxy.examlple.com:8080
#  ~/.wgetrc のパーミッションは 600(自分のみread/wriet可) にしておく
#
#
############### フロントエンド開発用 CentOS i386 版 ############


# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.

Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.

  # config.vm.box = "CentOS6.7i386"
  config.vm.box = "https://dl.dropboxusercontent.com/u/51478659/vagrant/morungos-centos67.box"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  

#####################プライベートネットワーク#####################

  config.vm.network "private_network", ip: "192.168.33.12"

#####################プライベートネットワーク#####################


  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"


##################### 公開するwwwの共有ディレクトリ設定 #####################

#  config.vm.synced_folder "../vagrant_www", "/vagrant_www"
#  config.vm.synced_folder "../ColumnSelector","/vagrant_www"
  config.vm.synced_folder "../vagrant_www","/vagrant_www"

##################### 公開するwwwの共有ディレクトリ設定 #####################


  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo apt-get update
  #   sudo apt-get install -y apache2
  # SHELL

##################################################### provision 開始

config.vm.provision "shell", inline: <<-SHELL
    echo "alias lla='ls -al'" > ~/.alias
    echo "alias la='ls -a'" >> ~/.alias
    echo "alias la='cd /vagrant_www" >> ~/.alias

    echo "" >> ~/.bash_profile
    echo "source ~/.alias" >> ~/.bash_profile


    echo "alias lla='ls -al'" > /home/vagrant/.alias
    echo "alias la='ls -a'" >> /home/vagrant/.alias
    echo "alias pj='cd /vagrant_www'" >> /home/vagrant/.alias

    echo "" >> /home/vagrant/.bash_profile
    echo "source ~/.alias" >> /home/vagrant/.bash_profile


    # sudo yum update -y
    sudo yum install httpd -y
    sudo yum install git -y
    sudo yum install mysql -y
    sudo yum install mysql-server -y
    sudo yum install php -y
    sudo yum install emacs -y
    sudo chkconfig mysqld on
    sudo chkconfig httpd on

    sudo chkconfig iptables off
    sudo service iptables stop

#### phantomjsをビルド

    sudo yum -y install gcc gcc-c++ make flex bison gperf ruby \
      openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel \
      libpng-devel libjpeg-devel

##    git clone --recurse-submodules git://github.com/ariya/phantomjs.git

    git clone git://github.com/ariya/phantomjs.git
    cd phantomjs
    ./build.py -c

    sudo cp ./bin/phantomjs /usr/local/bin

    sudo rehash

    sudo npm install phantomjs -g


#### NODEをインストール

    sudo yum install -y gcc-c++ make
    sudo curl -sL https://rpm.nodesource.com/setup | sudo bash -

    #sudo yum install nodejs npm --enablerepo=epel 
    sudo yum install nodejs npm -y
    sudo npm install -g n
    sudo n stable


#### gruntをインストール

    sudo npm install -g grunt
    sudo npm install -g grunt-cli
    sudo npm install -g grunt-contrib

#### jasmineをインストール

    sudo npm install -g jasmine
    sudo npm install -g grunt-contrib-jasmine


#### webをvagrant_wwwで動かせるように調整

    sudo mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bk
    sudo touch /etc/httpd/conf.d/welcome.conf

    sudo mv /var/www/html /var/www/html.old
    sudo mv /var/www/cgi-bin /var/www/cgi-bin.old

    sudo mkdir /vagrant_www/html
    sudo mkdir /vagrant_www/cgi-bin

    sudo ln -s /vagrant_www/html /var/www/
    sudo ln -s /vagrant_www/cgi-bin /var/www/


SHELL
##################################################### provision 終了


config.vm.provision :shell, run: "always", :inline => <<-EOT
   sudo service httpd restart
   sudo setenforce 0
EOT



end
