mirror of
https://github.com/YunoHost-Apps/immich_ynh.git
synced 2024-09-03 20:36:24 +02:00
94 lines
4.2 KiB
Bash
Executable file
94 lines
4.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
tmpdir="$(mktemp --directory)"
|
|
ynh_setup_source --source_id="main" --dest_dir="$tmpdir"
|
|
|
|
#=================================================
|
|
# CHECK PYTHON VERSION AND COMPILE IF NEEDED
|
|
#=================================================
|
|
ynh_script_progression --message="Check Python version & compile the required one if needed..." --weight=1
|
|
|
|
py_required_major=$(cat "$tmpdir/machine-learning/Dockerfile" | grep "FROM python:" | head -n1 | cut -d':' -f2 | cut -d'-' -f1)
|
|
myynh_py_latest_from_major --python="$py_required_major"
|
|
myynh_install_python --python="$py_required_version"
|
|
|
|
#=================================================
|
|
# INSTALL NODEJS
|
|
#=================================================
|
|
ynh_script_progression --message="Installing nodejs..." --weight=1
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1
|
|
|
|
db_pwd=$(ynh_string_random)
|
|
myynh_create_psql_db
|
|
db_port=$(myynh_execute_psql_as_root --sql="\conninfo" | cut -d'"' -f8)
|
|
ynh_app_setting_set --app="$app" --key=psql_pwd --value="$db_pwd"
|
|
ynh_app_setting_set --app="$app" --key=psql_version --value="$(postgresql_version)"
|
|
ynh_app_setting_set --app="$app" --key=psql_port --value="$db_port"
|
|
|
|
#=================================================
|
|
# MAKE INSTALL
|
|
#=================================================
|
|
ynh_script_progression --message="Making install..." --weight=5
|
|
|
|
myynh_install_immich
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..."
|
|
|
|
ynh_add_config --template="env" --destination="$install_dir/env"
|
|
chmod 600 "$install_dir/env"
|
|
chown $app:$app "$install_dir/env"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
ynh_add_nginx_config
|
|
|
|
ynh_add_systemd_config --service="$app-server" --template="immich-server.service"
|
|
ynh_add_systemd_config --service="$app-microservices" --template="immich-microservices.service"
|
|
ynh_add_systemd_config --service="$app-machine-learning" --template="immich-machine-learning.service"
|
|
|
|
yunohost service add "$app-server" --description="Immich Server" --log="/var/log/$app/$app-server.log"
|
|
yunohost service add "$app-microservices" --description="Immich Microservices" --log="/var/log/$app/$app-microservices.log"
|
|
yunohost service add "$app-machine-learning" --description="Immich Machine Learning" --log="/var/log/$app/$app-machine-learning.log"
|
|
|
|
ynh_use_logrotate
|
|
|
|
ynh_add_fail2ban_config --logpath="/var/log/$app/$app-server.log" --failregex="$failregex"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name="$app-microservices" --action="start" --line_match="Immich Microservices is listening" --log_path="/var/log/$app/$app-microservices.log"
|
|
ynh_systemd_action --service_name="$app-machine-learning" --action="start" --line_match="Application startup complete" --log_path="/var/log/$app/$app-machine-learning.log"
|
|
ynh_systemd_action --service_name="$app-server" --action="start" --line_match="Immich Server is listening" --log_path="/var/log/$app/$app-server.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
ynh_script_progression --message="Installation of $app completed" --last
|