summarylogtreecommitdiffstats
path: root/hass-update.service
blob: f7c041accfc5668ad38e223074619924be65d262 (plain)
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
[Unit]
Description=Home assistant update
After=network.target

[Service]
User=hass
Group=hass
LogsDirectory=hass
StateDirectory=hass hass-installation
CacheDirectory=hass
Environment=XDG_CACHE_HOME=%C/hass
Environment=CARGO_HOME=${XDG_CACHE_HOME}/cargo
Environment=PYTHON_EGG_CACHE=${XDG_CACHE_HOME}/python-eggs
Environment=VIRTUAL_ENV=%S/hass-installation
WorkingDirectory=~

EnvironmentFile=-/etc/hass.env

Type=oneshot
# install or upgrade the python venv, we want
ExecStart=python -m venv --system-site-packages --upgrade "${VIRTUAL_ENV}"

# install/upgrade home assistant and all its necessary libs
ExecStart=%S/hass-installation/bin/pip install --no-warn-script-location --upgrade homeassistant
# delete old site packages from old versions of python
ExecStart=sh -c '\
		baseVenvLib=$(%S/hass-installation/bin/python -c "import os.path as path; import site; print(path.dirname(path.dirname(site.getsitepackages()[0])))"); \
		curSitePackagesRel=$(%S/hass-installation/bin/python -c "import os.path as path; import site; print(path.basename(path.dirname(path.relpath(site.getsitepackages()[0],\'${VIRTUAL_ENV}/lib\'))))"); \
		echo "keeping ${curSitePackagesRel} out of "${baseVenvLib}"; \
		find \
				"${baseVenvLib}" -mindepth 1 -type d \
				-path "${curSitePackagesRel}" -prune \
				-print0 \
		| xargs --no-run-if-empty -0 rm --verbose --recursive'
# remove pinned dependencies
ExecStart=sh -c '\
		sitePackages=$(%S/hass-installation/bin/python -c "import os.path as path; import site; print(site.getsitepackages()[0])"); \
		find \
				"${sitePackages}/homeassistant" \
					-name "package_constraints.txt" \
				-o	-name "manifest.json" \
				-o 	-name "METADATA" \
				-exec sed -i "s/==/>=/g" {} \;'

LockPersonality=true
RestrictRealtime=true
RestrictSUIDSGID=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
PrivateMounts=true
PrivateTmp=true
ProtectSystem=full
PrivateDevices=true

[Install]
WantedBy=multi-user.target