From 5076ebe43c83460a1c9775b53f4c61c0705e0965 Mon Sep 17 00:00:00 2001 From: Alexander Fortin Date: Sun, 29 May 2016 08:58:09 +0200 Subject: [PATCH] Add Vagrant setup (#2171) --- .gitignore | 5 ++ virtualization/vagrant/Vagrantfile | 12 +++ virtualization/vagrant/config/.placeholder | 0 virtualization/vagrant/provision.sh | 88 ++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 virtualization/vagrant/Vagrantfile create mode 100644 virtualization/vagrant/config/.placeholder create mode 100644 virtualization/vagrant/provision.sh diff --git a/.gitignore b/.gitignore index f049564253f..12f35dc5c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,8 @@ venv *.swo ctags.tmp + +# vagrant stuff +virtualization/vagrant/setup_done +virtualization/vagrant/.vagrant +virtualization/vagrant/config diff --git a/virtualization/vagrant/Vagrantfile b/virtualization/vagrant/Vagrantfile new file mode 100644 index 00000000000..7c67baa2ce4 --- /dev/null +++ b/virtualization/vagrant/Vagrantfile @@ -0,0 +1,12 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + config.vm.box = "debian/contrib-jessie64" + config.vm.synced_folder "../../", "/home-assistant" + config.vm.synced_folder "./config", "/root/.homeassistant" + config.vm.network "forwarded_port", guest: 8123, host: 8123 + config.vm.provision "shell" do |shell| + shell.path = "provision.sh" + end +end diff --git a/virtualization/vagrant/config/.placeholder b/virtualization/vagrant/config/.placeholder new file mode 100644 index 00000000000..e69de29bb2d diff --git a/virtualization/vagrant/provision.sh b/virtualization/vagrant/provision.sh new file mode 100644 index 00000000000..299828525c1 --- /dev/null +++ b/virtualization/vagrant/provision.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e + +readonly SETUP_DONE='/home-assistant/virtualization/vagrant/setup_done' +readonly RUN_TESTS='/home-assistant/virtualization/vagrant/run_tests' +readonly RESTART='/home-assistant/virtualization/vagrant/restart' + +usage() { + echo '############################################################ +############################################################ +############################################################ + +Use `vagrant provision` to either run tests or restart HASS: + +`touch run_tests && vagrant provision` + +or + +`touch restart && vagrant provision` + +To destroy the host and start anew: + +`vagrant destroy -f ; rm setup_done; vagrant up` + +############################################################ +############################################################ +############################################################' +} + +print_done() { + echo '############################################################ +############################################################ +############################################################ + + +HASS running => http://localhost:8123/ + +' +} + +setup() { + local hass_path='/root/venv/bin/hass' + local systemd_bin_path='/usr/bin/hass' + # Setup systemd + cp /home-assistant/script/home-assistant@.service \ + /etc/systemd/system/home-assistant.service + systemctl --system daemon-reload + systemctl enable home-assistant + # Install packages + apt-get update + apt-get install -y git rsync python3-dev python3-pip + pip3 install --upgrade virtualenv + virtualenv ~/venv + source ~/venv/bin/activate + pip3 install --upgrade tox + /home-assistant/script/setup + if ! [ -f $systemd_bin_path ]; then + ln -s $hass_path $systemd_bin_path + fi + touch $SETUP_DONE + print_done + usage +} + +run_tests() { + systemctl stop home-assistant + source ~/venv/bin/activate + rsync -a --delete \ + --exclude='*.tox' \ + --exclude='*.git' \ + /home-assistant/ /home-assistant-tests/ + cd /home-assistant-tests && tox + rm $RUN_TESTS +} + +restart() { + systemctl restart home-assistant + rm $RESTART +} + +main() { + if ! [ -f $SETUP_DONE ]; then setup; fi + if [ -f $RUN_TESTS ]; then run_tests; fi + if [ -f $RESTART ]; then restart; fi + systemctl start home-assistant +} + +main