forked from tprelog/iocage-homeassistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_install.sh
executable file
·65 lines (53 loc) · 2.98 KB
/
post_install.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
#!/usr/bin/env bash
version="$(cat /root/.PLUGIN_VERSION)"
sysrc plugin_initialized="${version}"
sysrc plugin_version="${version}"
## Who will run the jail's primary service, Home Assistant Core
## Typically, the username is similar to the name of the service
## Also, the UID usually matches the service's default port ---
## If installed, optional services will also be run as this user
service_port="8123" # UID == service_port
service_name="homeassistant" # username == service_name
service_home="/home/${service_name}"
service_config="${service_home}/${service_name}"
## ISSUE 47 - Support for Python 3.8 to be dropped
pkg install -y python39 py39-sqlite3
## Which version of Python to use
service_python="python3.9"
## Add the service_name user and install a service_config directory. Creates service_home in the process
pw adduser -u "${service_port}" -n "${service_name}" -d "${service_home}" -w no -s /usr/local/bin/bash -G dialer
install -d -m 775 -o "${service_name}" -g "${service_name}" -- "${service_config}"
## Configure the jail's primary service using rcvars
sysrc ${service_name}_umask="002"
sysrc ${service_name}_user="${service_name}"
sysrc ${service_name}_group="${service_name}"
sysrc ${service_name}_config_dir="${service_config}"
sysrc ${service_name}_path="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
sysrc ${service_name}_python="$(which ${service_python})"
sysrc ${service_name}_venv="/usr/local/share/${service_name}"
## Provide the example configuration files for the jail's primary service
cp -R "/usr/local/examples/${service_name}/" "${service_config}"
find "${service_config}" -type f -name ".empty" -depth -exec rm -f {} \;
chown -R "${service_name}":"${service_name}" "${service_home}" && chmod -R g=u "${service_home}"
## Download R -> requirements and C -> constraints for the initial install
R="https://raw.githubusercontent.com/home-assistant/core/master/requirements.txt"
C="https://raw.githubusercontent.com/home-assistant/core/master/homeassistant/package_constraints.txt"
requirements="$(mktemp -t ${service_name}.requirements)"
constraints="$(mktemp -t ${service_name}.constraints)"
curl -so "${constraints}" ${C} \
&& curl -s ${R} | sed "s|homeassistant/package_constraints.txt|${constraints}|" > "${requirements}" \
&& chown "${service_name}" "${requirements}" "${constraints}"
## Install the jail's primary service, Home Assistant Core
## and remove temporary requirements and constraints files
service "${service_name}" oneinstall "${service_name}" -r "${requirements}" \
&& rm "${requirements}" "${constraints}"
## Enable and start the Home Assistant Core service
chmod +x "/usr/local/etc/rc.d/${service_name}"
sysrc -f /etc/rc.conf ${service_name}_enable="YES"
service "${service_name}" start
# shellcheck disable=SC1073,2016
{ echo -e '\nset path = (${path} /root/.plugin/bin)\n' ; \
echo -e "\n# Start console menu after login." ; \
echo "if ( -x /root/.plugin/bin/menu ) menu" ; } >> /root/.login
## Gererate PLUGIN_INFO
/root/.plugin/bin/plugin-info