-
Notifications
You must be signed in to change notification settings - Fork 11
/
post_update.sh
executable file
·75 lines (64 loc) · 2.58 KB
/
post_update.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC1091,2001,2154
. /etc/rc.subr && load_rc_config
: "${plugin_enable_pkglist:="NO"}"
: "${plugin_clean_install_service:="NO"}"
: "${plugin_force_reinstall_service:="NO"}"
: "${plugin_upgrade_service:="NO"}"
install_pkglist() {
## If enabled, re-install packages from a pkglist during a Plugin UPDATE
## Use `sysrc plugin_pkglist="/path/to/pkglist"` to set a pkglist
## Use `sysrc plugin_enable_pkglist=YES` to enable
local pkgs ; pkgs=$(cat "${plugin_pkglist:-/dev/null}")
echo -e "\nChecking for additional packages to install..."
echo "${pkgs}" | xargs pkg install -y
}
check_for_python() {
## Ensure the set version of Python is installed for Home Assistant Core
if [ -n "${homeassistant_python}" ]; then
local version ; version=$(echo "${homeassistant_python##*python}" | sed 's/\.//')
pkg install -y "python${version}" "py${version}-sqlite3"
fi
## ... and Appdaemon, if enabled
if checkyesno "{appdaemon_enable:-NO}"; then
if [ -n "${appdaemon_python}" ] && ! which "${appdaemon_python}" > /dev/null 2>&1; then
local version ; version=$(echo "${appdaemon_python##*python}" | sed 's/\.//')
pkg install -y "python${version}"
fi
fi
## ... and Hass-Configurator, if enabled
if checkyesno "{configurator_enable:-NO}"; then
if [ -n "${configurator_python}" ] && ! which "${configurator_python}" > /dev/null 2>&1; then
local version ; version=$(echo "${configurator_python##*python}" | sed 's/\.//')
pkg install -y "python${version}"
fi
fi
}
clean_install_service() {
## If enabled, clean-install Home Assistant Core during a Plugin UPDATE
## Use `sysrc plugin_clean_install_service=YES` to enable
rm -rf "${homeassistant_venv}"
service homeassistant install homeassistant
}
force_reinstall_service() {
## If enabled, force-reinstall Home Assistant Core during a Plugin UPDATE
## Use `sysrc plugin_force_reinstall_service=YES` to enable
service homeassistant install --upgrade --force-reinstall homeassistant
}
upgrade_service() {
## If enabled, upgrade Home Assistant Core during a Plugin UPDATE
## Use `sysrc plugin_upgrade_service=YES` to enable
service homeassistant install --upgrade homeassistant
}
checkyesno plugin_enable_pkglist && install_pkglist
check_for_python
if checkyesno plugin_clean_install_service; then
clean_install_service
elif checkyesno plugin_force_reinstall_service; then
force_reinstall_service
elif checkyesno plugin_upgrade_service; then
upgrade_service
fi
sysrc plugin_version="$(cat /root/.PLUGIN_VERSION)"
## Gererate PLUGIN_INFO
/root/.plugin/bin/plugin-info