From ba9b7ebc6183f1f952c4e3b52763a4bd481acad8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 16 Jun 2020 05:29:50 +0200 Subject: [PATCH 01/14] apply example_ynh --- README.md | 50 +++-- check_process | 67 ++++--- conf/app.src | 6 + conf/multimedia.src | 6 + conf/pythonz.src | 6 + conf/systemd.service | 6 +- issue_template.md | 46 +++++ manifest.json | 87 ++++---- pull_request_template.md | 18 ++ scripts/_common.sh | 22 +++ scripts/backup | 85 ++++++-- scripts/install | 414 ++++++++++++++++++++++++++------------- scripts/remove | 140 +++++++++---- scripts/restore | 222 ++++++++++++++------- scripts/upgrade | 297 ++++++++++++++++++++-------- 15 files changed, 1035 insertions(+), 437 deletions(-) create mode 100644 conf/app.src create mode 100644 conf/multimedia.src create mode 100644 conf/pythonz.src create mode 100644 issue_template.md create mode 100644 pull_request_template.md create mode 100644 scripts/_common.sh diff --git a/README.md b/README.md index c3bf03f..def40eb 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,32 @@ -## couchpotato_ynh +## CouchPotato -[![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) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg) +[![Install CouchPotato with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=couchpotato) -[![Latest Version](https://img.shields.io/badge/version-_--_-green.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh/releases) -[![Status](https://img.shields.io/badge/status-in_progress-yellow.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh/milestones) -[![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh#dependencies) -[![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/Snipees/couchpotato_ynh/master/LICENSE) -[![Yunohost version](https://img.shields.io/badge/yunohost-2.4.2_tested-orange.svg?style=flat)](https://github.com/YunoHost/yunohost) -[![GitHub issues](https://img.shields.io/github/issues/YunoHost-Apps/couchpotato_ynh.svg?style=flat)](https://github.com/YunoHost-Apps/couchpotato_ynh/issues) - -[ **CouchPotato Integration for Yunohost** ] +> *This package allows you to install CouchPotato quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* + +## Overview Download movies automatically, easily and in the best quality as soon as they are available. - 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 -### How to install: -- Use **Install software** option from Yunohost admin panel -- Find textbox tagged as **Install custom App from github** -- Copy and paste: https://github.com/YunoHost-Apps/couchpotato_ynh +**Shipped version:** 3.0.1 +## YunoHost specific features -### More information about: -- CouchPotato : https://couchpota.to -- Yunohost : https://yunohost.org +#### Supported architectures +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/couchpotato%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/couchpotato/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/couchpotato%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/couchpotato/) + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/couchpotato_ynh/issues + * App website: https://couchpota.to + * Upstream app repository: https://github.com/CouchPotato/CouchPotatoServer + * YunoHost website: https://yunohost.org/ #### Special Thanks to the Yunohost Community: [Snipees](https://github.com/Snipees) @@ -47,3 +49,17 @@ Download movies automatically, easily and in the best quality as soon as they ar [scith](https://github.com/scith), [tifred](https://github.com/drfred1981), ... :dizzy: + +--- + +Developer info +---------------- + +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. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug +or +sudo yunohost app upgrade couchpotato -u https://github.com/YunoHost-Apps/couchpotato_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 6ea04f6..1c48cbc 100644 --- a/check_process +++ b/check_process @@ -1,35 +1,34 @@ -;; Test CouchPotato - auto_remove=1 - ; Manifest - domain="domain.tld" (DOMAIN) - path="/couchpotato" (PATH)" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=1 - backup_restore=1 - multi_instance=0 - wrong_user=0 - wrong_path=1 - incorrect_path=1 - corrupt_source=0 - fail_download_source=0 - port_already_use=1 (5050) - final_path_already_use=0 +# See here for more information +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/couchpotato" (PATH)" + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=0 + upgrade=1 + upgrade=1 from_commit=2a7461345d70ae231cc81a580189934626ed8c58 + backup_restore=1 + multi_instance=0 + # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. + # incorrect_path=1 + port_already_use=1 (5050) + change_url=0 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - # The app is single-user and does not support LDAP. It is therefore protected behind SSO. - Level 4=1 - # See https://github.com/YunoHost/package_linter/issues/15 - Level 5=1 - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 + # If the level 5 (Package linter) is forced to 1. Please add justifications here. + Level 5=auto +;;; Options +Email= +Notification=none +;;; Upgrade options + ; commit=2a7461345d70ae231cc81a580189934626ed8c58 + name=From GIT + diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..03aa940 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/CouchPotato/CouchPotatoServer/archive/build/3.0.1.tar.gz +SOURCE_SUM=f08f9c6ac02f66c6667f17ded1eea4c051a62bbcbadd2a8673394019878e92f7 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/multimedia.src b/conf/multimedia.src new file mode 100644 index 0000000..54c3617 --- /dev/null +++ b/conf/multimedia.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/YunoHost-Apps/yunohost.multimedia/archive/v1.2.tar.gz +SOURCE_SUM=7dfc07e32d7842f87274ef780cb9757a7679573cbbeb095c5f86ef76806f5d95 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/pythonz.src b/conf/pythonz.src new file mode 100644 index 0000000..fd43a3e --- /dev/null +++ b/conf/pythonz.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/saghul/pythonz/archive/9067f35e0253b015eb51b8a4d60c0bd1a06dcc83.tar.gz +SOURCE_SUM=ce9eb5400fff81e4877e04dd7166c764d8adc999d9ca6b06ce933ee9375b8652 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/systemd.service b/conf/systemd.service index e0ae36c..80314b3 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -3,10 +3,10 @@ Description=CouchPotato application instance After=network.target [Service] -ExecStart=__PYTHON__ __APPDIR__/CouchPotato.py --quiet --pid_file=__PIDFILE__ --data_dir=__DATADIR__ --config_file=__CONFIGFILE__ +ExecStart=__FINALPATH__/ve2/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf Type=simple -User=__USER__ -Group=__USER__ +User=__APP__ +Group=__APP__ [Install] WantedBy=multi-user.target diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 0000000..5f7e006 --- /dev/null +++ b/issue_template.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *Otherwise, the issue may be due to CouchPotato itself. Refer to its documentation or repository for help.* + - *If you have a doubt, post here, we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +**Describe the bug** +*A clear and concise description of what the bug is.* + +**Versions** +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +**To Reproduce** +*Steps to reproduce the behavior.* +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install couchpotato + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '....'* + 3. *Scroll down to '....'* + 4. *See error* + +**Expected behavior** +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +**Logs** +*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index d46f55a..29c99dd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,44 +1,47 @@ { - "packaging_format": 1, - "name": "CouchPotato", - "id": "couchpotato", - "description": { - "en": "Automatic movie downloader", - "fr": "Téléchargement automatisé de film" - }, - "url": "https://couchpota.to/", - "license": "free", - "maintainer": { - "name": "Snipees", - "email": "snipees@wareziens.net", - "url": "https://github.com/Snipees" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "requirements": { - "yunohost": ">= 2.4.0" - }, - "arguments": { - "install": [ - { - "name": "domain", - "ask": { - "en": "Choose a domain for CouchPotato", - "fr": "Choisissez un domaine pour CouchPotato" - }, - "example": "mydomain.org" - }, - { - "name": "path", - "ask": { - "en": "Choose a path for CouchPotato", - "fr": "Choisissez un chemin pour CouchPotato" - }, - "example": "/couchpotato", - "default": "/couchpotato" - } - ] - } + "name": "CouchPotato", + "id": "couchpotato", + "packaging_format": 1, + "description": { + "en": "Automatic movie downloader", + "fr": "Téléchargement automatisé de film" + }, + "version": "3.0.1~ynh1", + "url": "https://couchpota.to/", + "license": "free", + "maintainer": { + "name": "Snipees", + "email": "snipees@wareziens.net", + "url": "https://github.com/Snipees" + }, + "requirements": { + "yunohost": ">= 3.5" + }, + "multi_instance": false, + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain for CouchPotato", + "fr": "Choisissez un domaine pour CouchPotato" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for CouchPotato", + "fr": "Choisissez un chemin pour CouchPotato" + }, + "example": "/couchpotato", + "default": "/couchpotato" + } + ] + } } diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..0797d3d --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,18 @@ +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/couchpotato_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/couchpotato_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..f2a44ac --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python" + +python_version=2.7.2 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index 740ef1f..710fad2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,25 +1,76 @@ #!/bin/bash - set -eu - app=$YNH_APP_INSTANCE_NAME -# Source app helpers - source /usr/share/yunohost/helpers +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Common variable declaration - app_install_dir="/opt/yunohost/$app" - app_data_dir="/home/yunohost.app/$app" +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers -# Retrieve arguments - domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Backup sources - ynh_backup "$app_install_dir" "sources" +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info --message="Loading installation settings..." + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# BACKUP VARIOUS FILES +#================================================= # Backup data - ynh_backup "$app_data_dir" "data" - -# Backup daemon - ynh_backup "/etc/systemd/system/$app.service" "$app.service" +ynh_backup --src_path="$app_data_dir" -# Copy the conf files - ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 0ba28fe..f416ae6 100644 --- a/scripts/install +++ b/scripts/install @@ -1,160 +1,304 @@ #!/bin/bash - set -eu - app=$YNH_APP_INSTANCE_NAME - source="https://github.com/CouchPotato/CouchPotatoServer" +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers -# Source app helpers - source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Retrieve arguments - domain=$YNH_APP_ARG_DOMAIN - path=$YNH_APP_ARG_PATH +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors -# Correct path: puts a / at the start and nothing at the end - if [ "${path:0:1}" != "/" ]; then - path="/$path" - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then - path="${path:0:${#path}-1}" - fi +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= -# Check domain/path availability - sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH -# Destinations definitions - app_install_dir="/opt/yunohost/$app" - app_data_dir="/home/yunohost.app/$app" - app_logs_dir="/var/log/$app" - app_config_file="${app_data_dir}/settings.conf" - app_pid_file="/var/run/$app/$app.pid" - app_python_bin="/usr/bin/python" +app=$YNH_APP_INSTANCE_NAME -# Install Couchpotato +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= +ynh_script_progression --message="Validating installation parameters..." - # Get first available port - port=5050 - sudo yunohost app checkport $port - while [[ ! $? -eq 0 ]]; do - port=$((port+1)) - sudo yunohost app checkport $port - done - ynh_app_setting_set "$app" port "$port" - - # Make directories - sudo mkdir -p $app_data_dir - sudo mkdir -p $app_install_dir - - # Install latest version of app using the fork - sudo git clone $source $app_install_dir - - # Install dependencies (using virtualenv) - if [[ $(python --version 2>&1) != Python\ 2* ]]; then - app_python_bin=$app_install_dir/bin/python - sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python - sudo virtualenv $app_install_dir - sudo bash -c "source $app_install_dir/bin/activate && pip install cheetah" - fi - - # Create app user - id -u $app &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app +final_path=/opt/yunohost/$app +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - # YunoHost multimedia - # Add yunohost.multimedia directory - wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip - unzip -qq master.zip - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh - # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory - sudo usermod -a -G multimedia $app - # Creates the "Movies" subfolder in "Video" - sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" - # Fix permissions - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh +multimedia_final_path=/opt/yunohost/${app}_multimedia +test ! -e "$multimedia_final_path" || ynh_die --message="This path already contains a folder" - # Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. - transmission_rpcurl="" - transmission_rpcpassword="" - transmission_watchdir="" - # Check if Transmission is installed - if [[ -z $(sudo yunohost app list -i -f transmission | grep -v 'apps:') ]]; then - sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC - sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir - sudo sed -i "s@__RENAMER__@0@g" ../conf/couchpotato.conf # Disable Renamer +app_data_dir=/home/yunohost.app/$app +test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder" + +# Register (book) web path +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= +ynh_script_progression --message="Storing installation settings..." + +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=multimedia_final_path --value=$multimedia_final_path +ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Configuring firewall..." + +# Find an available port +port=$(ynh_find_port --port=5050) +ynh_app_setting_set --app=$app --key=port --value=$port + +# Optional: Expose this port publicly +# (N.B. : you only need to do this if the app actually needs to expose the port publicly. +# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) + +# Open the port +# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring nginx web server..." + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# SPECIFIC SETUP +#================================================= +# MAKE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Make data directory..." + +# Make directories +mkdir -p $app_data_dir + +#================================================= +# INSTALL PYTHONZ TO GET PYTHON +#================================================= +ynh_print_info --message="Installing Python..." + +# Get pythonz +# curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install +# ./pythonz-install +ynh_setup_source --dest_dir="$final_path/.pythonz" --source_id=pythonz +export PYTHONZ_ROOT="$final_path/.pythonz" +# Then install it +python $final_path/.pythonz/pythonz_install.py + +# Install Python +$final_path/.pythonz/bin/pythonz install $python_version + +#================================================= +# BUILD COUCHPOTATO +#================================================= +ynh_script_progression --message="Building CouchPotato..." + +# Set permissions to app files +chown -R "$app": "$final_path" + +pushd $final_path/ + virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 + ve2/bin/pip install --upgrade pyopenssl + ve2/bin/pip install cheetah +popd + +#================================================= +# INSTALL YUNOHOST MULTIMEDIA +#================================================= +ynh_script_progression --message="Install YunoHost multimedia..." + +ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia +$multimedia_final_path/script/ynh_media_build.sh + +# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory +usermod -a -G multimedia $app + +# Creates the "Movies" subfolder in "Video" +mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + +# Fix permissions +$multimedia_final_path/script/ynh_media_build.sh + +#================================================= +# CONFIGURE TRANSMISSION +#================================================= +ynh_script_progression --message="Configuring transmission..." + +# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. +transmission_rpcurl="" +transmission_rpcpassword="" +transmission_watchdir="" + +# Check if Transmission is installed +if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then + ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..." + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer +else + ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..." + # Check if the transmission password is in settings + if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then + ynh_script_progression --message="Transmission will be linked to CouchPotato directly" + transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission" + transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword) + ynh_replace_string --match_string="__RPC__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer else - echo "Transmission is installed. Trying to link it to CouchPotato..." - # Check if the transmission password is in settings - if [[ -n $(ynh_app_setting_get transmission rpcpassword || true) ]]; then - echo "Transmission will be linked to CouchPotato directly" - transmission_rpcurl="$(ynh_app_setting_get transmission path)transmission" - transmission_rpcpassword=$(ynh_app_setting_get transmission rpcpassword) - sudo sed -i "s@__RPC__@1@g" ../conf/couchpotato.conf # Enable Transmission RPC - sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir - sudo sed -i "s@__RENAMER__@1@g" ../conf/couchpotato.conf # Enable Renamer - # If transmission uses YunoHost multimedia, use its folder for the renamer + # Check if transmission has watchdir enabled + if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then + ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir" + transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=watchdir) + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer else - # Check if transmission has watchdir enabled - if [[ -n $(ynh_app_setting_get transmission watchdir || true) ]]; then - echo "Transmission will be linked to CouchPotato with watchdir" - transmission_watchdir=$(ynh_app_setting_get transmission watchdir) - sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC - sudo sed -i "s@__BLACKHOLE__@1@g" ../conf/couchpotato.conf # Enable Transmission Watchdir - sudo sed -i "s@__RENAMER__@1@g" ../conf/couchpotato.conf # Enable Renamer - # If transmission uses YunoHost multimedia, use its folder for the renamer - else - echo "Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." - sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC - sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir - sudo sed -i "s@__RENAMER__@0@g" ../conf/couchpotato.conf # Disable Renamer - fi + ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer fi fi +fi - # Configure App - sudo sed -i "s@__RPCURL__@$transmission_rpcurl@g" ../conf/couchpotato.conf - sudo sed -i "s@__RPCPASSWORD__@$transmission_rpcpassword@g" ../conf/couchpotato.conf - sudo sed -i "s@__WATCHDIR__@$transmission_watchdir@g" ../conf/couchpotato.conf +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." - sudo sed -i "s@__PATH__@$path@g" ../conf/couchpotato.conf - sudo sed -i "s@__PORT__@$port@g" ../conf/couchpotato.conf - sudo sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/couchpotato.conf +app_config_file="${final_path}/settings.conf" - sudo cp -a ../conf/couchpotato.conf $app_config_file - - # Redirect logs directory - sudo mkdir -p $app_logs_dir - sudo chown -R $app $app_logs_dir - sudo chmod +x -R $app_logs_dir - sudo sed -i "s@self.log_dir =.*@self.log_dir = '$app_logs_dir'@g" $app_install_dir/CouchPotato.py +# Configure App +ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf" - # Permissions - sudo chown -R $app:$app $app_install_dir - sudo chown -R $app:$app $app_data_dir - - # Configure service - sed -i "s@__PYTHON__@$app_python_bin@g" ../conf/systemd.service - sed -i "s@__APPDIR__@$app_install_dir@g" ../conf/systemd.service - sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/systemd.service - sed -i "s@__PIDFILE__@$app_pid_file@g" ../conf/systemd.service - sed -i "s@__CONFIGFILE__@$app_config_file@g" ../conf/systemd.service - sed -i "s@__USER__@$app@g" ../conf/systemd.service - sudo cp ../conf/systemd.service /etc/systemd/system/$app.service - sudo systemctl daemon-reload - sudo systemctl enable $app - sudo yunohost service add $app +ynh_replace_string --match_string="__PATH__" --replace_string="$path" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__PORT__" --replace_string="$port@" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf" - # Start service - sudo yunohost service start $app +cp -a ../conf/couchpotato.conf $app_config_file -# Configure Nginx and reload - sed -i "s@__PATH__@$path@g" ../conf/nginx.conf - sed -i "s@__PORT__@$port@g" ../conf/nginx.conf - sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$app_config_file" + +#================================================= +# CONFIGURE LOGS +#================================================= +ynh_script_progression --message="Configuring logs..." + +# Redirect logs directory +app_logs_dir="/var/log/$app" +mkdir -p $app_logs_dir +chown -R $app $app_logs_dir +chmod +x -R $app_logs_dir +ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py" + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." + +# Create a dedicated systemd config +ynh_add_systemd_config --others_var="app_data_dir" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions to app files +chown -R $app:$app $final_path +chown -R $app:$app $app_data_dir + +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "CouchPotato Daemon" --log "/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Configuring SSOwat..." # Open the /api path so that external applications can connect - ynh_app_setting_set "$app" unprotected_uris "/api" +ynh_app_setting_set --app=$app --key=unprotected_uris --value="/api" -# Reload Nginx and regenerate SSOwat conf - sudo service nginx reload - sudo yunohost app ssowatconf +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 9692369..339d109 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,42 +1,114 @@ #!/bin/bash - - set -u - app=$YNH_APP_INSTANCE_NAME -# Source app helpers - source /usr/share/yunohost/helpers +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Common variable declaration - app_install_dir="/opt/yunohost/$app" - app_data_dir="/home/yunohost.app/$app" - app_logs_dir="/var/log/$app" +source _common.sh +source /usr/share/yunohost/helpers -# Retrieve arguments - domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." -# Remove files - # Kill app and remove from boot - sudo service $app stop - - # Delete app user - sudo deluser $app - - # Remove sources - sudo rm -rf $app_install_dir - sudo rm -rf $app_data_dir - sudo rm -rf $app_logs_dir +app=$YNH_APP_INSTANCE_NAME - # Remove data - sudo rm -rf $app_data_dir - -# Remove service - sudo systemctl disable $app.service - sudo rm -f /etc/systemd/system/$app.service - sudo systemctl daemon-reload - sudo yunohost service remove $app +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) -# Remove nginx configuration file - sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= -# Restart services - sudo service nginx reload +# 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..." + yunohost service remove $app +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing app main directory..." + +# Remove the app directory securely +ynh_secure_remove --file="$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Removing nginx web server configuration..." + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +# Remove a directory securely +ynh_secure_remove --file="$app_data_dir" + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Removing the dedicated system user..." + +# Delete a system user +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 6181e63..4261175 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,95 +1,169 @@ #!/bin/bash - set -eu - app=$YNH_APP_INSTANCE_NAME +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers - source /usr/share/yunohost/helpers +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers -# Common variable declaration - app_install_dir="/opt/yunohost/$app" - app_data_dir="/home/yunohost.app/$app" - app_logs_dir="/var/log/$app" - app_python_bin="/usr/bin/python" +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Retrieve arguments - domain=$(ynh_app_setting_get "$app" domain) - path=$(ynh_app_setting_get "$app" path) +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors -# Check destination directories - [[ -d $app_install_dir ]] && ynh_die \ - "The destination directory '$app_install_dir' already exists.\ - You should safely delete it before restoring this app." +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading settings..." - [[ -d $app_data_dir ]] && ynh_die \ - "The destination directory '$app_data_dir' already exists.\ - You should safely delete it before restoring this app." +app=$YNH_APP_INSTANCE_NAME - nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" - [[ -f $nginx_conf ]] && ynh_die \ - "The NGINX configuration already exists at '${nginx_conf}'. - You should safely delete it before restoring this app." +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) +multimedia_final_path=$(ynh_app_setting_get --app=$app --key=multimedia_final_path) - systemd_conf="/etc/systemd/system/${app}.service" - [[ -f $systemd_conf ]] && ynh_die \ - "The Systemd configuration already exists at '${systemd_conf}'. - You should safely delete it before restoring this app." +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= +ynh_script_progression --message="Validating restoration parameters..." -# Restore sources - sudo mkdir -p $app_install_dir - sudo cp -a ./sources/. $app_install_dir +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 " +test ! -d $app_data_dir \ + || ynh_die --message="There is already a directory: $app_data_dir " -# Restore data - sudo mkdir -p $app_data_dir - sudo cp -a ./data/. $app_data_dir +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the nginx configuration..." -# Reinstall dependencies (using virtualenv) - if [[ $(python --version 2>&1) != Python\ 2* ]]; then - sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python - sudo virtualenv $app_install_dir - sudo bash -c "source $app_install_dir/bin/activate && pip install cheetah" - fi +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -# Recreate app user - id -u $app &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." -# YunoHost multimedia - # Add yunohost.multimedia directory - wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip - unzip -qq master.zip - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh - # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory - sudo usermod -a -G multimedia $app - # Creates the "Movies" subfolder in "Video" - sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" - # Fix permissions - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh +ynh_restore_file --origin_path="$final_path" + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# RESTORE USER RIGHTS +#================================================= +ynh_script_progression --message="Restoring user rights..." + +# Restore permissions on app files +chown -R $app:$app $final_path +chown -R $app:$app $app_data_dir + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." + +ynh_restore_file --origin_path="$app_data_dir" + +#================================================= +# INSTALL YUNOHOST MULTIMEDIA +#================================================= +ynh_script_progression --message="Install YunoHost multimedia..." + +ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia +$multimedia_final_path/script/ynh_media_build.sh + +# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory +usermod -a -G multimedia $app + +# Creates the "Movies" subfolder in "Video" +mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + +# Fix permissions +$multimedia_final_path/script/ynh_media_build.sh + +#================================================= +# CONFIGURE LOGS +#================================================= +ynh_script_progression --message="Configuring logs..." # Redirect logs directory - sudo mkdir -p $app_logs_dir - sudo chown -R $app $app_logs_dir - sudo chmod +x -R $app_logs_dir - sudo sed -i "s@self.log_dir =.*@self.log_dir = '$app_logs_dir'@g" $app_install_dir/CouchPotato.py +app_logs_dir="/var/log/$app" +mkdir -p $app_logs_dir +chown -R $app $app_logs_dir +chmod +x -R $app_logs_dir +ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py" -# Permissions - sudo chown -R $app:$app $app_install_dir - sudo chown -R $app:$app $app_data_dir +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." -# Restore daemon config - sudo cp -a ./$app.service $systemd_conf - sudo systemctl daemon-reload - sudo systemctl enable $app - sudo yunohost service add $app +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service -# Start service - sudo yunohost service start $app - -# Restore Nginx conf - sudo cp -a ./nginx.conf "$nginx_conf" +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." -# Open the /api path so that external applications can connect - ynh_app_setting_set "$app" unprotected_uris "/api" +yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" -# Reload Nginx and regenerate SSOwat conf - sudo service nginx reload - sudo yunohost app ssowatconf +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index d7ac2dd..ca8f17c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,31 +1,51 @@ #!/bin/bash - set -eu - app=$YNH_APP_INSTANCE_NAME - source="https://github.com/CouchPotato/CouchPotatoServer" +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Backup the current version of the app, restore it if the upgrade fails - EXIT_PROPERLY () { - trap '' EXIT - set +e - sudo yunohost backup restore --ignore-hooks $app-before-upgrade --apps $app --force --quiet # Restore the backup if upgrade failed - ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade." - } - if [[ -n $(sudo yunohost backup info $app-before-upgrade || true) ]]; then - sudo yunohost backup delete $app-before-upgrade - fi - sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade --quiet - set -e - trap EXIT_PROPERLY ERR +source _common.sh +source /usr/share/yunohost/helpers -# Source app helpers - source /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." -# Retrieve arguments - domain=$(ynh_app_setting_get "$app" domain) - path=$(ynh_app_setting_get "$app" path) - port=$(ynh_app_setting_get "$app" port) +app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) + +# Destinations definitions + app_logs_dir="/var/log/$app" + app_python_bin="/usr/bin/python" + +#================================================= +# CHECK VERSION +#================================================= +ynh_script_progression --message="Checking version..." + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=0 + is_public=0 +fi # Cancel upgrade if the version is too old if [[ -n $(ynh_app_setting_get $app method) ]]; then ynh_die "Your current version is too old and cannot be upgraded.\ @@ -33,74 +53,189 @@ If you had a remote install, please remove the app and install redirect_ynh for this purpose instead." fi -# Destinations definitions - app_install_dir="/opt/yunohost/$app" - app_data_dir="/home/yunohost.app/$app" - app_logs_dir="/var/log/$app" - app_config_file="${app_data_dir}/settings.conf" - app_pid_file="/var/run/$app/$app.pid" - app_python_bin="/usr/bin/python" +# If final_path doesn't exist, create it +if [ -z "$final_path" ]; then + final_path=/var/www/$app + ynh_app_setting_set --app=$app --key=final_path --value=$final_path +fi -# Upgrade Couchpotato +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - # Kill app - sudo service $app stop || true +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors - # Upgrade to the latest version of app using the fork - cd $app_install_dir && sudo git pull - cd - - - # Upgrade dependencies - if [[ $(python --version 2>&1) != Python\ 2* ]]; then - app_python_bin=$app_install_dir/bin/python - sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python - fi +#================================================= +# CHECK THE PATH +#================================================= - # YunoHost multimedia - # Add yunohost.multimedia directory - wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip - unzip -qq master.zip - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh - # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory - sudo usermod -a -G multimedia $app - # Creates the "Movies" subfolder in "Video" - sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" - # Fix permissions - sudo ./yunohost.multimedia-master/script/ynh_media_build.sh +# Normalize the URL path syntax +# N.B. : this is for app installations before YunoHost 2.7 +# where this value might be something like /foo/ or foo/ +# instead of /foo .... +# If nobody installed your app before 2.7, then you may +# safely remove this line +path_url=$(ynh_normalize_url_path --path_url=$path_url) +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." - # Redirect logs directory - if [[ $app_logs_dir != "$app_data_dir"* ]]; then - sudo sed -i "s@self.log_dir =.*@self.log_dir = '$app_logs_dir'@g" $app_install_dir/CouchPotato.py - fi +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - # Permissions - sudo chown -R $app:$app $app_install_dir - sudo chown -R $app:$app $app_data_dir - - # Configure service - sed -i "s@__PYTHON__@$app_python_bin@g" ../conf/systemd.service - sed -i "s@__APPDIR__@$app_install_dir@g" ../conf/systemd.service - sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/systemd.service - sed -i "s@__PIDFILE__@$app_pid_file@g" ../conf/systemd.service - sed -i "s@__CONFIGFILE__@$app_config_file@g" ../conf/systemd.service - sed -i "s@__USER__@$app@g" ../conf/systemd.service - sudo cp ../conf/systemd.service /etc/systemd/system/$app.service - sudo systemctl daemon-reload - sudo systemctl enable $app - sudo yunohost service add $app +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= - # Start service - sudo yunohost service start $app +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." -# Configure Nginx and reload - sed -i "s@__PATH__@$path@g" ../conf/nginx.conf - sed -i "s@__PORT__@$port@g" ../conf/nginx.conf - sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# BUILD COUCHPOTATO +#================================================= +ynh_script_progression --message="Building CouchPotato..." + +# Set permissions to app files +chown -R "$app": "$final_path" + +pushd $final_path/ + virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 + ve2/bin/pip install --upgrade pyopenssl + ve2/bin/pip install cheetah +popd + +#================================================= +# BUILD COUCHPOTATO +#================================================= +ynh_script_progression --message="Building CouchPotato..." + +# Set permissions to app files +chown -R "$app": "$final_path" + +pushd $final_path/ + virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 + ve2/bin/pip install --upgrade pyopenssl + ve2/bin/pip install cheetah +popd + +#================================================= +# INSTALL YUNOHOST MULTIMEDIA +#================================================= +ynh_script_progression --message="Install YunoHost multimedia..." + +ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia +$multimedia_final_path/script/ynh_media_build.sh + +# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory +usermod -a -G multimedia $app + +# Creates the "Movies" subfolder in "Video" +mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + +# Fix permissions +$multimedia_final_path/script/ynh_media_build.sh + +#================================================= +# CONFIGURE LOGS +#================================================= +ynh_script_progression --message="Configuring logs..." + +# Redirect logs directory +app_logs_dir="/var/log/$app" +ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py" + +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configuration..." + +# Create a dedicated systemd config +ynh_add_systemd_config --others_var="app_data_dir" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions on app files +chown -R $app:$app $final_path +chown -R $app:$app $app_data_dir + +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." # Open the /api path so that external applications can connect - ynh_app_setting_set "$app" unprotected_uris "/api" +ynh_app_setting_set --app=$app --key=unprotected_uris --value="/api" -# Reload Nginx and regenerate SSOwat conf - sudo service nginx reload - sudo yunohost app ssowatconf +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +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_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" From d8122a9fc874de4a873268c40063545c12fdc0d5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 17 Jun 2020 00:02:57 +0200 Subject: [PATCH 02/14] Adding pythonz dependencies --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f2a44ac..8f9ca4b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python" +pkg_dependencies="python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev libffi-dev" python_version=2.7.2 From 6bcbfb9dcc482ed2f2644479079fc4e2110e471a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Jun 2020 05:35:15 +0200 Subject: [PATCH 03/14] Switch to ynh_install_python --- conf/multimedia.src | 6 -- conf/pythonz.src | 6 -- conf/systemd.service | 4 +- scripts/_common.sh | 5 +- scripts/install | 44 ++++------- scripts/remove | 2 + scripts/restore | 26 +++++-- scripts/upgrade | 31 +++----- scripts/ynh_install_python | 151 +++++++++++++++++++++++++++++++++++++ scripts/ynh_multimedia_3 | 78 +++++++++++++++++++ 10 files changed, 282 insertions(+), 71 deletions(-) delete mode 100644 conf/multimedia.src delete mode 100644 conf/pythonz.src create mode 100644 scripts/ynh_install_python create mode 100644 scripts/ynh_multimedia_3 diff --git a/conf/multimedia.src b/conf/multimedia.src deleted file mode 100644 index 54c3617..0000000 --- a/conf/multimedia.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://github.com/YunoHost-Apps/yunohost.multimedia/archive/v1.2.tar.gz -SOURCE_SUM=7dfc07e32d7842f87274ef780cb9757a7679573cbbeb095c5f86ef76806f5d95 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/pythonz.src b/conf/pythonz.src deleted file mode 100644 index fd43a3e..0000000 --- a/conf/pythonz.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://github.com/saghul/pythonz/archive/9067f35e0253b015eb51b8a4d60c0bd1a06dcc83.tar.gz -SOURCE_SUM=ce9eb5400fff81e4877e04dd7166c764d8adc999d9ca6b06ce933ee9375b8652 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/systemd.service b/conf/systemd.service index 80314b3..437a957 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -3,10 +3,12 @@ Description=CouchPotato application instance After=network.target [Service] -ExecStart=__FINALPATH__/ve2/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf Type=simple User=__APP__ Group=__APP__ +WorkingDirectory=__FINALPATH__/ +ExecStart=/opt/pyenv/versions/__APP__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf + [Install] WantedBy=multi-user.target diff --git a/scripts/_common.sh b/scripts/_common.sh index 8f9ca4b..49106f9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,9 +5,10 @@ #================================================= # dependencies used by the app -pkg_dependencies="python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev libffi-dev" +pkg_dependencies="" +#python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python -python_version=2.7.2 +PHYTON_VERSION=2.7.18 #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index f416ae6..6cbdde0 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,8 @@ #================================================= source _common.sh +source ynh_install_python +source ynh_multimedia_3 source /usr/share/yunohost/helpers #================================================= @@ -14,6 +16,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { + read -p "key" true } # Exit if an error occurs during the execution of the script @@ -36,9 +39,6 @@ ynh_script_progression --message="Validating installation parameters..." final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -multimedia_final_path=/opt/yunohost/${app}_multimedia -test ! -e "$multimedia_final_path" || ynh_die --message="This path already contains a folder" - app_data_dir=/home/yunohost.app/$app test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder" @@ -52,7 +52,6 @@ ynh_script_progression --message="Storing installation settings..." 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=multimedia_final_path --value=$multimedia_final_path ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir #================================================= @@ -115,22 +114,6 @@ ynh_script_progression --message="Make data directory..." # Make directories mkdir -p $app_data_dir -#================================================= -# INSTALL PYTHONZ TO GET PYTHON -#================================================= -ynh_print_info --message="Installing Python..." - -# Get pythonz -# curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install -# ./pythonz-install -ynh_setup_source --dest_dir="$final_path/.pythonz" --source_id=pythonz -export PYTHONZ_ROOT="$final_path/.pythonz" -# Then install it -python $final_path/.pythonz/pythonz_install.py - -# Install Python -$final_path/.pythonz/bin/pythonz install $python_version - #================================================= # BUILD COUCHPOTATO #================================================= @@ -139,10 +122,12 @@ ynh_script_progression --message="Building CouchPotato..." # Set permissions to app files chown -R "$app": "$final_path" -pushd $final_path/ - virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 - ve2/bin/pip install --upgrade pyopenssl - ve2/bin/pip install cheetah +ynh_install_python --python_version=$PHYTON_VERSION + +pushd $final_path + pyenv virtualenv $PHYTON_VERSION $app + /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl + /opt/pyenv/versions/$app/bin/pip install cheetah popd #================================================= @@ -150,17 +135,16 @@ popd #================================================= ynh_script_progression --message="Install YunoHost multimedia..." -ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia -$multimedia_final_path/script/ynh_media_build.sh +ynh_multimedia_build_main_dir # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory -usermod -a -G multimedia $app +ynh_multimedia_addaccess $app # Creates the "Movies" subfolder in "Video" mkdir -p "/home/yunohost.multimedia/share/Video/Movies" # Fix permissions -$multimedia_final_path/script/ynh_media_build.sh +/home/yunohost.multimedia/ynh_media_build.sh #================================================= # CONFIGURE TRANSMISSION @@ -219,8 +203,8 @@ ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_r ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf" -ynh_replace_string --match_string="__PATH__" --replace_string="$path" --target_file="../conf/couchpotato.conf" -ynh_replace_string --match_string="__PORT__" --replace_string="$port@" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf" cp -a ../conf/couchpotato.conf $app_config_file diff --git a/scripts/remove b/scripts/remove index 339d109..aea6ed0 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_python source /usr/share/yunohost/helpers #================================================= @@ -48,6 +49,7 @@ ynh_remove_systemd_config ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies +ynh_remove_python ynh_remove_app_dependencies #================================================= diff --git a/scripts/restore b/scripts/restore index 4261175..83a6c4c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,8 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_install_pyhon +source ../settings/scripts/ynh_multimedia_3 source /usr/share/yunohost/helpers #================================================= @@ -31,7 +33,6 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) -multimedia_final_path=$(ynh_app_setting_get --app=$app --key=multimedia_final_path) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -88,6 +89,22 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# BUILD COUCHPOTATO +#================================================= +ynh_script_progression --message="Building CouchPotato..." + +# Set permissions to app files +chown -R "$app": "$final_path" + +ynh_install_python --python_version=$PHYTON_VERSION + +pushd $final_path + pyenv virtualenv $PHYTON_VERSION $app + /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl + /opt/pyenv/versions/$app/bin/pip install cheetah +popd + #================================================= # RESTORE THE DATA DIRECTORY #================================================= @@ -100,17 +117,16 @@ ynh_restore_file --origin_path="$app_data_dir" #================================================= ynh_script_progression --message="Install YunoHost multimedia..." -ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia -$multimedia_final_path/script/ynh_media_build.sh +ynh_multimedia_build_main_dir # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory -usermod -a -G multimedia $app +ynh_multimedia_addaccess $app # Creates the "Movies" subfolder in "Video" mkdir -p "/home/yunohost.multimedia/share/Video/Movies" # Fix permissions -$multimedia_final_path/script/ynh_media_build.sh +/home/yunohost.multimedia/ynh_media_build.sh #================================================= # CONFIGURE LOGS diff --git a/scripts/upgrade b/scripts/upgrade index ca8f17c..2954292 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,8 @@ #================================================= source _common.sh +source ynh_install_python +source ynh_multimedia_3 source /usr/share/yunohost/helpers #================================================= @@ -139,24 +141,12 @@ ynh_script_progression --message="Building CouchPotato..." # Set permissions to app files chown -R "$app": "$final_path" -pushd $final_path/ - virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 - ve2/bin/pip install --upgrade pyopenssl - ve2/bin/pip install cheetah -popd +ynh_install_python --python_version=$PHYTON_VERSION -#================================================= -# BUILD COUCHPOTATO -#================================================= -ynh_script_progression --message="Building CouchPotato..." - -# Set permissions to app files -chown -R "$app": "$final_path" - -pushd $final_path/ - virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2 - ve2/bin/pip install --upgrade pyopenssl - ve2/bin/pip install cheetah +pushd $final_path + pyenv virtualenv $PHYTON_VERSION $app + /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl + /opt/pyenv/versions/$app/bin/pip install cheetah popd #================================================= @@ -164,17 +154,16 @@ popd #================================================= ynh_script_progression --message="Install YunoHost multimedia..." -ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia -$multimedia_final_path/script/ynh_media_build.sh +ynh_multimedia_build_main_dir # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory -usermod -a -G multimedia $app +ynh_multimedia_addaccess $app # Creates the "Movies" subfolder in "Video" mkdir -p "/home/yunohost.multimedia/share/Video/Movies" # Fix permissions -$multimedia_final_path/script/ynh_media_build.sh +/home/yunohost.multimedia/ynh_media_build.sh #================================================= # CONFIGURE LOGS diff --git a/scripts/ynh_install_python b/scripts/ynh_install_python new file mode 100644 index 0000000..7d763b2 --- /dev/null +++ b/scripts/ynh_install_python @@ -0,0 +1,151 @@ +#!/bin/bash + +# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args + +pyenv_install_dir="/opt/pyenv" +# PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable. +export PYENV_ROOT="$pyenv_install_dir" +# Required dependencies +pyenv_dependencies="build-essential libssl1.0-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git" + +# Install python version management +# +# [internal] +# +# usage: ynh_install_pyenv +ynh_install_pyenv () { + echo "Installation of pyenv - python version management" >&2 + # Build an app.src for pyenv + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v1.2.19.tar.gz +SOURCE_SUM=e93466735ac9c34d68b7d5d71f32c16a2b4b1a6a1adffb85acc4126a3398b9d0" > "../conf/pyenv.src" + # Download and extract pyenv + ynh_setup_source "$pyenv_install_dir" pyenv + + # Build an app.src for pyenv-virtualenv + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/pyenv/pyenv-virtualenv/archive/v1.1.5.tar.gz +SOURCE_SUM=27ae3de027a6f6dccdca4085225512e559c6b94b31625bd2b357a18890a1e618" > "../conf/pyenv-virtualenv.src" + # Download and extract pyenv-virtualenv + ynh_setup_source "$pyenv_install_dir/plugins/pyenv-virtualenv" pyenv-virtualenv + + (cd $pyenv_install_dir + ./src/configure && make -C src) + +# Create shims directory if needed +if [ ! -d $pyenv_install_dir/shims ] ; then + mkdir $pyenv_install_dir/shims +fi +} + +# Install a specific version of python +# +# ynh_install_python will install the version of python provided as argument by using pyenv. +# +# pyenv (python version management) stores the target python version in a .python_version file created in the target folder (using pyenv local ) +# It then uses that information for every python user that uses pyenv provided python command +# +# This helper creates a /etc/profile.d/pyenv.sh that configures PATH environment for pyenv +# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) +# +# Don't forget to execute python-dependent command in a login environment +# (e.g. sudo --login option) +# When not possible (e.g. in systemd service definition), please use direct path +# to pyenv shims (e.g. $PYENV_ROOT/shims/bundle) +# +# usage: ynh_install_python python_version user +# | arg: -v, --python_version= - Version of python to install. +# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0). +# The crontab will handle the update of minor versions when needed. +ynh_install_python () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [v]=python_version= ) + # Use pyenv, https://github.com/pyenv/pyenv to manage the python versions + local python_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Create $pyenv_install_dir + mkdir -p "$pyenv_install_dir/plugins/pyenv-virtualenv" + + # Load pyenv path in PATH + 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:@@') + + # Move an existing python binary, to avoid to block pyenv + #test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv + + # If pyenv is not previously setup, install it + if ! type pyenv > /dev/null 2>&1 + then + ynh_install_pyenv + elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt "1.2.19" + then + ynh_install_pyenv + elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt "1.1.5" + then + ynh_install_pyenv + fi + + # Restore /usr/local/bin in PATH (if needed) + PATH=$CLEAR_PATH + + # And replace the old python binary + # test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python + + # Install required dependencies + ynh_add_app_dependencies --package="$pyenv_dependencies" + + # Install the requested version of python + pyenv install --skip-existing $python_version + + # Store the ID of this app and the version of python requested for it + echo "$YNH_APP_ID:$python_version" | tee --append "$pyenv_install_dir/ynh_app_version" + + # Store python_version into the config of this app + ynh_app_setting_set --app=$app --key=python_version --value=$python_version + + # 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 right environment for the Installation + eval "$(pyenv init -)" + + (cd $final_path + pyenv local $python_version) +} + +# Remove the version of python used by the app. +# +# This helper will check if another app uses the same version of python, +# if not, this version of python will be removed. +# If no other app uses python, pyenv will be also removed. +# +# usage: ynh_remove_python +ynh_remove_python () { + python_version=$(ynh_app_setting_get --app=$app --key=python_version) + + # Remove the line for this app + sed --in-place "/$YNH_APP_ID:$python_version/d" "$pyenv_install_dir/ynh_app_version" + + # If no other app uses this version of python, remove it. + if ! grep --quiet "$python_version" "$pyenv_install_dir/ynh_app_version" + then + $pyenv_install_dir/bin/pyenv uninstall --force $python_version + fi + + # Remove pyenv environment configuration + rm /etc/profile.d/pyenv.sh + + # If no other app uses pyenv, remove pyenv and dedicated group + if [ ! -s "$pyenv_install_dir/ynh_app_version" ] + then + ynh_secure_remove --file="$pyenv_install_dir" + fi +} diff --git a/scripts/ynh_multimedia_3 b/scripts/ynh_multimedia_3 new file mode 100644 index 0000000..edf680c --- /dev/null +++ b/scripts/ynh_multimedia_3 @@ -0,0 +1,78 @@ +#!/bin/bash + +# Install or update the main directory yunohost.multimedia +# +# usage: ynh_multimedia_build_main_dir +ynh_multimedia_build_main_dir () { + local ynh_media_release="v1.2" + local checksum="806a827ba1902d6911095602a9221181" + + # Download yunohost.multimedia scripts + wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz + + # Check the control sum + echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \ + || ynh_die "Corrupt source" + + # Check if the package acl is installed. Or install it. + ynh_package_is_installed 'acl' \ + || ynh_package_install acl + + # Extract + mkdir yunohost.multimedia-master + tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1 + ./yunohost.multimedia-master/script/ynh_media_build.sh +} + +# Add a directory in yunohost.multimedia +# This "directory" will be a symbolic link to a existing directory. +# +# usage: ynh_multimedia_addfolder "Source directory" "Destination directory" +# +# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias. +# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia" +ynh_multimedia_addfolder () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= ) + local source_dir + local dest_dir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir" +} + +# Move a directory in yunohost.multimedia, and replace by a symbolic link +# +# usage: ynh_multimedia_movefolder "Source directory" "Destination directory" +# +# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias. +# It will be moved to "Destination directory" +# A symbolic link will replace it. +# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia" +ynh_multimedia_movefolder () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= ) + local source_dir + local dest_dir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir" +} + +# Allow an user to have an write authorisation in multimedia directories +# +# usage: ynh_multimedia_addaccess user_name +# +# | arg: -u, --user_name= - The name of the user which gain this access. +ynh_multimedia_addaccess () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [u]=user_name=) + local user_name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + groupadd -f multimedia + usermod -a -G multimedia $user_name +} From 73b08c9e1c92147416d70109b2a8344950b862e5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Jun 2020 05:47:06 +0200 Subject: [PATCH 04/14] Cleanup --- scripts/install | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install b/scripts/install index 6cbdde0..4873673 100644 --- a/scripts/install +++ b/scripts/install @@ -16,7 +16,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - read -p "key" true } # Exit if an error occurs during the execution of the script From d1a7c9d9b87d8b46f2eb92f4fbb9f234ff2b032a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Jun 2020 13:47:58 +0200 Subject: [PATCH 05/14] typo --- scripts/restore | 2 +- scripts/ynh_install_python | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index 83a6c4c..4b7faac 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,7 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_install_pyhon +source ../settings/scripts/ynh_install_python source ../settings/scripts/ynh_multimedia_3 source /usr/share/yunohost/helpers diff --git a/scripts/ynh_install_python b/scripts/ynh_install_python index 7d763b2..3273fcc 100644 --- a/scripts/ynh_install_python +++ b/scripts/ynh_install_python @@ -6,7 +6,7 @@ pyenv_install_dir="/opt/pyenv" # PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable. export PYENV_ROOT="$pyenv_install_dir" # Required dependencies -pyenv_dependencies="build-essential libssl1.0-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git" +pyenv_dependencies="build-essential libssl1.0-dev|libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git" # Install python version management # From 2fc0cb5deb527393a5c61a862889048eb8e22e37 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Jun 2020 19:12:51 +0200 Subject: [PATCH 06/14] chown: cannot access '/home/yunohost.app/couchpotato': No such file or directory --- scripts/restore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 4b7faac..e8826d3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -77,7 +77,6 @@ ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R $app:$app $final_path -chown -R $app:$app $app_data_dir #================================================= # SPECIFIC RESTORATION @@ -112,6 +111,8 @@ ynh_script_progression --message="Restoring the data directory..." ynh_restore_file --origin_path="$app_data_dir" +chown -R $app:$app $app_data_dir + #================================================= # INSTALL YUNOHOST MULTIMEDIA #================================================= From 537526b1d6d6073e4c55cd16599e1f1021dc048b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Jun 2020 22:32:31 +0200 Subject: [PATCH 07/14] Switching PYHTNON_VERSIOn to lowercase --- conf/systemd.service | 2 +- scripts/_common.sh | 2 +- scripts/install | 9 ++++----- scripts/restore | 4 ++-- scripts/upgrade | 9 ++++----- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 437a957..3fa13b1 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=/opt/pyenv/versions/__APP__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf +ExecStart=/opt/pyenv/versions/__PHYTON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf [Install] diff --git a/scripts/_common.sh b/scripts/_common.sh index 49106f9..a611f99 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,7 +8,7 @@ pkg_dependencies="" #python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python -PHYTON_VERSION=2.7.18 +python_version=2.7.18 #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 4873673..a54ed0e 100644 --- a/scripts/install +++ b/scripts/install @@ -121,12 +121,11 @@ ynh_script_progression --message="Building CouchPotato..." # Set permissions to app files chown -R "$app": "$final_path" -ynh_install_python --python_version=$PHYTON_VERSION +ynh_install_python --python_version=$python_version pushd $final_path - pyenv virtualenv $PHYTON_VERSION $app - /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl - /opt/pyenv/versions/$app/bin/pip install cheetah + /opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl + /opt/pyenv/versions/$python_version/bin/pip install cheetah popd #================================================= @@ -229,7 +228,7 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config -ynh_add_systemd_config --others_var="app_data_dir" +ynh_add_systemd_config --others_var="app_data_dir python_version" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index e8826d3..98b7537 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,10 +96,10 @@ ynh_script_progression --message="Building CouchPotato..." # Set permissions to app files chown -R "$app": "$final_path" -ynh_install_python --python_version=$PHYTON_VERSION +ynh_install_python --python_version=$python_version pushd $final_path - pyenv virtualenv $PHYTON_VERSION $app + pyenv virtualenv $python_version $app /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl /opt/pyenv/versions/$app/bin/pip install cheetah popd diff --git a/scripts/upgrade b/scripts/upgrade index 2954292..69319c6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -141,12 +141,11 @@ ynh_script_progression --message="Building CouchPotato..." # Set permissions to app files chown -R "$app": "$final_path" -ynh_install_python --python_version=$PHYTON_VERSION +ynh_install_python --python_version=$python_version pushd $final_path - pyenv virtualenv $PHYTON_VERSION $app - /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl - /opt/pyenv/versions/$app/bin/pip install cheetah + /opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl + /opt/pyenv/versions/$python_version/bin/pip install cheetah popd #================================================= @@ -188,7 +187,7 @@ ynh_use_logrotate --non-append ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_add_systemd_config --others_var="app_data_dir" +ynh_add_systemd_config --others_var="app_data_dir python_version" #================================================= # GENERIC FINALIZATION From f3900fbd8bb059116b5068c8641d32a17bb7198e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 23 Jun 2020 00:02:36 +0200 Subject: [PATCH 08/14] typo --- conf/systemd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/systemd.service b/conf/systemd.service index 3fa13b1..f33eefd 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=/opt/pyenv/versions/__PHYTON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf +ExecStart=/opt/pyenv/versions/__PYTHON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf [Install] From eeac9ff67125fcf167895049a2871b52f4332d11 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 23 Jun 2020 19:25:56 +0200 Subject: [PATCH 09/14] Update upgrade --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 69319c6..ebdb878 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,8 +25,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) # Destinations definitions - app_logs_dir="/var/log/$app" - app_python_bin="/usr/bin/python" +app_logs_dir="/var/log/$app" +app_python_bin="/usr/bin/python" #================================================= # CHECK VERSION From 4a750a207a83f9f7c9bc050cc48df46402da9594 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 24 Jun 2020 02:59:53 +0200 Subject: [PATCH 10/14] Fix upgrade --- scripts/upgrade | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index ebdb878..c53d67f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -49,11 +49,11 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi # Cancel upgrade if the version is too old - if [[ -n $(ynh_app_setting_get $app method) ]]; then - ynh_die "Your current version is too old and cannot be upgraded.\ - If you had a local install, please remove the app and reinstall it.\ - If you had a remote install, please remove the app and install redirect_ynh for this purpose instead." - fi +if [[ -n $(ynh_app_setting_get $app method) ]]; then + ynh_die "Your current version is too old and cannot be upgraded.\ + If you had a local install, please remove the app and reinstall it.\ + If you had a remote install, please remove the app and install redirect_ynh for this purpose instead." +fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then @@ -61,6 +61,12 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# If app_data_dir doesn't exist, create it +if [ -z "$app_data_dir" ]; then + app_data_dir=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= From dd9e5485b48d37e2e2182a4fa9f64bf810a3f1d0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 24 Jun 2020 20:24:54 +0200 Subject: [PATCH 11/14] Fix upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index c53d67f..151337f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,7 +57,7 @@ fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then - final_path=/var/www/$app + final_path=/opt/yunohost/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi From 3e79c96f16de96f5629dcae1d86765ab87af93ac Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 23 Jul 2020 00:41:24 +0200 Subject: [PATCH 12/14] Update ynh_install_python --- scripts/ynh_install_python | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/ynh_install_python b/scripts/ynh_install_python index 3273fcc..2d8206f 100644 --- a/scripts/ynh_install_python +++ b/scripts/ynh_install_python @@ -1,10 +1,13 @@ #!/bin/bash # Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - +pyenv_version=1.2.19 +pyenv_virtualenv_version=1.1.5 pyenv_install_dir="/opt/pyenv" + # PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable. export PYENV_ROOT="$pyenv_install_dir" + # Required dependencies pyenv_dependencies="build-essential libssl1.0-dev|libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git" @@ -17,14 +20,14 @@ ynh_install_pyenv () { echo "Installation of pyenv - python version management" >&2 # Build an app.src for pyenv mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v1.2.19.tar.gz + echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v${pyenv_version}.tar.gz SOURCE_SUM=e93466735ac9c34d68b7d5d71f32c16a2b4b1a6a1adffb85acc4126a3398b9d0" > "../conf/pyenv.src" # Download and extract pyenv ynh_setup_source "$pyenv_install_dir" pyenv # Build an app.src for pyenv-virtualenv mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/pyenv/pyenv-virtualenv/archive/v1.1.5.tar.gz + echo "SOURCE_URL=https://github.com/pyenv/pyenv-virtualenv/archive/v${pyenv_virtualenv_version}.tar.gz SOURCE_SUM=27ae3de027a6f6dccdca4085225512e559c6b94b31625bd2b357a18890a1e618" > "../conf/pyenv-virtualenv.src" # Download and extract pyenv-virtualenv ynh_setup_source "$pyenv_install_dir/plugins/pyenv-virtualenv" pyenv-virtualenv @@ -55,7 +58,7 @@ fi # # usage: ynh_install_python python_version user # | arg: -v, --python_version= - Version of python to install. -# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0). +# If possible, prefer to use major version number (e.g. 3 instead of 3.7.3). # The crontab will handle the update of minor versions when needed. ynh_install_python () { # Declare an array to define the options of this helper. @@ -81,10 +84,10 @@ ynh_install_python () { if ! type pyenv > /dev/null 2>&1 then ynh_install_pyenv - elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt "1.2.19" + elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt $pyenv_version then ynh_install_pyenv - elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt "1.1.5" + elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt $pyenv_virtualenv_version then ynh_install_pyenv fi From 9949873d11fd7b981d5184e1b0b29b94286bfe62 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 23 Jul 2020 01:44:52 +0200 Subject: [PATCH 13/14] Fix upgrade --- conf/app.src | 4 +-- conf/couchpotato.conf | 19 ++++++------ scripts/upgrade | 68 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/conf/app.src b/conf/app.src index 03aa940..854b162 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/CouchPotato/CouchPotatoServer/archive/build/3.0.1.tar.gz -SOURCE_SUM=f08f9c6ac02f66c6667f17ded1eea4c051a62bbcbadd2a8673394019878e92f7 +SOURCE_URL=https://github.com/CouchPotato/CouchPotatoServer/archive/7260c12f72447ddb6f062367c6dfbda03ecd4e9c.tar.gz +SOURCE_SUM=2944f73f1630ada31e24d47df678c4412bd6acc93295ce2915179a75ecfd5dd1 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/couchpotato.conf b/conf/couchpotato.conf index 99ef79e..36654f6 100644 --- a/conf/couchpotato.conf +++ b/conf/couchpotato.conf @@ -2,25 +2,26 @@ api_key = username = ssl_key = +proxy_server = ssl_cert = data_dir = __DATADIR__ +use_proxy = 0 +permission_file = 0755 +proxy_password = +dereferer = http://www.nullrefer.com/? permission_folder = 0755 +dark_theme = False development = 0 -url_base = __PATH__ +proxy_username = +ipv6 = 0 debug = 0 launch_browser = False password = port = __PORT__ -permission_file = 0755 +url_base = __PATH__ show_wizard = 0 username_internal_meta = rw -use_proxy = 0 -proxy_password = -dereferer = http://www.nullrefer.com/? -dark_theme = False api_key_internal_meta = ro -proxy_username = -ipv6 = 0 [updater] notification = False @@ -32,7 +33,7 @@ automatic = False startup_scan = True library_refresh_interval = 0 cleanup = True -enabled = 1 +enabled = True library = /home/yunohost.multimedia/share/Video/Movies [renamer] diff --git a/scripts/upgrade b/scripts/upgrade index 151337f..8037451 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -170,6 +170,74 @@ mkdir -p "/home/yunohost.multimedia/share/Video/Movies" # Fix permissions /home/yunohost.multimedia/ynh_media_build.sh +#================================================= +# CONFIGURE TRANSMISSION +#================================================= +ynh_script_progression --message="Configuring transmission..." + +# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. +transmission_rpcurl="" +transmission_rpcpassword="" +transmission_watchdir="" + +# Check if Transmission is installed +if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then + ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..." + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer +else + ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..." + # Check if the transmission password is in settings + if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then + ynh_script_progression --message="Transmission will be linked to CouchPotato directly" + transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission" + transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword) + ynh_replace_string --match_string="__RPC__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer + else + # Check if transmission has watchdir enabled + if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then + ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir" + transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=watchdir) + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer + else + ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." + ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC + ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir + ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer + fi + fi +fi + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." + +app_config_file="${final_path}/settings.conf" + +# Configure App +ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf" + +ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf" + +ynh_backup_if_checksum_is_different --file=$app_config_file + +cp -a ../conf/couchpotato.conf $app_config_file + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$app_config_file" + #================================================= # CONFIGURE LOGS #================================================= From 82a2dbbb04d59bc162efd52e9d263444459ac23d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 4 Aug 2020 00:27:51 +0200 Subject: [PATCH 14/14] back to git --- scripts/_common.sh | 2 ++ scripts/install | 2 +- scripts/upgrade | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index a611f99..c0faaa3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,6 +10,8 @@ pkg_dependencies="" python_version=2.7.18 +source="https://github.com/CouchPotato/CouchPotatoServer" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index a54ed0e..0d7cea4 100644 --- a/scripts/install +++ b/scripts/install @@ -85,7 +85,7 @@ ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" +git clone $source $final_path #================================================= # NGINX CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 8037451..19b6e49 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -111,7 +111,9 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + pushd $final_path + git pull + popd fi #=================================================