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

Merge pull request #11 from YunoHost-Apps/testing

apply example_ynh
This commit is contained in:
yalh76 2020-09-04 02:18:31 +02:00 committed by GitHub
commit 2e7405c02e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 1339 additions and 450 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)
[![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)
> *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.*
[ **CouchPotato Integration for Yunohost** ]
## 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,5 +1,9 @@
;; Test CouchPotato
auto_remove=1
# 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)"
@ -11,25 +15,20 @@
setup_private=0
setup_public=0
upgrade=1
upgrade=1 from_commit=2a7461345d70ae231cc81a580189934626ed8c58
backup_restore=1
multi_instance=0
wrong_user=0
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=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)
final_path_already_use=0
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/7260c12f72447ddb6f062367c6dfbda03ecd4e9c.tar.gz
SOURCE_SUM=2944f73f1630ada31e24d47df678c4412bd6acc93295ce2915179a75ecfd5dd1
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

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

View file

@ -3,10 +3,12 @@ Description=CouchPotato application instance
After=network.target
[Service]
ExecStart=__PYTHON__ __APPDIR__/CouchPotato.py --quiet --pid_file=__PIDFILE__ --data_dir=__DATADIR__ --config_file=__CONFIGFILE__
Type=simple
User=__USER__
Group=__USER__
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=/opt/pyenv/versions/__PYTHON_VERSION__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf
[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,11 +1,12 @@
{
"packaging_format": 1,
"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": {
@ -13,25 +14,27 @@
"email": "snipees@wareziens.net",
"url": "https://github.com/Snipees"
},
"requirements": {
"yunohost": ">= 3.5"
},
"multi_instance": false,
"services": [
"nginx"
],
"requirements": {
"yunohost": ">= 2.4.0"
},
"arguments": {
"install": [
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for CouchPotato",
"fr": "Choisissez un domaine pour CouchPotato"
},
"example": "mydomain.org"
"example": "example.com"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for CouchPotato",
"fr": "Choisissez un chemin pour 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)/)

25
scripts/_common.sh Normal file
View file

@ -0,0 +1,25 @@
#!/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.18
source="https://github.com/CouchPotato/CouchPotatoServer"
#=================================================
# 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"
ynh_backup --src_path="$app_data_dir"
# Backup daemon
ynh_backup "/etc/systemd/system/$app.service" "$app.service"
#=================================================
# END OF SCRIPT
#=================================================
# Copy the conf files
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,160 +1,286 @@
#!/bin/bash
set -eu
app=$YNH_APP_INSTANCE_NAME
source="https://github.com/CouchPotato/CouchPotatoServer"
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_python
source ynh_multimedia_3
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"
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Make directories
sudo mkdir -p $app_data_dir
sudo mkdir -p $app_install_dir
app_data_dir=/home/yunohost.app/$app
test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder"
# Install latest version of app using the fork
sudo git clone $source $app_install_dir
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
# 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
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
# Create app user
id -u $app &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app
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=app_data_dir --value=$app_data_dir
# 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
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..."
# 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
else
echo "Transmission is installed. Trying to link it to CouchPotato..."
# 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
git clone $source $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
#=================================================
# BUILD COUCHPOTATO
#=================================================
ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files
chown -R "$app": "$final_path"
ynh_install_python --python_version=$python_version
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah
popd
#=================================================
# INSTALL YUNOHOST MULTIMEDIA
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video"
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 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 [[ -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 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 [[ -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
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
# 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"
# 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
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"
# Permissions
sudo chown -R $app:$app $app_install_dir
sudo chown -R $app:$app $app_data_dir
cp -a ../conf/couchpotato.conf $app_config_file
# 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
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$app_config_file"
# Start service
sudo yunohost service start $app
#=================================================
# CONFIGURE LOGS
#=================================================
ynh_script_progression --message="Configuring logs..."
# 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
# 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 python_version"
#=================================================
# 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,116 @@
#!/bin/bash
set -u
app=$YNH_APP_INSTANCE_NAME
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source /usr/share/yunohost/helpers
source _common.sh
source ynh_install_python
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"
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
app=$YNH_APP_INSTANCE_NAME
# Remove files
# Kill app and remove from boot
sudo service $app stop
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)
# Delete app user
sudo deluser $app
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove sources
sudo rm -rf $app_install_dir
sudo rm -rf $app_data_dir
sudo rm -rf $app_logs_dir
# 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
# Remove data
sudo rm -rf $app_data_dir
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove service
sudo systemctl disable $app.service
sudo rm -f /etc/systemd/system/$app.service
sudo systemctl daemon-reload
sudo yunohost service remove $app
# Remove the dedicated systemd config
ynh_remove_systemd_config
# Remove nginx configuration file
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Restart services
sudo service nginx reload
# Remove metapackage and its dependencies
ynh_remove_python
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,186 @@
#!/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 ../settings/scripts/ynh_install_python
source ../settings/scripts/ynh_multimedia_3
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)
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
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
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=$python_version
pushd $final_path
pyenv virtualenv $python_version $app
/opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$app/bin/pip install cheetah
popd
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
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
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video"
mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
# Fix permissions
/home/yunohost.multimedia/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
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
# Restore Nginx conf
sudo cp -a ./nginx.conf "$nginx_conf"
yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log"
# Open the /api path so that external applications can connect
ynh_app_setting_set "$app" unprotected_uris "/api"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf
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,106 +1,305 @@
#!/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 ynh_install_python
source ynh_multimedia_3
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
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
final_path=/opt/yunohost/$app
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
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# 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
#=================================================
# CHECK THE PATH
#=================================================
# 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..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
pushd $final_path
git pull
popd
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"
ynh_install_python --python_version=$python_version
pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$python_version/bin/pip install cheetah
popd
#=================================================
# INSTALL YUNOHOST MULTIMEDIA
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video"
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
# 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"
# Upgrade Couchpotato
# Kill app
sudo service $app stop || true
# 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
fi
# 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
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..."
app_config_file="${final_path}/settings.conf"
# 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
# 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
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"
# 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_backup_if_checksum_is_different --file=$app_config_file
# 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"
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 python_version"
#=================================================
# 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"

154
scripts/ynh_install_python Normal file
View file

@ -0,0 +1,154 @@
#!/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"
# 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/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/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
(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 <version>)
# 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. 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.
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 $pyenv_version
then
ynh_install_pyenv
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
# 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
}

78
scripts/ynh_multimedia_3 Normal file
View file

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