2018-09-25 19:03:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# manage script failure
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
# retrieve arguments
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-10-18 05:16:40 +02:00
|
|
|
|
2018-09-25 19:03:30 +02:00
|
|
|
# definie useful vars
|
2018-10-18 05:16:40 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
|
|
|
home_path="/home/$app"
|
2018-09-25 19:03:30 +02:00
|
|
|
data_path="/home/$app/.$app"
|
|
|
|
|
|
|
|
# check domain/path availability
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2018-09-25 19:03:30 +02:00
|
|
|
path_url=$(ynh_normalize_url_path "/")
|
2018-10-18 05:16:40 +02:00
|
|
|
ynh_webpath_available "$domain" "$path_url" || ynh_die "$domain/$path_url is not available, please use an other domain."
|
|
|
|
ynh_webpath_register $app "$domain" "$path_url"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# add required packages
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
|
|
|
|
|
|
|
# save app settings
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2018-10-18 05:16:40 +02:00
|
|
|
ynh_app_setting_set $app domain "$domain"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# find a free port & open it
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Looking for a free port and opening it..."
|
2018-09-25 19:03:30 +02:00
|
|
|
port=$(ynh_find_port 8123)
|
|
|
|
ynh_app_setting_set $app port $port
|
2018-10-18 05:16:40 +02:00
|
|
|
ynh_exec_fully_quiet yunohost firewall allow TCP $port
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# create a dedicated system user
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Creating dedicated user, rights and folders..."
|
2018-10-18 05:16:40 +02:00
|
|
|
ynh_system_user_create $app
|
2019-06-10 12:07:28 +02:00
|
|
|
## grant sudo permissions to the user to manage his own systemd service
|
2018-12-18 07:30:30 +01:00
|
|
|
myynh_create_dir "/etc/sudoers.d"
|
2018-12-18 22:36:54 +01:00
|
|
|
cp "../conf/sudoers" "/etc/sudoers.d/$app"
|
2019-06-10 12:07:28 +02:00
|
|
|
## create a directory for the installation of Home Assistant
|
2018-10-18 05:16:40 +02:00
|
|
|
myynh_create_dir "$final_path"
|
|
|
|
chown $app: "$final_path"
|
2019-06-10 12:07:28 +02:00
|
|
|
## create a directory for the datas of Home Assistant
|
2018-10-18 05:16:40 +02:00
|
|
|
myynh_create_dir "$data_path"
|
|
|
|
chown -R $app: "$home_path"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# installation in a virtual environment
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
2018-10-18 05:16:40 +02:00
|
|
|
exec_as $app -H -s /bin/bash -c " \
|
2018-09-25 19:03:30 +02:00
|
|
|
echo 'create the virtual environment' \
|
2018-10-18 05:16:40 +02:00
|
|
|
&& python3 -m venv "$final_path" \
|
2018-09-25 19:03:30 +02:00
|
|
|
&& echo 'activate the virtual environment' \
|
2018-10-18 05:16:40 +02:00
|
|
|
&& source "$final_path/bin/activate" \
|
2018-09-25 19:03:30 +02:00
|
|
|
&& echo 'install a required python package' \
|
2018-10-18 05:16:40 +02:00
|
|
|
&& pip install --upgrade wheel \
|
2018-09-25 19:03:30 +02:00
|
|
|
&& echo 'install Home Assistant' \
|
2020-08-12 16:51:17 +02:00
|
|
|
&& pip install --upgrade $app==$VERSION \
|
2018-09-25 19:03:30 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
# set default configuration files
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Configuring the installation..."
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_replace_string "__PORT__" "$port" "../conf/homeassistant_conf_files/configuration.yaml"
|
2019-06-09 18:30:25 +02:00
|
|
|
chmod -R +x "../conf/homeassistant_conf_files/bin/"
|
2018-09-25 19:03:30 +02:00
|
|
|
## move all homeassistant_conf_files
|
|
|
|
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
|
|
|
|
chown -R $app: "$data_path"
|
|
|
|
|
2020-08-13 20:50:44 +02:00
|
|
|
# setup up systemd service
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Adding the dedicated service..."
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_add_systemd_config --service="$app@$app"
|
2019-06-10 12:07:28 +02:00
|
|
|
## add service in admin panel
|
|
|
|
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-08-13 20:50:44 +02:00
|
|
|
# start systemd service
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Starting the Home Assistant server..."
|
2020-08-13 21:04:43 +02:00
|
|
|
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=1000
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# create a dedicated nginx config
|
2019-06-10 12:07:28 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_add_nginx_config
|
2019-06-10 12:07:28 +02:00
|
|
|
## reload nginx
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# unprotect app access if public (needed for Android app to work)
|
2020-08-12 22:22:59 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
[ $is_public -eq 1 ] && ynh_permission_update --permission "main" --add "visitors"
|
2019-06-10 12:07:28 +02:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|