#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= #REMOVEME? ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= #REMOVEME? domain=$YNH_APP_ARG_DOMAIN #REMOVEME? path=$YNH_APP_ARG_PATH #REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC #REMOVEME? password=$YNH_APP_ARG_PASSWORD #REMOVEME? app=$YNH_APP_INSTANCE_NAME # Secret key for cookies encryption. secret_key=$(ynh_string_random --length=32) #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= #REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 #REMOVEME? install_dir=/var/www/$app #REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path #REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path #================================================= # STORE SETTINGS FROM MANIFEST #================================================= #REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1 #REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain #REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=3 #REMOVEME? ynh_install_app_dependencies "${pkg_dependencies[@]}" #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # CREATE A MYSQL DATABASE #================================================= #REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=1 #REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) #REMOVEME? db_user=$db_name #REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name #REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # SPECIFIC SETUP #================================================= # BUILD VENV #================================================= ynh_script_progression --message="Building venv..." --weight=6 #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir __ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}" python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv") chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ## Needs $python_venv_site_packages ynh_add_nginx_config #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." #run source in a 'sub shell' ( set +o nounset source "${install_dir}/venv/bin/activate" set -o nounset python3 ../conf/hash_generator.py $password > ${install_dir}/key.txt ) hashed_password=$(cat $install_dir/key.txt) #REMOVEME? ynh_secure_remove --file="$install_dir/key.txt" #REMOVEME? ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py" chmod 640 "$install_dir/gunicorn.conf.py" chown $app:$app "$install_dir/gunicorn.conf.py" # Allows to comment some config lines if not using sub path sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)" ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg" chmod 640 "$install_dir/ihatemoney.cfg" chown $app:$app "$install_dir/ihatemoney.cfg" # Configure log directory mkdir -p "/var/log/$app" chown -R $app:$app "/var/log/$app" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="$app daemon for IHateMoney" --log=systemd #================================================= # 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" --line_match="Listening at" # line_match isn't enough because ihatemoney may stop if database upgrades for _ in {1..20}; do test -S /tmp/budget.gunicorn_$app.sock && break sleep 1 done #================================================= # SETUP SSOWAT #================================================= #REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary #REMOVEME? if [ $is_public -eq 1 ] then # Everyone can access the app. # The "main" permission is automatically created before the install script. #REMOVEME? ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last