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

Apply last example_ynh

This commit is contained in:
yalh76 2022-09-23 23:16:42 +02:00
parent 686a590376
commit b3b7d07d0c
13 changed files with 294 additions and 296 deletions

View file

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

View file

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

View file

@ -9,6 +9,5 @@ Group=__APP__
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
[Install]
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 [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure
* 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

View file

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

View file

@ -4,9 +4,8 @@
# COMMON VARIABLES
#=================================================
# dependencies used by the app
# dependencies used by the app (must be on a single line)
pkg_dependencies=""
#python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python
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
#=================================================
ynh_script_progression --message="Validating installation parameters..."
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -43,7 +43,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# 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=path --value=$path_url
@ -53,7 +53,7 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# 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
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 !)
# 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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
ynh_install_python --python_version=$python_version
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
ynh_script_progression --message="Configuring system user..." --weight=1
# 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
#=================================================
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
# Download, check integrity, uncompress and patch the source from app.src
@ -98,7 +99,7 @@ chown -R $app:$app "$final_path"
#=================================================
# 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
ynh_add_nginx_config
@ -108,7 +109,7 @@ ynh_add_nginx_config
#=================================================
# 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
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
@ -122,20 +123,19 @@ chown -R $app:$app "$datadir"
#=================================================
# 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
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah
ynh_pip install --upgrade pyopenssl
ynh_pip install cheetah
popd
#=================================================
# 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"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -148,7 +148,7 @@ ynh_multimedia_addaccess $app
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Configuring transmission..."
ynh_script_progression --message="Configuring transmission..." --weight=1
# Variable initialization
rpc=""
@ -202,7 +202,7 @@ fi
#=================================================
# 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"
@ -212,7 +212,7 @@ chown $app:$app "$datadir/settings.conf"
#=================================================
# 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
ynh_add_systemd_config
@ -220,7 +220,7 @@ ynh_add_systemd_config
#=================================================
# CONFIGURE LOGS
#=================================================
ynh_script_progression --message="Configuring logs..."
ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory
app_logs_dir="/var/log/$app"
@ -234,7 +234,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#=================================================
# 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)
ynh_use_logrotate
@ -242,14 +242,14 @@ ynh_use_logrotate
#=================================================
# 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"
#=================================================
# 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
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
#=================================================
ynh_script_progression --message="Configuring permissions..."
ynh_script_progression --message="Configuring permissions..." --weight=1
ynh_permission_update --permission="main" --add="visitors"
@ -269,7 +269,7 @@ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --sho
#=================================================
# 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
@ -277,4 +277,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# 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
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
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`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..."
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
#=================================================
# 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
ynh_remove_systemd_config
@ -45,24 +45,15 @@ ynh_remove_systemd_config
#=================================================
# 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
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
#=================================================
ynh_script_progression --message="Removing app main directory..."
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -70,18 +61,27 @@ ynh_secure_remove --file="$final_path"
#=================================================
# 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
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
#=================================================
if yunohost firewall list | grep -q "\- $port$"
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
fi
@ -90,7 +90,7 @@ fi
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
ynh_script_progression --message="Removing various files..." --weight=1
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
@ -100,7 +100,7 @@ ynh_secure_remove --file="/var/log/$app"
#=================================================
# 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
ynh_system_user_delete --username=$app
@ -109,4 +109,4 @@ ynh_system_user_delete --username=$app
# 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
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
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
#=================================================
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 \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# 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
#=================================================
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)
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
#=================================================
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"
@ -74,7 +65,7 @@ chown -R $app:$app "$final_path"
#=================================================
# 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
@ -89,17 +80,24 @@ chown -R $app:$app "$datadir"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install 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
#=================================================
ynh_script_progression --message="Building CouchPotato..."
ynh_script_progression --message="Building CouchPotato..." --weight=1
ynh_install_python --python_version=$python_version
ynh_use_python
pushd $final_path
@ -110,7 +108,7 @@ popd
#=================================================
# 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"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -123,7 +121,7 @@ ynh_multimedia_addaccess $app
#=================================================
# CONFIGURE LOGS
#=================================================
ynh_script_progression --message="Configuring logs..."
ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory
app_logs_dir="/var/log/$app"
@ -135,7 +133,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#=================================================
# 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"
systemctl enable $app.service --quiet
@ -143,21 +141,21 @@ systemctl enable $app.service --quiet
#=================================================
# 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"
#=================================================
# 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"
#=================================================
# 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"
@ -166,7 +164,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#=================================================
# 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
@ -174,4 +172,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# 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
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
@ -26,14 +26,14 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# 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
ynh_backup_before_upgrade
@ -49,14 +49,14 @@ ynh_abort_if_errors
#=================================================
# 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"
#=================================================
# 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 [ -z "$final_path" ]; then
@ -96,10 +96,10 @@ fi
#=================================================
# 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)
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
@ -107,7 +107,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
if [ "$upgrade_type" == "UPGRADE_APP" ]
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
pushd "$final_path"
@ -119,40 +119,40 @@ chmod 750 "$final_path"
chmod -R o-rwx "$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
#=================================================
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
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# 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
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah
ynh_pip install --upgrade pyopenssl
ynh_pip install cheetah
popd
#=================================================
# 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"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
@ -165,7 +165,7 @@ ynh_multimedia_addaccess $app
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Configuring transmission..."
ynh_script_progression --message="Configuring transmission..." --weight=1
# Variable initialization
rpc=""
@ -219,7 +219,7 @@ fi
#=================================================
# 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"
@ -229,7 +229,7 @@ chown $app:$app "$datadir/settings.conf"
#=================================================
# CONFIGURE LOGS
#=================================================
ynh_script_progression --message="Configuring logs..."
ynh_script_progression --message="Configuring logs..." --weight=1
# Redirect logs directory
app_logs_dir="/var/log/$app"
@ -241,7 +241,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
@ -251,7 +251,7 @@ ynh_add_systemd_config
#=================================================
# 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)
ynh_use_logrotate --non-append
@ -259,21 +259,21 @@ ynh_use_logrotate --non-append
#=================================================
# 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"
#=================================================
# 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"
#=================================================
# 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
@ -281,4 +281,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# 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
ynh_python_try_bash_extension() {
if [ -x src/configure ]; then
src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
}
fi
if [ -x src/configure ]; then
src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
}
fi
}
pyenv_install_dir="/opt/pyenv"
python_version_path="$pyenv_install_dir/versions"
# 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"
# 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.
#
@ -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`
#
# $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
# 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`
#
#
# 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.
# In such situation, you need to load PATH
# `Environment="__YNH_PYTHON_LOAD_ENV_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_PYTHON_LOAD_ENV_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
# Either the app is dependent of python or pip, but does not called it directly.
# In such situation, you need to load PATH
# `Environment="__YNH_PYTHON_LOAD_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# 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
#
# 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
#
# Requires YunoHost version 2.7.12 or higher.
# Requires YunoHost version 3.2.2 or higher.
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
python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin"
# Get the absolute path of this version of Python
ynh_python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin"
# Allow alias to be used into bash script
shopt -s expand_aliases
# Allow alias to be used into bash script
shopt -s expand_aliases
# Create an alias for the specific version of Python and a variable as fallback
ynh_python="$python_path/python"
alias ynh_python="$ynh_python"
# And pip
ynh_pip="$python_path/pip"
alias ynh_pip="$ynh_pip"
# Create an alias for the specific version of Python and a variable as fallback
ynh_python="$ynh_python_path/python"
alias ynh_python="$ynh_python"
# And pip
ynh_pip="$ynh_python_path/pip"
alias ynh_pip="$ynh_pip"
# Load the path of this version of Python in $PATH
if [[ :$PATH: != *":$python_path"* ]]; then
PATH="$python_path:$PATH"
fi
# Create an alias to easily load the PATH
ynh_python_load_path="PATH=$PATH"
# Load the path of this version of Python in $PATH
if [[ :$PATH: != *":$ynh_python_path"* ]]; then
PATH="$ynh_python_path:$PATH"
fi
# Create an alias to easily load the PATH
ynh_python_load_path="PATH=$PATH"
# Sets the local application-specific Python version
pushd $final_path
$pyenv_install_dir/bin/pyenv local $python_version
popd
# Sets the local application-specific Python version
pushd $final_path
$pyenv_install_dir/bin/pyenv local $python_version
popd
}
# Install a specific version of Python
@ -98,122 +98,123 @@ ynh_use_python () {
# usage: ynh_install_python --python_version=python_version
# | 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 () {
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=python_version= )
local python_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=python_version= )
local python_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Install required dependencies
ynh_add_app_dependencies --package="$pyenv_dependencies"
# Install required dependencies
ynh_add_app_dependencies --package="$pyenv_dependencies"
# Load pyenv path in PATH
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Load pyenv path in PATH
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing Python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# Move an existing Python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# Install or update pyenv
pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)"
if [ -n "$pyenv" ]; then
ynh_print_info --message="pyenv already seems installed in \`$pyenv'."
pushd "${pyenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then
echo "Trying to update with git..."
git pull -q --tags origin master
cd ..
ynh_python_try_bash_extension
fi
popd
else
ynh_print_info --message="Installing pyenv with git..."
mkdir -p $pyenv_install_dir
pushd $pyenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_python_try_bash_extension
pyenv=$pyenv_install_dir/bin/pyenv
popd
fi
# Install or update pyenv
pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)"
if [ -n "$pyenv" ]; then
ynh_print_info --message="pyenv already seems installed in \`$pyenv'."
pushd "${pyenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then
ynh_print_info --message="Trying to update with git..."
git pull -q --tags origin master
cd ..
ynh_python_try_bash_extension
fi
popd
else
ynh_print_info --message="Installing pyenv with git..."
mkdir -p $pyenv_install_dir
pushd $pyenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_python_try_bash_extension
pyenv=$pyenv_install_dir/bin/pyenv
popd
fi
pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)"
if [ -n "$pyenv_virtualenv" ]; then
ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'."
pushd "${pyenv_virtualenv%/*/*}"
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..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing pyenv-virtualenv with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv"
fi
pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)"
if [ -n "$pyenv_virtualenv" ]; then
ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'."
pushd "${pyenv_virtualenv%/*/*}"
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..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing pyenv-virtualenv with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv"
fi
pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)"
if [ -n "$pyenv_latest" ]; then
ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'."
pushd "${pyenv_latest%/*/*}"
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..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest"
fi
pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)"
if [ -n "$pyenv_latest" ]; then
ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'."
pushd "${pyenv_latest%/*/*}"
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..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest"
fi
# Enable caching
mkdir -p "${pyenv_install_dir}/cache"
# Enable caching
mkdir -p "${pyenv_install_dir}/cache"
# Create shims directory if needed
mkdir -p "${pyenv_install_dir}/shims"
# Create shims directory if needed
mkdir -p "${pyenv_install_dir}/shims"
chmod -R a+w "${pyenv_install_dir}/shims"
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# And replace the old Python binary
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# And replace the old Python binary
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# Install the requested version of Python
local final_python_version=$(pyenv latest --print $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
# Install the requested version of Python
local final_python_version=$(pyenv latest --print $python_version)
ynh_print_info --message="Installation of Python-$python_version"
pyenv install --skip-existing $final_python_version > /dev/null 2>&1
# Store python_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version
# Store python_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version
# Remove app virtualenv
if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1`
then
pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
fi
# Remove app virtualenv
if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1`
then
pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
fi
# Create app virtualenv
pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME
# Create app virtualenv
pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME
# Cleanup Python versions
ynh_cleanup_python
# Cleanup Python versions
ynh_cleanup_python
# Set environment for Python users
echo "#pyenv
# Set environment for Python users
echo "#pyenv
export PYENV_ROOT=$pyenv_install_dir
export PATH=\"$pyenv_install_dir/bin:$PATH\"
eval \"\$(pyenv init -)\"
#pyenv" > /etc/profile.d/pyenv.sh
# Load the environment
eval "$(pyenv init -)"
# Load the environment
eval "$(pyenv init -)"
}
# Remove the version of Python used by the app.
@ -222,21 +223,21 @@ eval \"\$(pyenv init -)\"
#
# usage: 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
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Load pyenv path in PATH
local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Remove /usr/local/bin in PATH in case of Python prior installation
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
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version
# Remove the line for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version
# Cleanup Python versions
ynh_cleanup_python
# Cleanup Python versions
ynh_cleanup_python
}
# Remove no more needed versions of Python used by the app.
@ -248,35 +249,35 @@ ynh_remove_python () {
# usage: ynh_cleanup_python
ynh_cleanup_python () {
# List required Python version
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
local required_python_versions=""
for installed_app in $installed_apps
do
local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version")
if [[ $installed_app_python_version ]]
then
required_python_versions="${installed_app_python_version}\n${required_python_versions}"
fi
done
# List required Python versions
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
local required_python_versions=""
for installed_app in $installed_apps
do
local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version")
if [[ $installed_app_python_version ]]
then
required_python_versions="${installed_app_python_version}\n${required_python_versions}"
fi
done
# Remove no more needed Python version
local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/')
for installed_python_version in $installed_python_versions
do
if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Python-$installed_python_version"
$pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version
fi
done
# Remove no more needed Python versions
local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/')
for installed_python_version in $installed_python_versions
do
if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Python-$installed_python_version"
$pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version
fi
done
# If none Python version is required
if [[ ! $required_python_versions ]]
then
# Remove pyenv environment configuration
ynh_print_info --message="Removing of pyenv-$pyenv_version"
ynh_secure_remove --file="$pyenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/pyenv.sh"
fi
}
# If none Python version is required
if [[ ! $required_python_versions ]]
then
# Remove pyenv environment configuration
ynh_print_info --message="Removing of pyenv-$pyenv_version"
ynh_secure_remove --file="$pyenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/pyenv.sh"
fi
}