diff --git a/check_process b/check_process index b6f01b2..755855f 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,8 @@ ;; Full test ; Manifest - domain="domain.tld" - path="/path" - is_public=1 + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 setup_sub_dir=1 @@ -13,7 +13,21 @@ upgrade=1 backup_restore=1 multi_instance=0 + incorrect_path=1 + port_already_use=0 change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + # There is no user concept in ihatemoney + Level 4=1 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 ;;; Options Email= Notification=change diff --git a/conf/nginx.conf b/conf/nginx.conf index 7c7358e..3d13167 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,10 +1,7 @@ -location __PATH__/static/ { +location PATHTOCHANGE/static/ { alias /opt/yunohost/ihatemoney/venv/lib/pythonPYTHON_VERSION/site-packages/ihatemoney/static/; } - -#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; -location __PATH__/ { - +location PATHTOCHANGE { # Force https. if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; diff --git a/manifest.json b/manifest.json index d672ea1..5e1bd73 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "https://jocelyn.delalande.fr" }, "requirements": { - "yunohost": ">= 4.2.4" + "yunohost": ">= 3.8" }, "multi_instance": false, "services": ["nginx", "mysql", "postfix"], @@ -24,17 +24,29 @@ { "name": "domain", "type": "domain", + "ask": { + "en": "Choose a domain for ihatemoney", + "fr": "Choisir un domaine pour ihatemoney" + }, "example": "example.com" }, { "name": "path", "type": "path", + "ask": { + "en": "Choose a path for ihatemoney", + "fr": "Choisir un chemin pour ihatemoney" + }, "example": "/example", "default": "/ihatemoney" }, { "name": "is_public", "type": "boolean", + "ask": { + "en": "Is it a public website ? (even if service is public, each project is protected by a password)", + "fr": "Le service est-il public ? (même dans ce cas, chaque projet est protégé par un mot de passe)" + }, "default": true } ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 8cc6629..8c54da6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,3 @@ -#================================================= -# COMMON VARIABLES -#================================================= - -# dependencies used by the app -pkg_dependencies="python3-dev python3-virtualenv libffi-dev libssl-dev supervisor virtualenv" - - - - ### Constants supervisor_conf_path="/etc/supervisor/conf.d/ihatemoney.conf" @@ -16,6 +6,23 @@ ihatemoney_conf_path="/etc/ihatemoney/ihatemoney.cfg" INSTALL_DIR="/opt/yunohost/ihatemoney" +### Functions + + +install_apt_dependencies() { + ynh_install_app_dependencies \ + python3-dev \ + python3-virtualenv \ + libffi-dev \ + libssl-dev \ + supervisor \ + virtualenv +} + +create_unix_user() { + mkdir -p /opt/yunohost + useradd ihatemoney -d /opt/yunohost/ihatemoney/ --create-home || ynh_die "User creation failed" +} create_system_dirs() { install -o ihatemoney -g ihatemoney -m 755 -d \ diff --git a/scripts/backup b/scripts/backup index b1cfaf8..7c21e82 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,39 +1,25 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Source YunoHost helpers source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} -# Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - +# Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +# Set app specific variables +dbname=$app +dbuser=$app INSTALL_DIR=/opt/yunohost/ihatemoney +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +dbpass=$(ynh_app_setting_get "$app" mysqlpwd) + # Backup conf files mkdir ./conf ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" @@ -41,18 +27,8 @@ ynh_backup "$gunicorn_conf_path" ynh_backup "$supervisor_conf_path" ynh_backup "$ihatemoney_conf_path" +# Dump the database +mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql + # Backup code and venv ynh_backup "$INSTALL_DIR" "install_dir" - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_print_info --message="Backing up the MySQL database..." - -ynh_mysql_dump_db --database="$db_name" > db.sql - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 4c389fd..8c1202c 100755 --- a/scripts/install +++ b/scripts/install @@ -1,30 +1,14 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - +# Source YunoHost 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 +app=ihatemoney # Database settings db_pwd=$(ynh_string_random) @@ -36,52 +20,12 @@ secret_key=$(ynh_string_random --length 32) mails_sender="no-reply@${domain}" +ynh_abort_if_errors -#================================================= -# 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 - +ynh_webpath_register $app $domain $path +# Configure database +ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" # Save app settings ynh_app_setting_set "$app" mysqlpwd "$db_pwd" @@ -118,23 +62,17 @@ 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" +# If app is public, add url to SSOWat conf as skipped_uris +if [[ "$is_public" -ne 0 ]]; +then + ynh_app_setting_set $app unprotected_uris "/" +fi +# Configure Nginx +configure_nginx "$domain" "$path" +# Start backend +systemctl start supervisor # Wait that gunicorn is ready to consider the install finished, that is to # avoid HTTP 502 right after installation @@ -147,26 +85,4 @@ 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 +systemctl reload nginx