1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/couchpotato_ynh.git synced 2024-09-03 18:16:22 +02:00

Merge pull request #19 from YunoHost-Apps/upgrade

Apply last example_ynh
This commit is contained in:
yalh76 2022-09-25 04:46:51 +02:00 committed by GitHub
commit 5167c1e1d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 337 additions and 330 deletions

View file

@ -5,7 +5,7 @@ It shall NOT be edited by hand.
# CouchPotato for YunoHost # CouchPotato for YunoHost
[![Integration level](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![Working status](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg)
[![Install CouchPotato with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=couchpotato) [![Install CouchPotato with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=couchpotato)
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*
@ -15,34 +15,38 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview ## Overview
Automatic movie downloader Download movies automatically, easily and in the best quality as soon as they are available.
**Shipped version:** 3.0.1~ynh3
**Shipped version:** 3.0.1~ynh4
## Screenshots
![Screenshot of CouchPotato](./doc/screenshots/couchpotato_interface.png)
## Disclaimers / important information ## Disclaimers / important information
* Other infos that people should be aware of, such as: * Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...),
* Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...), * Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
* Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
## Documentation and resources ## Documentation and resources
* Official app website: https://couchpota.to * Official app website: <https://couchpota.to>
* Upstream app code repository: https://github.com/CouchPotato/CouchPotatoServer * Upstream app code repository: <https://github.com/CouchPotato/CouchPotatoServer>
* YunoHost documentation for this app: https://yunohost.org/app_couchpotato * YunoHost documentation for this app: <https://yunohost.org/app_couchpotato>
* Report a bug: https://github.com/YunoHost-Apps/couchpotato_ynh/issues * Report a bug: <https://github.com/YunoHost-Apps/couchpotato_ynh/issues>
## Developer info ## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing). Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug
or or
sudo yunohost app upgrade couchpotato -u https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug sudo yunohost app upgrade couchpotato -u https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug
``` ```
**More info regarding app packaging:** https://yunohost.org/packaging_apps **More info regarding app packaging:** <https://yunohost.org/packaging_apps>

View file

@ -1,44 +1,52 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# CouchPotato pour YunoHost # CouchPotato pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg) [![Niveau d'intégration](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg)
[![Installer CouchPotato avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=couchpotato) [![Installer CouchPotato avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=couchpotato)
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer CouchPotato rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet d'installer CouchPotato rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
## Vue d'ensemble ## Vue d'ensemble
Téléchargement automatisé de film Download movies automatically, easily and in the best quality as soon as they are available.
**Version incluse :** 3.0.1~ynh3
**Version incluse :** 3.0.1~ynh4
## Captures d'écran
![Capture d'écran de CouchPotato](./doc/screenshots/couchpotato_interface.png)
## Avertissements / informations importantes ## Avertissements / informations importantes
* Other infos that people should be aware of, such as: * Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...),
* Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...), * Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
* Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
## Documentations et ressources ## Documentations et ressources
* Site officiel de l'app : https://couchpota.to * Site officiel de l'app : <https://couchpota.to>
* Dépôt de code officiel de l'app : https://github.com/CouchPotato/CouchPotatoServer * Dépôt de code officiel de l'app : <https://github.com/CouchPotato/CouchPotatoServer>
* Documentation YunoHost pour cette app : https://yunohost.org/app_couchpotato * Documentation YunoHost pour cette app : <https://yunohost.org/app_couchpotato>
* Signaler un bug : https://github.com/YunoHost-Apps/couchpotato_ynh/issues * Signaler un bug : <https://github.com/YunoHost-Apps/couchpotato_ynh/issues>
## Informations pour les développeurs ## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing). Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit. Pour essayer la branche testing, procédez comme suit.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug
ou ou
sudo yunohost app upgrade couchpotato -u https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug sudo yunohost app upgrade couchpotato -u https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug
``` ```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps **Plus d'infos sur le packaging d'applications :** <https://yunohost.org/packaging_apps>

View file

@ -11,9 +11,11 @@
setup_public=0 setup_public=0
upgrade=1 upgrade=1
# From GIT # From GIT
upgrade=1 from_commit=2a7461345d70ae231cc81a580189934626ed8c58 upgrade=0 from_commit=2a7461345d70ae231cc81a580189934626ed8c58
# 3.0.1~ynh2 # 3.0.1~ynh2
upgrade=1 from_commit=06e0d129fef72c1c43063f81ae2bef97576f7fa7 upgrade=0 from_commit=06e0d129fef72c1c43063f81ae2bef97576f7fa7
# 3.0.1~ynh3
upgrade=1 from_commit=686a590376d1b18ed38cfd4b8676d4a1cf3867fb
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=0
port_already_use=1 (5050) port_already_use=1 (5050)
@ -21,8 +23,3 @@
;;; Options ;;; Options
Email= Email=
Notification=none Notification=none
;;; Upgrade options
; commit=2a7461345d70ae231cc81a580189934626ed8c58
name=From GIT
; commit=06e0d129fef72c1c43063f81ae2bef97576f7fa7
name=3.0.1~ynh2

View file

@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME= SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -1,15 +1,16 @@
location __PATH__ { #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
proxy_http_version 1.1; location __PATH__/ {
proxy_pass_header Server; proxy_http_version 1.1;
proxy_pass http://127.0.0.1:__PORT__; proxy_pass_header Server;
proxy_redirect off; proxy_pass http://127.0.0.1:__PORT__;
proxy_set_header Host $http_host; proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host;
proxy_set_header X-Scheme $scheme; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Scheme $scheme;
proxy_set_header Connection "upgrade"; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Include SSOWAT user panel. # Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc; include conf.d/yunohost_panel.conf.inc;
more_clear_input_headers 'Accept-Encoding'; more_clear_input_headers 'Accept-Encoding';
} }

View file

@ -9,6 +9,5 @@ Group=__APP__
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__FINALPATH__/
ExecStart=/opt/pyenv/versions/__PYTHON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__DATADIR__ --config_file=__DATADIR__/settings.conf ExecStart=/opt/pyenv/versions/__PYTHON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__DATADIR__ --config_file=__DATADIR__/settings.conf
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
Download movies automatically, easily and in the best quality as soon as they are available.

View file

@ -1,3 +1,2 @@
* Other infos that people should be aware of, such as: * Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...),
* Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...), * Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
* Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

View file

@ -6,7 +6,7 @@
"en": "Automatic movie downloader", "en": "Automatic movie downloader",
"fr": "Téléchargement automatisé de film" "fr": "Téléchargement automatisé de film"
}, },
"version": "3.0.1~ynh3", "version": "3.0.1~ynh4",
"url": "https://couchpota.to/", "url": "https://couchpota.to/",
"upstream": { "upstream": {
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
@ -27,11 +27,10 @@
"nginx" "nginx"
], ],
"arguments": { "arguments": {
"install" : [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain"
"example": "example.com"
}, },
{ {
"name": "path", "name": "path",

View file

@ -4,9 +4,8 @@
# COMMON VARIABLES # COMMON VARIABLES
#================================================= #=================================================
# dependencies used by the app # dependencies used by the app (must be on a single line)
pkg_dependencies="" pkg_dependencies=""
#python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python
python_version=2.7.18 python_version=2.7.18

View file

@ -32,7 +32,7 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -43,7 +43,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." 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=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
@ -53,7 +53,7 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_script_progression --message="Finding an available port..." ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port # Find an available port
port=$(ynh_find_port --port=5050) port=$(ynh_find_port --port=5050)
@ -64,28 +64,29 @@ ynh_app_setting_set --app=$app --key=port --value=$port
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port # Open the port
# ynh_script_progression --message="Configuring firewall..." # ynh_script_progression --message="Configuring firewall..." --weight=1
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port # ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_install_python --python_version=$python_version
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Configuring system user..." ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user # Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
@ -98,7 +99,7 @@ chown -R $app:$app "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..." ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
@ -108,7 +109,7 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DATA DIRECTORY # CREATE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Creating a data directory..." ynh_script_progression --message="Creating a data directory..." --weight=1
datadir=/home/yunohost.app/$app datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir ynh_app_setting_set --app=$app --key=datadir --value=$datadir
@ -122,20 +123,19 @@ chown -R $app:$app "$datadir"
#================================================= #=================================================
# BUILD COUCHPOTATO # BUILD COUCHPOTATO
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..." --weight=1
ynh_install_python --python_version=$python_version
ynh_use_python ynh_use_python
pushd $final_path pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl ynh_pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah ynh_pip install cheetah
popd popd
#================================================= #=================================================
# INSTALL YUNOHOST MULTIMEDIA # INSTALL YUNOHOST MULTIMEDIA
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..." --weight=1
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies" mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -148,7 +148,7 @@ ynh_multimedia_addaccess $app
#================================================= #=================================================
# CONFIGURE TRANSMISSION # CONFIGURE TRANSMISSION
#================================================= #=================================================
ynh_script_progression --message="Configuring transmission..." ynh_script_progression --message="Configuring transmission..." --weight=1
# Variable initialization # Variable initialization
rpc="" rpc=""
@ -202,7 +202,7 @@ fi
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/couchpotato.conf" --destination="$datadir/settings.conf" ynh_add_config --template="../conf/couchpotato.conf" --destination="$datadir/settings.conf"
@ -212,7 +212,7 @@ chown $app:$app "$datadir/settings.conf"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -220,7 +220,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS
#================================================= #=================================================
ynh_script_progression --message="Configuring logs..." ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory # Redirect logs directory
app_logs_dir="/var/log/$app" app_logs_dir="/var/log/$app"
@ -234,7 +234,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." ynh_script_progression --message="Configuring log rotation..." --weight=1
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate
@ -242,14 +242,14 @@ ynh_use_logrotate
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log" yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." 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="/var/log/$app/$app.log"
@ -257,7 +257,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring permissions..." ynh_script_progression --message="Configuring permissions..." --weight=1
ynh_permission_update --permission="main" --add="visitors" ynh_permission_update --permission="main" --add="visitors"
@ -269,7 +269,7 @@ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --sho
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." 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
@ -277,4 +277,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" ynh_script_progression --message="Installation of $app completed" --last

View file

@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -30,14 +30,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app yunohost service remove $app
fi fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
@ -45,24 +45,15 @@ ynh_remove_systemd_config
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing logrotate configuration..." ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_python
ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..." ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file="$final_path" ynh_secure_remove --file="$final_path"
@ -70,18 +61,27 @@ ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_python
ynh_remove_app_dependencies
#================================================= #=================================================
# CLOSE A PORT # CLOSE A PORT
#================================================= #=================================================
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_script_progression --message="Closing port $port..." ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
@ -90,7 +90,7 @@ fi
#================================================= #=================================================
# REMOVE VARIOUS FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..." ynh_script_progression --message="Removing various files..." --weight=1
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"
@ -100,7 +100,7 @@ ynh_secure_remove --file="/var/log/$app"
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Removing the dedicated system user..." ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user # Delete a system user
ynh_system_user_delete --username=$app ynh_system_user_delete --username=$app
@ -109,4 +109,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" ynh_script_progression --message="Removal of $app completed" --last

View file

@ -24,7 +24,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -36,26 +36,17 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#=================================================
# 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"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Recreating the dedicated system user..." 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 --home_dir=$final_path ynh_system_user_create --username=$app --home_dir=$final_path
@ -63,7 +54,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path"
@ -74,7 +65,7 @@ chown -R $app:$app "$final_path"
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring the data directory..." ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$datadir" --not_mandatory ynh_restore_file --origin_path="$datadir" --not_mandatory
@ -89,17 +80,24 @@ chown -R $app:$app "$datadir"
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." 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
ynh_install_python --python_version=$python_version
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BUILD COUCHPOTATO # BUILD COUCHPOTATO
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..." --weight=1
ynh_install_python --python_version=$python_version
ynh_use_python ynh_use_python
pushd $final_path pushd $final_path
@ -110,7 +108,7 @@ popd
#================================================= #=================================================
# INSTALL YUNOHOST MULTIMEDIA # INSTALL YUNOHOST MULTIMEDIA
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..." --weight=1
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies" mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -123,7 +121,7 @@ ynh_multimedia_addaccess $app
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS
#================================================= #=================================================
ynh_script_progression --message="Configuring logs..." ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory # Redirect logs directory
app_logs_dir="/var/log/$app" app_logs_dir="/var/log/$app"
@ -135,7 +133,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
@ -143,21 +141,21 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log" yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a 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="/var/log/$app/$app.log"
@ -166,7 +164,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." 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
@ -174,4 +172,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -26,14 +26,14 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..." ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -49,14 +49,14 @@ ynh_abort_if_errors
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." 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="/var/log/$app/$app.log"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]; then
@ -96,10 +96,10 @@ fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." 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 --home_dir=$final_path ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -107,7 +107,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
pushd "$final_path" pushd "$final_path"
@ -119,40 +119,40 @@ chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path" chown -R $app:$app "$final_path"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
ynh_install_python --python_version=$python_version
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# BUILD COUCHPOTATO # BUILD COUCHPOTATO
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..." --weight=1
ynh_install_python --python_version=$python_version
ynh_use_python ynh_use_python
pushd $final_path pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl ynh_pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah ynh_pip install cheetah
popd popd
#================================================= #=================================================
# INSTALL YUNOHOST MULTIMEDIA # INSTALL YUNOHOST MULTIMEDIA
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..." --weight=1
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies" mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -165,7 +165,7 @@ ynh_multimedia_addaccess $app
#================================================= #=================================================
# CONFIGURE TRANSMISSION # CONFIGURE TRANSMISSION
#================================================= #=================================================
ynh_script_progression --message="Configuring transmission..." ynh_script_progression --message="Configuring transmission..." --weight=1
# Variable initialization # Variable initialization
rpc="" rpc=""
@ -219,7 +219,7 @@ fi
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_backup_if_checksum_is_different --file="$datadir/settings.conf" ynh_backup_if_checksum_is_different --file="$datadir/settings.conf"
@ -229,7 +229,7 @@ chown $app:$app "$datadir/settings.conf"
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS
#================================================= #=================================================
ynh_script_progression --message="Configuring logs..." ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory # Redirect logs directory
app_logs_dir="/var/log/$app" app_logs_dir="/var/log/$app"
@ -241,7 +241,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Upgrading systemd configuration..." ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -251,7 +251,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
@ -259,21 +259,21 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log" yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a 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="/var/log/$app/$app.log"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." 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
@ -281,4 +281,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" ynh_script_progression --message="Upgrade of $app completed" --last

View file

@ -1,20 +1,21 @@
#!/bin/bash #!/bin/bash
ynh_python_try_bash_extension() { ynh_python_try_bash_extension() {
if [ -x src/configure ]; then if [ -x src/configure ]; then
src/configure && make -C src || { src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
} }
fi fi
} }
pyenv_install_dir="/opt/pyenv" pyenv_install_dir="/opt/pyenv"
python_version_path="$pyenv_install_dir/versions" python_version_path="$pyenv_install_dir/versions"
# PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable. # PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable.
export PYENV_ROOT="$pyenv_install_dir" export PYENV_ROOT="$pyenv_install_dir"
export pyenv_root="$pyenv_install_dir"
# Required dependencies # Required dependencies
pyenv_dependencies="build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev|libedit-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git" pyenv_dependencies="make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev git"
# Load the version of Python for an app, and set variables. # Load the version of Python for an app, and set variables.
# #
@ -30,57 +31,56 @@ pyenv_dependencies="build-essential libssl-dev zlib1g-dev libbz2-dev libreadline
# Exemple: `ynh_exec_as $app $ynh_python_load_path $ynh_pip install` # Exemple: `ynh_exec_as $app $ynh_python_load_path $ynh_pip install`
# #
# $PATH contains the path of the requested version of Python. # $PATH contains the path of the requested version of Python.
# However, $PATH is duplicated into $python_path to outlast any manipulation of $PATH # However, $PATH is duplicated into $ynh_python_path to outlast any manipulation of $PATH
# You can use the variable `$ynh_python_load_path` to quickly load your Python version # You can use the variable `$ynh_python_load_path` to quickly load your Python version
# in $PATH for an usage into a separate script. # in $PATH for an usage into a separate script.
# Exemple: $ynh_python_load_path $final_path/script_that_use_pip.sh` # Exemple: $ynh_python_load_path $final_path/script_that_use_pip.sh`
# #
# #
# Finally, to start a Python service with the correct version, 2 solutions # Finally, to start a Python service with the correct version, 2 solutions
# Either the app is dependent of python or pip, but does not called it directly. # Either the app is dependent of python or pip, but does not called it directly.
# In such situation, you need to load PATH # In such situation, you need to load PATH
# `Environment="__YNH_PYTHON_LOAD_ENV_PATH__"` # `Environment="__YNH_PYTHON_LOAD_PATH__"`
# `ExecStart=__FINALPATH__/my_app` # `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_PYTHON_LOAD_ENV_PATH__ with $ynh_python_load_path # You will replace __YNH_PYTHON_LOAD_PATH__ with $ynh_python_load_path
#
# Or Python start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_PYTHON__ my_app run`
# You will replace __YNH_PYTHON__ with $ynh_python
# #
# Or Python start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_PYTHON__ my_app run`
# You will replace __YNH_PYTHON__ with $ynh_python
# #
# one other variable is also available # one other variable is also available
# - $python_path: The absolute path to Python binaries for the chosen version. # - $ynh_python_path: The absolute path to Python binaries for the chosen version.
# #
# usage: ynh_use_python # usage: ynh_use_python
# #
# Requires YunoHost version 2.7.12 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_use_python () { ynh_use_python () {
python_version=$(ynh_app_setting_get --app=$app --key=python_version) python_version=$(ynh_app_setting_get --app=$app --key=python_version)
# Get the absolute path of this version of Python # Get the absolute path of this version of Python
python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin" ynh_python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin"
# Allow alias to be used into bash script # Allow alias to be used into bash script
shopt -s expand_aliases shopt -s expand_aliases
# Create an alias for the specific version of Python and a variable as fallback # Create an alias for the specific version of Python and a variable as fallback
ynh_python="$python_path/python" ynh_python="$ynh_python_path/python"
alias ynh_python="$ynh_python" alias ynh_python="$ynh_python"
# And pip # And pip
ynh_pip="$python_path/pip" ynh_pip="$ynh_python_path/pip"
alias ynh_pip="$ynh_pip" alias ynh_pip="$ynh_pip"
# Load the path of this version of Python in $PATH # Load the path of this version of Python in $PATH
if [[ :$PATH: != *":$python_path"* ]]; then if [[ :$PATH: != *":$ynh_python_path"* ]]; then
PATH="$python_path:$PATH" PATH="$ynh_python_path:$PATH"
fi fi
# Create an alias to easily load the PATH # Create an alias to easily load the PATH
ynh_python_load_path="PATH=$PATH" ynh_python_load_path="PATH=$PATH"
# Sets the local application-specific Python version # Sets the local application-specific Python version
pushd $final_path pushd $final_path
$pyenv_install_dir/bin/pyenv local $python_version $pyenv_install_dir/bin/pyenv local $python_version
popd popd
} }
# Install a specific version of Python # Install a specific version of Python
@ -98,122 +98,123 @@ ynh_use_python () {
# usage: ynh_install_python --python_version=python_version # usage: ynh_install_python --python_version=python_version
# | arg: -v, --python_version= - Version of Python to install. # | arg: -v, --python_version= - Version of Python to install.
# #
# Requires YunoHost version 2.7.12 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_install_python () { ynh_install_python () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=v local legacy_args=v
local -A args_array=( [v]=python_version= ) local -A args_array=( [v]=python_version= )
local python_version local python_version
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
# Install required dependencies # Install required dependencies
ynh_add_app_dependencies --package="$pyenv_dependencies" ynh_add_app_dependencies --package="$pyenv_dependencies"
# Load pyenv path in PATH # Load pyenv path in PATH
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Python prior installation # Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing Python binary, to avoid to block pyenv # Move an existing Python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv #test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# Install or update pyenv # Install or update pyenv
pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)" pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)"
if [ -n "$pyenv" ]; then if [ -n "$pyenv" ]; then
ynh_print_info --message="pyenv already seems installed in \`$pyenv'." ynh_print_info --message="pyenv already seems installed in \`$pyenv'."
pushd "${pyenv%/*/*}" pushd "${pyenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then
echo "Trying to update with git..." ynh_print_info --message="Trying to update with git..."
git pull -q --tags origin master git pull -q --tags origin master
cd .. cd ..
ynh_python_try_bash_extension ynh_python_try_bash_extension
fi fi
popd popd
else else
ynh_print_info --message="Installing pyenv with git..." ynh_print_info --message="Installing pyenv with git..."
mkdir -p $pyenv_install_dir mkdir -p $pyenv_install_dir
pushd $pyenv_install_dir pushd $pyenv_install_dir
git init -q git init -q
git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1 git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1
git checkout -q -b master origin/master git checkout -q -b master origin/master
ynh_python_try_bash_extension ynh_python_try_bash_extension
pyenv=$pyenv_install_dir/bin/pyenv pyenv=$pyenv_install_dir/bin/pyenv
popd popd
fi fi
pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)" pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)"
if [ -n "$pyenv_virtualenv" ]; then if [ -n "$pyenv_virtualenv" ]; then
ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'." ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'."
pushd "${pyenv_virtualenv%/*/*}" pushd "${pyenv_virtualenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv-virtualenv.git"; then if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv-virtualenv.git"; then
ynh_print_info --message="Trying to update pyenv-virtualenv with git..." ynh_print_info --message="Trying to update pyenv-virtualenv with git..."
git pull -q origin master git pull -q origin master
fi fi
popd popd
else else
ynh_print_info --message="Installing pyenv-virtualenv with git..." ynh_print_info --message="Installing pyenv-virtualenv with git..."
mkdir -p "${pyenv_install_dir}/plugins" mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv" git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv"
fi fi
pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)" pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)"
if [ -n "$pyenv_latest" ]; then if [ -n "$pyenv_latest" ]; then
ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'." ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'."
pushd "${pyenv_latest%/*/*}" pushd "${pyenv_latest%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
ynh_print_info --message="Trying to update xxenv-latest with git..." ynh_print_info --message="Trying to update xxenv-latest with git..."
git pull -q origin master git pull -q origin master
fi fi
popd popd
else else
ynh_print_info --message="Installing xxenv-latest with git..." ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${pyenv_install_dir}/plugins" mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest" git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest"
fi fi
# Enable caching # Enable caching
mkdir -p "${pyenv_install_dir}/cache" mkdir -p "${pyenv_install_dir}/cache"
# Create shims directory if needed # Create shims directory if needed
mkdir -p "${pyenv_install_dir}/shims" mkdir -p "${pyenv_install_dir}/shims"
chmod -R a+w "${pyenv_install_dir}/shims"
# Restore /usr/local/bin in PATH # Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH PATH=$CLEAR_PATH
# And replace the old Python binary # And replace the old Python binary
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python # test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# Install the requested version of Python # Install the requested version of Python
local final_python_version=$(pyenv latest --print $python_version) local final_python_version=$(pyenv latest --print $python_version)
ynh_print_info --message="Installation of Python-$python_version" ynh_print_info --message="Installation of Python-$python_version"
ynh_exec_warn_less pyenv install --skip-existing $final_python_version > /dev/null 2>&1 pyenv install --skip-existing $final_python_version > /dev/null 2>&1
# Store python_version into the config of this app # Store python_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version
# Remove app virtualenv # Remove app virtualenv
if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1`
then then
pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
fi fi
# Create app virtualenv # Create app virtualenv
pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME
# Cleanup Python versions # Cleanup Python versions
ynh_cleanup_python ynh_cleanup_python
# Set environment for Python users # Set environment for Python users
echo "#pyenv echo "#pyenv
export PYENV_ROOT=$pyenv_install_dir export PYENV_ROOT=$pyenv_install_dir
export PATH=\"$pyenv_install_dir/bin:$PATH\" export PATH=\"$pyenv_install_dir/bin:$PATH\"
eval \"\$(pyenv init -)\" eval \"\$(pyenv init -)\"
#pyenv" > /etc/profile.d/pyenv.sh #pyenv" > /etc/profile.d/pyenv.sh
# Load the environment # Load the environment
eval "$(pyenv init -)" eval "$(pyenv init -)"
} }
# Remove the version of Python used by the app. # Remove the version of Python used by the app.
@ -222,21 +223,21 @@ eval \"\$(pyenv init -)\"
# #
# usage: ynh_remove_python # usage: ynh_remove_python
ynh_remove_python () { ynh_remove_python () {
local python_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=python_version) local python_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=python_version)
# Load pyenv path in PATH # Load pyenv path in PATH
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Python prior installation # Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
# Remove the line for this app # Remove the line for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version
# Cleanup Python versions # Cleanup Python versions
ynh_cleanup_python ynh_cleanup_python
} }
# Remove no more needed versions of Python used by the app. # Remove no more needed versions of Python used by the app.
@ -248,35 +249,35 @@ ynh_remove_python () {
# usage: ynh_cleanup_python # usage: ynh_cleanup_python
ynh_cleanup_python () { ynh_cleanup_python () {
# List required Python version # List required Python versions
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
local required_python_versions="" local required_python_versions=""
for installed_app in $installed_apps for installed_app in $installed_apps
do do
local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version") local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version")
if [[ $installed_app_python_version ]] if [[ $installed_app_python_version ]]
then then
required_python_versions="${installed_app_python_version}\n${required_python_versions}" required_python_versions="${installed_app_python_version}\n${required_python_versions}"
fi fi
done done
# Remove no more needed Python version # Remove no more needed Python versions
local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/') local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/')
for installed_python_version in $installed_python_versions for installed_python_version in $installed_python_versions
do do
if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1` if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1`
then then
ynh_print_info --message="Removing of Python-$installed_python_version" ynh_print_info --message="Removing of Python-$installed_python_version"
$pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version $pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version
fi fi
done done
# If none Python version is required # If none Python version is required
if [[ ! $required_python_versions ]] if [[ ! $required_python_versions ]]
then then
# Remove pyenv environment configuration # Remove pyenv environment configuration
ynh_print_info --message="Removing of pyenv-$pyenv_version" ynh_print_info --message="Removing of pyenv-$pyenv_version"
ynh_secure_remove --file="$pyenv_install_dir" ynh_secure_remove --file="$pyenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/pyenv.sh" ynh_secure_remove --file="/etc/profile.d/pyenv.sh"
fi fi
} }