diff --git a/README.md b/README.md index 5cab32b..140c5a2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview - Pepettes is a donation form based on Stripe. **Shipped version:** 1.0 @@ -54,7 +53,6 @@ Can the app be used by multiple users? yes ## Links * Report a bug: https://github.com/YunoHost-Apps/pepettes_ynh/issues - * App website: - * Upstream app repository: https://github.com/YunoHost/pepettes/ * YunoHost website: https://yunohost.org/ @@ -62,7 +60,6 @@ Can the app be used by multiple users? yes ## Developer info -**Only if you want to use a testing branch for coding, instead of merging directly into master.** Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/pepettes_ynh/tree/testing). To try the testing branch, please proceed like that. diff --git a/check_process b/check_process index af20c83..3c806e3 100644 --- a/check_process +++ b/check_process @@ -12,7 +12,7 @@ prices="one_time/EUR/price_1IKuPV,recuring/EUR/price_1IKuPV" ; Checks pkg_linter=1 - setup_sub_dir=1 + setup_sub_dir=0 setup_root=1 setup_nourl=0 setup_private=1 diff --git a/conf/gunicorn.py b/conf/gunicorn.py index 4c88dda..db092a2 100644 --- a/conf/gunicorn.py +++ b/conf/gunicorn.py @@ -1,11 +1,11 @@ command = '__FINALPATH__/venv/bin/gunicorn' pythonpath = '__FINALPATH__' workers = 4 -user = '__NAME__' +user = '__APP__' bind = 'unix:__FINALPATH__/sock' -pid = '/run/gunicorn/__NAME__-pid' -errorlog = '/var/log/__NAME__/error.log' -accesslog = '/var/log/__NAME__/access.log' +pid = '__FINALPATH__/__APP__-pid' +errorlog = '/var/log/__APP__/error.log' +accesslog = '/var/log/__APP__/access.log' access_log_format = '%({X-Real-IP}i)s %({X-Forwarded-For}i)s %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' loglevel = 'warning' capture_output = True diff --git a/conf/systemd.service b/conf/systemd.service index 746d3db..c25b84f 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,13 +1,13 @@ [Unit] -Description=Small description of the service +Description=__APP__ Daemon After=network.target [Service] -PIDFile=/run/gunicorn/__APP__-pid +PIDFile=__FINALPATH__/__APP__-pid User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__ -ExecStart=__FINALPATH__/venv/bin/gunicorn -c __FINALPATH__/gunicorn.py wsgi:app +ExecStart=__FINALPATH__/venv/bin/gunicorn -c __FINALPATH__/gunicorn.py wsgi:app --pid __FINALPATH__/__APP__-pid ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID PrivateTmp=true diff --git a/manifest.json b/manifest.json index 3077a93..6d5d8ac 100644 --- a/manifest.json +++ b/manifest.json @@ -32,16 +32,6 @@ }, "example": "example.com" }, - { - "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for pepettes", - "fr": "Choisissez un chemin pour pepettes" - }, - "example": "/donation", - "default": "/donation" - }, { "name": "is_public", "type": "boolean", diff --git a/scripts/backup b/scripts/backup index 1400566..3beb939 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -51,8 +50,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP -#================================================= - #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/change_url b/scripts/change_url index 17802c4..cf801f6 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -74,7 +74,7 @@ fi #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped" #================================================= # MODIFY URL IN NGINX CONF @@ -118,7 +118,8 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 1e50915..cdcd2d7 100755 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -25,7 +24,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH +path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC project_name=$YNH_APP_ARG_PROJECT_NAME contact_url=$YNH_APP_ARG_CONTACT_URL @@ -108,25 +107,29 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC SETUP #================================================= +# INSTALL PYTHON DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing Python dependencies..." + pushd $final_path -python3 -m venv venv -venv/bin/pip install -r requirements.txt -venv/bin/pip install gunicorn -mkdir -p /var/log/$app -chown -R $app:www-data /var/log/$app -cat <> wsgi.py + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements.txt + venv/bin/pip install gunicorn + mkdir -p /var/log/$app + chown -R $app:www-data /var/log/$app + cat <> wsgi.py from server import app if __name__ == "__main__": app.run() EOF popd -#================================================= #================================================= # SETUP SYSTEMD @@ -139,17 +142,11 @@ ynh_add_systemd_config #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_script_progression --message="Modifying a config file..." ynh_add_config --template="../conf/gunicorn.py" --destination="$final_path/gunicorn.py" ynh_add_config --template="../conf/settings.py" --destination="$final_path/settings.py" -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/gunicorn.py" -ynh_store_file_checksum --file="$final_path/settings.py" for price in $(echo $prices | sed "s/,/ /"); do frequency=$(echo $price | cut -d/ -f1) currency=$(echo $price | cut -d/ -f2) @@ -157,24 +154,25 @@ for price in $(echo $prices | sed "s/,/ /"); do echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py" done +ynh_store_file_checksum --file="$final_path/settings.py" + #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions to app files -chown -R root: $final_path -chown pepettes:root $final_path -chown pepettes:root $final_path/settings.py -chmod o=--- $final_path/settings.py +chown -R $app:www-data $final_path +chmod o=--- $final_path #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A simple donation form" --log="/var/log/$app/$app.log" +yunohost service add $app --description="A simple donation form" --log_type="systemd" #================================================= # START SYSTEMD SERVICE @@ -182,7 +180,7 @@ yunohost service add $app --description="A simple donation form" --log="/var/log ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index a2cf263..b492b54 100755 --- a/scripts/remove +++ b/scripts/remove @@ -70,9 +70,10 @@ ynh_remove_nginx_config #================================================= # REMOVE VARIOUS FILES #================================================= +ynh_script_progression --message="Removing various files..." # Remove the log files -#ynh_secure_remove --file="/var/log/$app/" +ynh_secure_remove --file="/var/log/$app" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index a8fc3ba..6f48eb9 100755 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -24,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -47,6 +46,7 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -63,14 +63,7 @@ ynh_restore_file --origin_path="$final_path" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chown -R root: $final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC RESTORATION @@ -82,6 +75,29 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# INSTALL PYTHON DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing Python dependencies..." + +pushd $final_path + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements.txt + venv/bin/pip install gunicorn + mkdir -p /var/log/$app + chown -R $app:www-data /var/log/$app +popd + +#================================================= +# RESTORE USER RIGHTS +#================================================= +ynh_script_progression --message="Restoring user rights..." + +# Restore permissions on app files +chown -R $app:www-data $final_path +chmod o=--- $final_path + #================================================= # RESTORE SYSTEMD #================================================= @@ -95,21 +111,21 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A simple donation form" --log="/var/log/$app/$app.log" +yunohost service add $app --description="A simple donation form" --log_type="systemd" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 6ddfcb0..2428f02 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,10 +18,23 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +port=$(ynh_app_setting_get --app=$app --key=port) + +project_name=$(ynh_app_setting_get --app=$app --key=project_name) +contact_url=$(ynh_app_setting_get --app=$app --key=contact_url) +logo=$(ynh_app_setting_get --app=$app --key=logo) +favicon=$(ynh_app_setting_get --app=$app --key=favicon) +publishable_key=$(ynh_app_setting_get --app=$app --key=publishable_key) +secret_key=$(ynh_app_setting_get --app=$app --key=secret_key) +prices=$(ynh_app_setting_get --app=$app --key=prices) +secret=$(ynh_app_setting_get --app=$app --key=secret) +csrf_key=$(ynh_app_setting_get --app=$app --key=csrf_key) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -51,7 +64,7 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -86,13 +99,29 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC UPGRADE #================================================= -# ... +# UPGRADE PYTHON DEPENDENCIES #================================================= +ynh_script_progression --message="Installing Python dependencies..." + +pushd $final_path + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements.txt + venv/bin/pip install gunicorn + mkdir -p /var/log/$app + chown -R $app:www-data /var/log/$app + cat <> wsgi.py +from server import app + +if __name__ == "__main__": + app.run() +EOF +popd #================================================= # SETUP SYSTEMD @@ -105,30 +134,44 @@ ynh_add_systemd_config #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_script_progression --message="Modifying a config file..." +ynh_add_config --template="../conf/gunicorn.py" --destination="$final_path/gunicorn.py" +ynh_add_config --template="../conf/settings.py" --destination="$final_path/settings.py" + +for price in $(echo $prices | sed "s/,/ /"); do + frequency=$(echo $price | cut -d/ -f1) + currency=$(echo $price | cut -d/ -f2) + price_id=$(echo $price | cut -d/ -f3) + echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py" +done + +ynh_store_file_checksum --file="$final_path/settings.py" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions on app files -chown -R root: $final_path +chown -R $app:www-data $final_path +chmod o=--- $final_path #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A simple donation form" --log="/var/log/$app/$app.log" +yunohost service add $app --description="A simple donation form" --log_type="systemd" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started" #================================================= # RELOAD NGINX