#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INITIALIZE AND STORE SETTINGS #================================================= secretkey=$(ynh_string_random --length=12) ynh_app_setting_set --app=$app --key=secretkey --value="$secretkey" #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing NodeJS..." --weight=3 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # CREATE A PostgreSQL DATABASE #================================================= ynh_script_progression --message="Configuring a PostgreSQL database..." --weight=1 ynh_psql_execute_as_root --sql="GRANT ALL PRIVILEGES ON DATABASE $db_name TO $db_user;" ynh_psql_execute_as_root --sql="ALTER DATABASE $db_name OWNER TO $db_user;" ynh_psql_execute_as_root --sql="ALTER USER $db_name WITH SUPERUSER;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/source" chown -R "$app:www-data" "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="dot_env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" chown "$app:$app" "$install_dir/.env" version=$(ynh_app_upstream_version) ynh_add_config --template="version.py" --destination="$install_dir/source/recipes/version.py" chmod 400 "$install_dir/source/recipes/version.py" chown "$app:$app" "$install_dir/source/recipes/version.py" #================================================= # SPECIFIC SETUP #================================================= ynh_script_progression --message="Building frontend..." --weight=5 _tandoor_build_frontend ynh_script_progression --message="Installing Tandoor and its python dependencies..." --weight=1 _tandoor_venv_install ynh_script_progression --message="Running migrations and generating static files..." --weight=2 pushd "$install_dir/source" ( source "$install_dir/.env" ynh_exec_as "$app" "$venvpy" manage.py migrate ynh_psql_execute_as_root --sql="ALTER USER $app WITH NOSUPERUSER;" ynh_exec_as "$app" "$venvpy" manage.py collectstatic --no-input ynh_exec_as "$app" "$venvpy" manage.py collectstatic_js_reverse ) popd #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config yunohost service add "$app" --description="Smart recipe management" --log="/var/log/$app/$app.log" # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last