#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME # Database settings db_pwd=$(ynh_string_random) db_name=$app db_user=$app # Constant arguments secret_key=$(ynh_string_random --length 32) mails_sender="no-reply@${domain}" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." --time --weight=1 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name # Save app settings ynh_app_setting_set "$app" mysqlpwd "$db_pwd" ynh_app_setting_set "$app" is_public "$is_public" install_apt_dependencies create_unix_user # Prepare venv init_virtualenv pip_install create_system_dirs # Configure gunicorn install -o ihatemoney -g ihatemoney -m 644 \ ../conf/gunicorn.conf.py /etc/ihatemoney/gunicorn.conf.py # Configure supervisor configure_supervisor # In case it was already installed before, # so that it picks /etc/supervisor/conf.d/ihatemoney.conf: supervisorctl update yunohost service add supervisor # Configure ihatemoney ynh_replace_string "MY_SECRET_KEY" "$secret_key" ../conf/ihatemoney.cfg ynh_replace_string "MY_EMAIL" "$mails_sender" ../conf/ihatemoney.cfg ynh_replace_string "MY_MYSQL_PW" "$db_pwd" ../conf/ihatemoney.cfg ynh_replace_string "MY_PATH" "$path" ../conf/ihatemoney.cfg # Remove the conf directive if served at root sed -i "/APPLICATION_ROOT='\/'/d" ../conf/ihatemoney.cfg install -o ihatemoney -g ihatemoney -m 640 \ ../conf/ihatemoney.cfg /etc/ihatemoney/ihatemoney.cfg #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 # Start a systemd service ynh_systemd_action --service_name=supervisor --action="start" --log_path="/var/log/$app/$app.log" # Wait that gunicorn is ready to consider the install finished, that is to # avoid HTTP 502 right after installation for i in `seq 1 120` do test -S /tmp/budget.gunicorn.sock && break sleep 1 done # If socket not ready after 2 minutes waiting, ihatemoney will not work. test -S /tmp/budget.gunicorn.sock || ynh_die #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last