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

apply example_ynh

This commit is contained in:
yalh76 2020-06-16 05:29:50 +02:00
parent 2a7461345d
commit ba9b7ebc61
15 changed files with 1035 additions and 437 deletions

View file

@ -1,30 +1,32 @@
## <img src="https://github.com/binhex/docker-templates/raw/master/binhex/images/couchpotato-icon.png" height="32" align="top"> couchpotato_ynh <a href="https://yunohost.org/#/apps_in_progress_en"><img src="http://pix.toile-libre.org/upload/original/1440352021.png" height="32" align="right"></a>
## <img src="https://github.com/binhex/docker-templates/raw/master/binhex/images/couchpotato-icon.png" height="32" align="top"> CouchPotato <a href="https://yunohost.org/#/apps_in_progress_en"><img src="http://pix.toile-libre.org/upload/original/1440352021.png" height="32" align="right"></a>
[![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
```

View file

@ -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

6
conf/app.src Normal file
View file

@ -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=

6
conf/multimedia.src Normal file
View file

@ -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=

6
conf/pythonz.src Normal file
View file

@ -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=

View file

@ -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

46
issue_template.md Normal file
View file

@ -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.*

View file

@ -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"
}
]
}
}

18
pull_request_template.md Normal file
View file

@ -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)/)

22
scripts/_common.sh Normal file
View file

@ -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
#=================================================

View file

@ -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)."

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"