-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
182 lines (129 loc) · 4.78 KB
/
Makefile
1
2
3
4
5
6
7
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Home Assistant Config
# Makefile for config and home assistant deployment
# This file must be run as root
BASE_DIR:=$(shell pwd)
HASS_GIT=$(BASE_DIR)/../home-assistant
HASS_BRANCH=dev-jhome
INSTALL_HOST=pi@pi
INSTALL_DIR=/srv/home-assistant
BUILD_DIR=$(BASE_DIR)/build
TMPID:=$(shell bash -c "echo $$$$")
VIRTUALENV_ACTIVATE=env/bin/activate
PRIVATE_FILES=secrets.yaml known_devices.yaml
# Default target
.PHONY: default
default:
$(info Please specify a make target. )
# Clean build
.PHONY: clean
clean:
$(info Cleaning build. )
rm -rf $(BUILD_DIR)
# Install webcam cron job and create snapshot directories
.PHONY: install-user
install-user:
adduser homeassistant || true
adduser homeassistant video || true
# Installs home assistant as service
.PHONY: install-service
install-service:
cp ext/systemd/home-assistant\@homeassistant.service /etc/systemd/system
systemctl --system daemon-reload
# Install webcam cron job and create snapshot directories
.PHONY: install-webcam
install-webcam:
# Install cron job
cp ext/webcam/webcam /etc/cron.d/
# Make script runnable
chmod +x ext/webcam/webcam.py
# Create directory for webcam snapshots
mkdir -p /mnt/tmpfs
mkdir -p $(INSTALL_DIR)/webcam
chown homeassistant /mnt/tmpfs
chown homeassistant -R $(INSTALL_DIR)/webcam
.PHONY: install-homeassistant
install-homeassistant: install-virtualenv
sudo apt-get --yes --force-yes install nmap fortunes libttspico-utils fswebcam
cd $(INSTALL_DIR) && . $(VIRTUALENV_ACTIVATE) && cd home-assistant && sudo python3 setup.py clean
cd $(INSTALL_DIR) && . $(VIRTUALENV_ACTIVATE) && cd home-assistant && sudo python3 setup.py install
chown -R homeassistant. $(INSTALL_DIR)
.PHONY: install-virtualenv
install-virtualenv:
#apt-get update --yes --force-yes
#sudo apt-get --yes --force-yes install python3 python3-venv python3-pip
mkdir -p $(INSTALL_DIR)
[ ! -d $(INSTALL_DIR)/env ] && cd $(INSTALL_DIR) && sudo python3 -m venv env || true
#cd $(INSTALL_DIR) && . $(VIRTUALENV_ACTIVATE) && cd home-assistant && sudo pip3 install -r requirements.txt --upgrade
sudo chown -R homeassistant $(INSTALL_DIR)/env
.PHONY: install
install: install-homeassistant install-user install-service install-webcam
# Default target
.PHONY: test
test:
. $(VIRTUALENV_ACTIVATE) && hass -c config --script check_config
.PHONY: build-config
build-config: test
mkdir -p $(BUILD_DIR)/hass-config
rsync -av \
--exclude='*.db' --exclude='*.log' \
--exclude='*.sample' \
--exclude='secrets.yaml' --exclude='known_devices.yaml' \
--exclude='.google.token' --exclude='.uuid' \
--exclude='config/tts/' --exclude='config/deps' \
config ext Makefile README.md \
$(BUILD_DIR)/hass-config/
.PHONY: build-hass
build-hass:
#mkdir -p $(BUILD_DIR)/hass-hass
rm -rf $(BUILD_DIR)/hass-hass
git clone -b $(HASS_BRANCH) $(HASS_GIT) $(BUILD_DIR)/hass-hass || true
rm -rf $(BUILD_DIR)/hass-hass/.git
.PHONY: build
dist: build-config build-hass
.PHONY: dist-config
dist-config: build-config
cd $(BUILD_DIR) && tar cvzf hass-config.tar.gz hass-config
.PHONY: dist-hass
dist-hass: build-hass
cd $(BUILD_DIR) && tar cvzf hass-hass.tar.gz hass-hass
.PHONY: dist
dist: dist-config dist-hass
# Copy to target host and install (runs make install on target host)
.PHONY: deploy-hass
deploy-hass: dist-hass deploy-config
$(info Deploying HA package to $(INSTALL_HOST).)
scp $(BUILD_DIR)/hass-hass.tar.gz $(INSTALL_HOST):/tmp
ssh $(INSTALL_HOST) "\
mkdir -p /tmp/hass-$(TMPID) && \
cd /tmp/hass-$(TMPID) && \
tar xf ../hass-hass.tar.gz"
ssh $(INSTALL_HOST) '\
sudo mkdir -p $(INSTALL_DIR)/home-assistant/ && \
sudo cp -r /tmp/hass-$(TMPID)/hass-hass/* $(INSTALL_DIR)/home-assistant/ && \
sudo chown -R homeassistant. $(INSTALL_DIR)/home-assistant/ && \
cd $(INSTALL_DIR) && \
sudo make install'
.PHONY: deploy-config
deploy-config: dist-config
$(info Deploying HA config to $(INSTALL_HOST).)
scp $(BUILD_DIR)/hass-config.tar.gz $(INSTALL_HOST):/tmp
ssh $(INSTALL_HOST) "\
mkdir -p /tmp/hass-$(TMPID) && \
cd /tmp/hass-$(TMPID) && \
tar xf ../hass-config.tar.gz"
ssh $(INSTALL_HOST) '\
sudo mkdir -p $(INSTALL_DIR) && \
sudo cp -r /tmp/hass-$(TMPID)/hass-config/* $(INSTALL_DIR)/ && \
sudo chown -R homeassistant. $(INSTALL_DIR)'
ssh $(INSTALL_HOST) '\
sudo sed -i "s/ \#base_url: !secret base_url/ base_url: !secret base_url/" $(INSTALL_DIR)/config/configuration.yaml'
.PHONY: deploy-secrets
deploy-secrets:
$(info Deploying HA var config to $(INSTALL_HOST).)
cd $(BASE_DIR)/config && scp $(PRIVATE_FILES) $(INSTALL_HOST):/tmp/
ssh $(INSTALL_HOST) "\
cd /tmp && sudo cp $(PRIVATE_FILES) $(INSTALL_DIR)/config && \
cd $(INSTALL_DIR)/config && sudo chown homeassistant. $(PRIVATE_FILES) && \
cd /tmp && rm $(PRIVATE_FILES)"
.PHONY: deploy
deploy: deploy-config deploy-hass