Skip to content

Instantly share code, notes, and snippets.

@yuki777
Last active August 29, 2015 14:13
Show Gist options
  • Save yuki777/2513b7ee1b1932f91a49 to your computer and use it in GitHub Desktop.
Save yuki777/2513b7ee1b1932f91a49 to your computer and use it in GitHub Desktop.
create fvndev10
#!/bin/bash
sudo date
project_name=fvndev10.local
ip=192.168.33.55
# このスクリプトはMac用なのでそれ以外のOSでは終了
if [ 'Darwin' != `uname` ];then
echo sorry, this script made for Darwin.
exit 1
fi
# 既に使用しているIPなら終了
grep $ip /etc/hosts > /dev/null
if [ $? == 0 ];then
echo duplicate on /etc/hosts .
exit 1
fi
# $project_nameでhost解決したいのでhostsに登録しておく
sudo sh -c "echo $ip $project_name >> /etc/hosts"
# vagrantにfreebsd10のboxファイルを登録
cd ~/vagrant
vagrant box add --force $project_name ~/vagrant/freebsd10.box
mkdir -p $project_name
cd $project_name
# vagrantの設定ファイルを作っておく
touch Vagrantfile
rm Vagrantfile
vagrant init
cat << EOF > Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.ssh.shell = 'sh'
config.vm.box = "$project_name"
config.vm.network "private_network", ip: "$ip"
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048", "--cpus", "4"]
vb.name = "$project_name" # shown in VirtualBox GUI menu
end
config.vm.define "$project_name" do |t|
t.vm.hostname = "$project_name"
end
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
ansible.inventory_path = "hosts"
end
end
EOF
# ansibleで管理したいので設定ファイルを作っておく
cat << EOF > hosts
[vagrant]
$project_name ansible_python_interpreter=/usr/local/bin/python
EOF
# ansibleのプレイブックを作っておく
# TODO:rc.local
# rc.localはdhcp client em2をkillしている
# 理由はalready runningでvagrant upに失敗するため
# このやり方は良くないのでなんとかするべき
cat << EOF > playbook.yml
- hosts: $project_name
sudo: true
user: vagrant
tasks:
- copy: src=~/vagrant/rc.local dest=/etc/rc.local
- pkgng: name=vim
- pkgng: name=zsh
- pkgng: name=tmux
- pkgng: name=git
- pkgng: name=subversion
- pkgng: name=mercurial
- pkgng: name=ctags
- pkgng: name=global
- pkgng: name=the_silver_searcher
EOF
# ssh設定をconfigに追記
cd ~/vagrant/$project_name
vagrant ssh-config >> ~/.ssh/config
# 簡単な起動、ログイン、終了の説明
cat <<-EOF
###############################
# You can run these commands. #
###############################
# boot
vagrant up
# login
ssh $project_name
# shutdown
vagrant halt
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment