1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pepettes_ynh.git synced 2024-09-03 19:56:35 +02:00

Merge pull request #4 from YunoHost-Apps/example

Example
This commit is contained in:
yalh76 2021-03-18 20:13:41 +01:00 committed by GitHub
commit 800d11aba1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 124 additions and 97 deletions

View file

@ -9,13 +9,13 @@
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview ## Overview
Pepettes is a donation form working with stripe. Pepettes is a donation form based on Stripe.
**Shipped version:** 1.0 **Shipped version:** 1.0
## Screenshots ## Screenshots
![](Link to a screenshot of this app.) (none yet)
## Demo ## Demo
@ -23,7 +23,7 @@ Pepettes is a donation form working with stripe.
## Configuration ## Configuration
How to configure this app: From an admin panel, a plain file with SSH, or any other way. How to configure this app: During the installation, or in `settings.py` after installation.
## Documentation ## Documentation
@ -44,15 +44,15 @@ Can the app be used by multiple users? yes
## Limitations ## Limitations
* Any known limitations. (none)
## Additional information ## Additional information
(none)
## Links ## Links
* Report a bug: https://github.com/YunoHost-Apps/pepettes_ynh/issues * Report a bug: https://github.com/YunoHost-Apps/pepettes_ynh/issues
* App website: -
* Upstream app repository: https://github.com/YunoHost/pepettes/ * Upstream app repository: https://github.com/YunoHost/pepettes/
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/
@ -60,7 +60,6 @@ Can the app be used by multiple users? yes
## Developer info ## 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). 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. To try the testing branch, please proceed like that.

View file

@ -1,8 +1,3 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet ;; Test complet
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
@ -17,22 +12,13 @@
prices="one_time/EUR/price_1IKuPV,recuring/EUR/price_1IKuPV" prices="one_time/EUR/price_1IKuPV,recuring/EUR/price_1IKuPV"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=0
setup_root=1 setup_root=1
setup_nourl=0 setup_nourl=0
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=CommitHash
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
port_already_use=0 port_already_use=0
change_url=1 change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH

View file

@ -1,11 +1,11 @@
command = '__FINALPATH__/venv/bin/gunicorn' command = '__FINALPATH__/venv/bin/gunicorn'
pythonpath = '__FINALPATH__' pythonpath = '__FINALPATH__'
workers = 4 workers = 4
user = '__NAME__' user = '__APP__'
bind = 'unix:__FINALPATH__/sock' bind = 'unix:__FINALPATH__/sock'
pid = '/run/gunicorn/__NAME__-pid' pid = '__FINALPATH__/__APP__-pid'
errorlog = '/var/log/__NAME__/error.log' errorlog = '/var/log/__APP__/error.log'
accesslog = '/var/log/__NAME__/access.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"' 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' loglevel = 'warning'
capture_output = True capture_output = True

View file

@ -1,13 +1,13 @@
[Unit] [Unit]
Description=Small description of the service Description=__APP__ Daemon
After=network.target After=network.target
[Service] [Service]
PIDFile=/run/gunicorn/__APP__-pid PIDFile=__FINALPATH__/__APP__-pid
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__ 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 ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true PrivateTmp=true

View file

@ -32,16 +32,6 @@
}, },
"example": "example.com" "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", "name": "is_public",
"type": "boolean", "type": "boolean",

View file

@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true true
} }
# Exit if an error occurs during the execution of the script # 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 # SPECIFIC BACKUP
#=================================================
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================

View file

@ -74,7 +74,7 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 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 # MODIFY URL IN NGINX CONF
@ -118,7 +118,8 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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 # RELOAD NGINX

View file

@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -25,7 +24,7 @@ ynh_abort_if_errors
#================================================= #=================================================
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
project_name=$YNH_APP_ARG_PROJECT_NAME project_name=$YNH_APP_ARG_PROJECT_NAME
contact_url=$YNH_APP_ARG_CONTACT_URL contact_url=$YNH_APP_ARG_CONTACT_URL
@ -108,25 +107,29 @@ ynh_add_nginx_config
ynh_script_progression --message="Configuring system user..." --weight=1 ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user # Create a system user
ynh_system_user_create --username=$app ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# INSTALL PYTHON DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing Python dependencies..."
pushd $final_path pushd $final_path
python3 -m venv venv python3 -m venv venv
venv/bin/pip install -r requirements.txt venv/bin/pip install --upgrade pip
venv/bin/pip install gunicorn venv/bin/pip install -r requirements.txt
mkdir -p /var/log/$app venv/bin/pip install gunicorn
chown -R $app:www-data /var/log/$app mkdir -p /var/log/$app
cat <<EOF >> wsgi.py chown -R $app:www-data /var/log/$app
cat <<EOF >> wsgi.py
from server import app from server import app
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()
EOF EOF
popd popd
#=================================================
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -139,17 +142,11 @@ ynh_add_systemd_config
#================================================= #=================================================
# MODIFY A CONFIG FILE # 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/gunicorn.py" --destination="$final_path/gunicorn.py"
ynh_add_config --template="../conf/settings.py" --destination="$final_path/settings.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 for price in $(echo $prices | sed "s/,/ /"); do
frequency=$(echo $price | cut -d/ -f1) frequency=$(echo $price | cut -d/ -f1)
currency=$(echo $price | cut -d/ -f2) currency=$(echo $price | cut -d/ -f2)
@ -162,19 +159,18 @@ done
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions to app files # Set permissions to app files
chown -R root: $final_path chown -R $app:www-data $final_path
chown pepettes:root $final_path chmod o=--- $final_path
chown pepettes:root $final_path/settings.py
chmod o=--- $final_path/settings.py
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 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 # START SYSTEMD SERVICE
@ -182,7 +178,7 @@ yunohost service add $app --description="A simple donation form" --log="/var/log
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # 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 # SETUP SSOWAT

View file

@ -70,9 +70,10 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE VARIOUS FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..."
# Remove the log files # Remove the log files
#ynh_secure_remove --file="/var/log/$app/" ynh_secure_remove --file="/var/log/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -24,7 +23,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression --message="Loading settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -47,6 +46,7 @@ test ! -d $final_path \
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # 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" 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 ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R root: $final_path
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -82,6 +75,29 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_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 # RESTORE SYSTEMD
#================================================= #=================================================
@ -95,21 +111,21 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 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 # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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 # 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 ynh_systemd_action --service_name=nginx --action=reload

View file

@ -18,10 +18,23 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) 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 # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) 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_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 # 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 ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing) # 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 # 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 <<EOF >> wsgi.py
from server import app
if __name__ == "__main__":
app.run()
EOF
popd
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -105,30 +134,42 @@ ynh_add_systemd_config
#================================================= #=================================================
# MODIFY A CONFIG FILE # 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
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions on app files # 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 # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 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 # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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 # RELOAD NGINX