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 #14 from YunoHost-Apps/testing

Testing
This commit is contained in:
yalh76 2021-06-06 19:03:19 +02:00 committed by GitHub
commit 06e0d129fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 497 additions and 507 deletions

View file

@ -1,46 +1,55 @@
--- ---
name: Bug report 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. about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
--- ---
**How to post a meaningful bug report** **How to post a meaningful bug report**
1. *Read this whole template first.* 1. *Read this whole template first.*
2. *Determine if you are on the right place:* 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!* - *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.* - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.*
- *If you have a doubt, post here, we will figure it out together.* - *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.* 3. *Delete the italic comments as you write over them below, and remove this guide.*
--- ---
**Describe the bug** ### Describe the bug
*A clear and concise description of what the bug is.* *A clear and concise description of what the bug is.*
**Versions** ### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x - YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* - 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* - Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain: - If yes, please explain:
- Using, or trying to install package version/branch: - 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`* - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
**To Reproduce** ### Steps to reproduce
*Steps to reproduce the behavior.*
- *If you performed a command from the CLI, the command itself is enough. For example:* - *If you performed a command from the CLI, the command itself is enough. For example:*
```sh ```sh
sudo yunohost app install couchpotato sudo yunohost app install the_app
``` ```
- *If you used the webadmin, please perform the equivalent command from the CLI first.* - *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:* - *If the error occurs in your browser, explain what you did:*
1. *Go to '...'* 1. *Go to '...'*
2. *Click on '....'* 2. *Click on '...'*
3. *Scroll down to '....'* 3. *Scroll down to '...'*
4. *See error* 4. *See error*
**Expected behavior** ### 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.* *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** ### 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.*
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.* *If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

View file

@ -1,4 +1,4 @@
## <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> # CouchPotato for YunoHost
[![Integration level](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/couchpotato.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/couchpotato.svg)](https://dash.yunohost.org/appci/app/couchpotato) ![](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) [![Install CouchPotato with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=couchpotato)

View file

@ -1,12 +1,7 @@
# 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 ;; Test complet
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld"
path="/couchpotato" (PATH)" path="/path"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=1

View file

@ -4,7 +4,7 @@ username =
ssl_key = ssl_key =
proxy_server = proxy_server =
ssl_cert = ssl_cert =
data_dir = __DATADIR__ data_dir = __APP_DATA_DIR__
use_proxy = 0 use_proxy = 0
permission_file = 0755 permission_file = 0755
proxy_password = proxy_password =
@ -43,7 +43,7 @@ to = /home/yunohost.multimedia/share/Video/Movies
enabled = __RENAMER__ enabled = __RENAMER__
[blackhole] [blackhole]
directory = __WATCHDIR__ directory = __TRANSMISSION_WATCHDIR__
manual = 0 manual = 0
enabled = __BLACKHOLE__ enabled = __BLACKHOLE__
create_subdir = 0 create_subdir = 0
@ -54,7 +54,7 @@ magnet_file = 0
username = transmission username = transmission
stalled_as_failed = True stalled_as_failed = True
delete_failed = True delete_failed = True
rpc_url = __RPCURL__ rpc_url = __TRANSMISSION_RPCURL__
manual = 0 manual = 0
enabled = __RPC__ enabled = __RPC__
paused = False paused = False
@ -62,7 +62,7 @@ host = 127.0.0.1:9091
delete_files = True delete_files = True
directory = directory =
remove_complete = True remove_complete = True
password = __RPCPASSWORD__ password = __TRANSMISSION_RPCPASSWORD__
[suggestion] [suggestion]
enabled = True enabled = True

View file

@ -3,19 +3,19 @@
"id": "couchpotato", "id": "couchpotato",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Automatic movie downloader", "en": "Automatic movie downloader",
"fr": "Téléchargement automatisé de film" "fr": "Téléchargement automatisé de film"
}, },
"version": "3.0.1~ynh1", "version": "3.0.1~ynh2",
"url": "https://couchpota.to/", "url": "https://couchpota.to/",
"license": "free", "license": "GPL-3.0-only",
"maintainer": { "maintainer": {
"name": "Snipees", "name": "Snipees",
"email": "snipees@wareziens.net", "email": "snipees@wareziens.net",
"url": "https://github.com/Snipees" "url": "https://github.com/Snipees"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.5" "yunohost": ">= 4.2.0"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
@ -26,19 +26,11 @@
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": {
"en": "Choose a domain for CouchPotato",
"fr": "Choisissez un domaine pour CouchPotato"
},
"example": "example.com" "example": "example.com"
}, },
{ {
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": {
"en": "Choose a path for CouchPotato",
"fr": "Choisissez un chemin pour CouchPotato"
},
"example": "/couchpotato", "example": "/couchpotato",
"default": "/couchpotato" "default": "/couchpotato"
} }

View file

@ -1,18 +0,0 @@
## 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)/)

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # 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/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -67,7 +67,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# Backup data # Backup data
ynh_backup --src_path="$app_data_dir" ynh_backup --src_path="$app_data_dir" --is_big
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -8,7 +8,6 @@
source _common.sh source _common.sh
source ynh_install_python source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -39,7 +38,6 @@ final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
app_data_dir=/home/yunohost.app/$app 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 # Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@ -58,17 +56,18 @@ ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_script_progression --message="Configuring firewall..." ynh_script_progression --message="Finding an available port..."
# Find an available port # Find an available port
port=$(ynh_find_port --port=5050) port=$(ynh_find_port --port=5050)
ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=port --value=$port
# Optional: Expose this port publicly # Optional: Expose this port publicly
# (N.B. : you only need to do this if the app actually needs to expose the 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 !) # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port # Open the port
# ynh_script_progression --message="Configuring firewall..."
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port # ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#================================================= #=================================================
@ -78,23 +77,6 @@ ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_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 # CREATE DEDICATED USER
#================================================= #=================================================
@ -103,6 +85,27 @@ ynh_script_progression --message="Configuring system user..."
# Create a system user # Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
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"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
@ -111,17 +114,18 @@ ynh_system_user_create --username=$app --home_dir=$final_path
ynh_script_progression --message="Make data directory..." ynh_script_progression --message="Make data directory..."
# Make directories # Make directories
mkdir -p $app_data_dir mkdir -p "$app_data_dir"
chmod 750 "$app_data_dir"
chmod -R o-rwx "$app_data_dir"
chown -R $app:$app "$app_data_dir"
#================================================= #=================================================
# BUILD COUCHPOTATO # BUILD COUCHPOTATO
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files
chown -R "$app": "$final_path"
ynh_install_python --python_version=$python_version ynh_install_python --python_version=$python_version
ynh_use_python
pushd $final_path pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl /opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
@ -133,82 +137,85 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
# Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app 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 # CONFIGURE TRANSMISSION
#================================================= #=================================================
ynh_script_progression --message="Configuring transmission..." ynh_script_progression --message="Configuring transmission..."
# Variable initialization
rpc=""
blackhole=""
renamer=""
# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. # Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir.
transmission_rpcurl="" transmission_rpcurl=""
transmission_rpcpassword="" transmission_rpcpassword=""
transmission_watchdir="" transmission_watchdir=""
# Check if Transmission is installed # Check if Transmission is installed
if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then if [[ -z $(yunohost app list | grep -q 'id: $transmission') ]]; then
ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..." 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 rpc="0"
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir blackhole="0"
ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer renamer="0"
else else
ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..." ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..."
# Check if the transmission password is in settings # Check if the transmission password is in settings
if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato directly" ynh_script_progression --message="Transmission will be linked to CouchPotato directly"
transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission" transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission"
transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword) 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 rpc="1" # Enable Transmission RPC
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir blackhole="0" # Disable Transmission Watchdir
ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer renamer="1" # Enable Renamer
# If transmission uses YunoHost multimedia, use its folder for the renamer # If transmission uses YunoHost multimedia, use its folder for the renamer
else else
# Check if transmission has watchdir enabled # Check if transmission has watchdir enabled
if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir" ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir"
transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=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 rpc="0" # Disable Transmission RPC
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir blackhole="1" # Enable Transmission Watchdir
ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer renamer="1" # Enable Renamer
# If transmission uses YunoHost multimedia, use its folder for the renamer # If transmission uses YunoHost multimedia, use its folder for the renamer
else else
ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." 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 rpc="0" # Disable Transmission RPC
ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer blackhole="0" # Disable Transmission Watchdir
renamer="0" # Disable Renamer
fi fi
fi fi
fi fi
#================================================= #=================================================
# MODIFY A CONFIG FILE # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." ynh_script_progression --message="Adding a configuration file..."
app_config_file="${final_path}/settings.conf" ynh_add_config --template="../conf/couchpotato.conf" --destination="$final_path/settings.conf"
# Configure App chmod 600 "$final_path/settings.conf"
ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf" chown $app:$app "$final_path/settings.conf"
ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf" #=================================================
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf" # SETUP SYSTEMD
ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf" #=================================================
ynh_script_progression --message="Configuring a systemd service..."
cp -a ../conf/couchpotato.conf $app_config_file # Create a dedicated systemd config
ynh_add_systemd_config
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$app_config_file"
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS
@ -218,29 +225,12 @@ ynh_script_progression --message="Configuring logs..."
# Redirect logs directory # Redirect logs directory
app_logs_dir="/var/log/$app" app_logs_dir="/var/log/$app"
mkdir -p $app_logs_dir mkdir -p $app_logs_dir
chown -R $app $app_logs_dir chown -R $app:$app $app_logs_dir
chmod +x -R $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" 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 # 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 # SETUP LOGROTATE
#================================================= #=================================================
@ -254,7 +244,7 @@ ynh_use_logrotate
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "CouchPotato Daemon" --log "/var/log/$app/$app.log" yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -267,15 +257,19 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." ynh_script_progression --message="Configuring permissions..."
# Open the /api path so that external applications can connect ynh_permission_update --permission="main" --add="visitors"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/api"
# Everyone can access to the api part
# We don't want to display the tile in the sso so we put --show_tile="false"
# And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true"
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload

View file

@ -63,9 +63,9 @@ ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing nginx web server configuration..." ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
@ -93,9 +93,6 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Removing various files..." ynh_script_progression --message="Removing various files..."
# Remove a directory securely
ynh_secure_remove --file="$app_data_dir"
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"

View file

@ -6,10 +6,9 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # 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/_common.sh
source ../settings/scripts/ynh_install_python source ../settings/scripts/ynh_install_python
source ../settings/scripts/ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -25,7 +24,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -43,25 +42,16 @@ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
test ! -d $app_data_dir \
|| ynh_die --message="There is already a directory: $app_data_dir "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the nginx configuration..." ynh_script_progression --message="Restoring the NGINX configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
@ -71,12 +61,15 @@ ynh_script_progression --message="Recreating the dedicated system user..."
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring user rights..." ynh_script_progression --message="Restoring the app main directory..."
# Restore permissions on app files ynh_restore_file --origin_path="$final_path"
chown -R $app:$app $final_path
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -93,13 +86,10 @@ ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files
chown -R "$app": "$final_path"
ynh_install_python --python_version=$python_version ynh_install_python --python_version=$python_version
ynh_use_python
pushd $final_path pushd $final_path
pyenv virtualenv $python_version $app
/opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$app/bin/pip install cheetah /opt/pyenv/versions/$app/bin/pip install cheetah
popd popd
@ -109,26 +99,26 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Restoring the data directory..." ynh_script_progression --message="Restoring the data directory..."
ynh_restore_file --origin_path="$app_data_dir" ynh_restore_file --origin_path="$app_data_dir" --not_mandatory
chown -R $app:$app $app_data_dir mkdir -p "$app_data_dir"
chmod 750 "$app_data_dir"
chmod -R o-rwx "$app_data_dir"
chown -R $app:$app "$app_data_dir"
#================================================= #=================================================
# INSTALL YUNOHOST MULTIMEDIA # INSTALL YUNOHOST MULTIMEDIA
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
# Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app 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 # CONFIGURE LOGS
#================================================= #=================================================
@ -137,7 +127,7 @@ ynh_script_progression --message="Configuring logs..."
# Redirect logs directory # Redirect logs directory
app_logs_dir="/var/log/$app" app_logs_dir="/var/log/$app"
mkdir -p $app_logs_dir mkdir -p $app_logs_dir
chown -R $app $app_logs_dir chown -R $app:$app $app_logs_dir
chmod +x -R $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" ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py"
@ -147,14 +137,14 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
ynh_script_progression --message="Restoring the systemd configuration..." ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -175,7 +165,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload

View file

@ -8,7 +8,6 @@
source _common.sh source _common.sh
source ynh_install_python source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,10 +23,6 @@ port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_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) 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 # CHECK VERSION
#================================================= #=================================================
@ -35,26 +30,34 @@ ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# 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
#=================================================
# 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"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring 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.\
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 final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]; then
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
@ -67,69 +70,17 @@ if [ -z "$app_data_dir" ]; then
ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir
fi fi
#================================================= # Cleaning legacy permissions
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP if ynh_legacy_permissions_exists; then
#================================================= ynh_legacy_permissions_delete_all
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app ynh_app_setting_delete --app=$app --key=is_public
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 fi
#================================================= # Create a permission if needed
# NGINX CONFIGURATION if ! ynh_permission_exists --permission="api"; then
#================================================= ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
ynh_script_progression --message="Upgrading nginx web server configuration..." fi
# 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 # CREATE DEDICATED USER
@ -139,6 +90,39 @@ ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
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
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# 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
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
@ -146,10 +130,8 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
ynh_script_progression --message="Building CouchPotato..." ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files
chown -R "$app": "$final_path"
ynh_install_python --python_version=$python_version ynh_install_python --python_version=$python_version
ynh_use_python
pushd $final_path pushd $final_path
/opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl /opt/pyenv/versions/$python_version/bin/pip install --upgrade pyopenssl
@ -161,84 +143,77 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
# Creates the "Movies" subfolder in "Video"
mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app 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 # CONFIGURE TRANSMISSION
#================================================= #=================================================
ynh_script_progression --message="Configuring transmission..." ynh_script_progression --message="Configuring transmission..."
# Variable initialization
rpc=""
blackhole=""
renamer=""
# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. # Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir.
transmission_rpcurl="" transmission_rpcurl=""
transmission_rpcpassword="" transmission_rpcpassword=""
transmission_watchdir="" transmission_watchdir=""
# Check if Transmission is installed # Check if Transmission is installed
if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then if [[ -z $(yunohost app list | grep -q 'id: $transmission') ]]; then
ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..." 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 rpc="0"
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir blackhole="0"
ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer renamer="0"
else else
ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..." ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..."
# Check if the transmission password is in settings # Check if the transmission password is in settings
if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato directly" ynh_script_progression --message="Transmission will be linked to CouchPotato directly"
transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission" transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission"
transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword) 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 rpc="1" # Enable Transmission RPC
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir blackhole="0" # Disable Transmission Watchdir
ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer renamer="1" # Enable Renamer
# If transmission uses YunoHost multimedia, use its folder for the renamer # If transmission uses YunoHost multimedia, use its folder for the renamer
else else
# Check if transmission has watchdir enabled # Check if transmission has watchdir enabled
if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir" ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir"
transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=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 rpc="0" # Disable Transmission RPC
ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir blackhole="1" # Enable Transmission Watchdir
ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer renamer="1" # Enable Renamer
# If transmission uses YunoHost multimedia, use its folder for the renamer # If transmission uses YunoHost multimedia, use its folder for the renamer
else else
ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." 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 rpc="0" # Disable Transmission RPC
ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer blackhole="0" # Disable Transmission Watchdir
renamer="0" # Disable Renamer
fi fi
fi fi
fi fi
#================================================= #=================================================
# MODIFY A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." ynh_script_progression --message="Updating a configuration file..."
app_config_file="${final_path}/settings.conf" ynh_add_config --template="../conf/couchpotato.conf" --destination="$final_path/settings.conf"
# Configure App chmod 600 "$final_path/settings.conf"
ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf" chown $app:$app "$final_path/settings.conf"
ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf"
ynh_backup_if_checksum_is_different --file=$app_config_file
cp -a ../conf/couchpotato.conf $app_config_file
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$app_config_file"
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS
@ -249,6 +224,16 @@ ynh_script_progression --message="Configuring logs..."
app_logs_dir="/var/log/$app" 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" 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="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
@ -258,31 +243,11 @@ ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= #=================================================
# SETUP SYSTEMD # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Upgrading systemd configuration..." ynh_script_progression --message="Integrating service in YunoHost..."
# Create a dedicated systemd config yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
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=$app --key=unprotected_uris --value="/api"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -294,7 +259,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload

View file

@ -1,52 +1,91 @@
#!/bin/bash #!/bin/bash
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args ynh_python_try_bash_extension() {
pyenv_version=1.2.19 if [ -x src/configure ]; then
pyenv_virtualenv_version=1.1.5 src/configure && make -C src || {
pyenv_install_dir="/opt/pyenv" ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
}
fi
}
pyenv_install_dir="/opt/pyenv"
python_version_path="$pyenv_install_dir/versions"
# PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable. # PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable.
export PYENV_ROOT="$pyenv_install_dir" export PYENV_ROOT="$pyenv_install_dir"
# Required dependencies # 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" pyenv_dependencies="build-essential libssl1.0-dev|libssl-dev zlib1g-dev libbz2-dev libreadline-dev|libedit-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git"
# Install python version management # Load the version of Python for an app, and set variables.
# #
# [internal] # ynh_use_python has to be used in any app scripts before using Python for the first time.
# This helper will provide alias and variables to use in your scripts.
# #
# usage: ynh_install_pyenv # To use pip or Python, use the alias `ynh_pip` and `ynh_python`
ynh_install_pyenv () { # Those alias will use the correct version installed for the app
echo "Installation of pyenv - python version management" >&2 # For example: use `ynh_pip install` instead of `pip install`
# Build an app.src for pyenv #
mkdir -p "../conf" # With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_pip` and `$ynh_python`
echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v${pyenv_version}.tar.gz # And propagate $PATH to sudo with $ynh_python_load_path
SOURCE_SUM=e93466735ac9c34d68b7d5d71f32c16a2b4b1a6a1adffb85acc4126a3398b9d0" > "../conf/pyenv.src" # Exemple: `ynh_exec_as $app $ynh_python_load_path $ynh_pip install`
# Download and extract pyenv #
ynh_setup_source "$pyenv_install_dir" pyenv # $PATH contains the path of the requested version of Python.
# However, $PATH is duplicated into $python_path to outlast any manipulation of $PATH
# You can use the variable `$ynh_python_load_path` to quickly load your Python version
# in $PATH for an usage into a separate script.
# Exemple: $ynh_python_load_path $final_path/script_that_use_pip.sh`
#
#
# Finally, to start a Python service with the correct version, 2 solutions
# Either the app is dependent of python or pip, but does not called it directly.
# In such situation, you need to load PATH
# `Environment="__YNH_PYTHON_LOAD_ENV_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_PYTHON_LOAD_ENV_PATH__ with $ynh_python_load_path
#
# Or Python start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_PYTHON__ my_app run`
# You will replace __YNH_PYTHON__ with $ynh_python
#
#
# one other variable is also available
# - $python_path: The absolute path to Python binaries for the chosen version.
#
# usage: ynh_use_python
#
# Requires YunoHost version 2.7.12 or higher.
ynh_use_python () {
python_version=$(ynh_app_setting_get --app=$app --key=python_version)
# Build an app.src for pyenv-virtualenv # Get the absolute path of this version of Python
mkdir -p "../conf" python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin"
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 # Allow alias to be used into bash script
./src/configure && make -C src) shopt -s expand_aliases
# Create shims directory if needed # Create an alias for the specific version of Python and a variable as fallback
if [ ! -d $pyenv_install_dir/shims ] ; then ynh_python="$python_path/python"
mkdir $pyenv_install_dir/shims alias ynh_python="$ynh_python"
fi # And pip
ynh_pip="$python_path/pip"
alias ynh_pip="$ynh_pip"
# Load the path of this version of Python in $PATH
if [[ :$PATH: != *":$python_path"* ]]; then
PATH="$python_path:$PATH"
fi
# Create an alias to easily load the PATH
ynh_python_load_path="PATH=$PATH"
# Sets the local application-specific Python version
pushd $final_path
$pyenv_install_dir/bin/pyenv local $python_version
popd
} }
# Install a specific version of python # Install a specific version of Python
# #
# ynh_install_python will install the version of python provided as argument by using pyenv. # 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 # 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) # for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
@ -56,99 +95,188 @@ fi
# When not possible (e.g. in systemd service definition), please use direct path # When not possible (e.g. in systemd service definition), please use direct path
# to pyenv shims (e.g. $PYENV_ROOT/shims/bundle) # to pyenv shims (e.g. $PYENV_ROOT/shims/bundle)
# #
# usage: ynh_install_python python_version user # usage: ynh_install_python --python_version=python_version
# | arg: -v, --python_version= - Version of python to install. # | arg: -v, --python_version= - Version of Python to install.
# 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. # Requires YunoHost version 2.7.12 or higher.
ynh_install_python () { ynh_install_python () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
declare -Ar args_array=( [v]=python_version= ) local legacy_args=v
# Use pyenv, https://github.com/pyenv/pyenv to manage the python versions local -A args_array=( [v]=python_version= )
local python_version local python_version
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
# Create $pyenv_install_dir # Install required dependencies
mkdir -p "$pyenv_install_dir/plugins/pyenv-virtualenv" ynh_add_app_dependencies --package="$pyenv_dependencies"
# Load pyenv path in PATH # Load pyenv path in PATH
CLEAR_PATH="$pyenv_install_dir/bin:$PATH" local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of python prior installation # Remove /usr/local/bin in PATH in case of Python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing python binary, to avoid to block pyenv # Move an existing Python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv #test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# If pyenv is not previously setup, install it # Install or update pyenv
if ! type pyenv > /dev/null 2>&1 pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)"
then if [ -n "$pyenv" ]; then
ynh_install_pyenv ynh_print_info --message="pyenv already seems installed in \`$pyenv'."
elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt $pyenv_version pushd "${pyenv%/*/*}"
then if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then
ynh_install_pyenv echo "Trying to update with git..."
elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt $pyenv_virtualenv_version git pull -q --tags origin master
then cd ..
ynh_install_pyenv ynh_python_try_bash_extension
fi fi
popd
else
ynh_print_info --message="Installing pyenv with git..."
mkdir -p $pyenv_install_dir
pushd $pyenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_python_try_bash_extension
pyenv=$pyenv_install_dir/bin/pyenv
popd
fi
# Restore /usr/local/bin in PATH (if needed) pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)"
PATH=$CLEAR_PATH if [ -n "$pyenv_virtualenv" ]; then
ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'."
pushd "${pyenv_virtualenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv-virtualenv.git"; then
ynh_print_info --message="Trying to update pyenv-virtualenv with git..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing pyenv-virtualenv with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv"
fi
# And replace the old python binary pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)"
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python if [ -n "$pyenv_latest" ]; then
ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'."
pushd "${pyenv_latest%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
ynh_print_info --message="Trying to update xxenv-latest with git..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${pyenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest"
fi
# Install required dependencies # Enable caching
ynh_add_app_dependencies --package="$pyenv_dependencies" mkdir -p "${pyenv_install_dir}/cache"
# Install the requested version of python # Create shims directory if needed
pyenv install --skip-existing $python_version mkdir -p "${pyenv_install_dir}/shims"
# Store the ID of this app and the version of python requested for it # Restore /usr/local/bin in PATH
echo "$YNH_APP_ID:$python_version" | tee --append "$pyenv_install_dir/ynh_app_version" PATH=$CLEAR_PATH
# Store python_version into the config of this app # And replace the old Python binary
ynh_app_setting_set --app=$app --key=python_version --value=$python_version # test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# Set environment for python users # Install the requested version of Python
echo "#pyenv local final_python_version=$(pyenv latest --print $python_version)
ynh_print_info --message="Installation of Python-$python_version"
pyenv install --skip-existing $final_python_version > /dev/null 2>&1
# Store python_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version
# Remove app virtualenv
if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1`
then
pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
fi
# Create app virtualenv
pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME
# Cleanup Python versions
ynh_cleanup_python
# Set environment for Python users
echo "#pyenv
export PYENV_ROOT=$pyenv_install_dir export PYENV_ROOT=$pyenv_install_dir
export PATH=\"$pyenv_install_dir/bin:$PATH\" export PATH=\"$pyenv_install_dir/bin:$PATH\"
eval \"\$(pyenv init -)\" eval \"\$(pyenv init -)\"
#pyenv" > /etc/profile.d/pyenv.sh #pyenv" > /etc/profile.d/pyenv.sh
# Load the right environment for the Installation # Load the environment
eval "$(pyenv init -)" eval "$(pyenv init -)"
(cd $final_path
pyenv local $python_version)
} }
# Remove the version of python used by the app. # Remove the version of Python used by the app.
# #
# This helper will check if another app uses the same version of python, # This helper will also cleanup Python versions
# if not, this version of python will be removed.
# If no other app uses python, pyenv will be also removed.
# #
# usage: ynh_remove_python # usage: ynh_remove_python
ynh_remove_python () { ynh_remove_python () {
python_version=$(ynh_app_setting_get --app=$app --key=python_version) local python_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=python_version)
# Remove the line for this app # Load pyenv path in PATH
sed --in-place "/$YNH_APP_ID:$python_version/d" "$pyenv_install_dir/ynh_app_version" local CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# If no other app uses this version of python, remove it. # Remove /usr/local/bin in PATH in case of Python prior installation
if ! grep --quiet "$python_version" "$pyenv_install_dir/ynh_app_version" PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
then
$pyenv_install_dir/bin/pyenv uninstall --force $python_version
fi
# Remove pyenv environment configuration pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME
rm /etc/profile.d/pyenv.sh
# If no other app uses pyenv, remove pyenv and dedicated group # Remove the line for this app
if [ ! -s "$pyenv_install_dir/ynh_app_version" ] ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version
then
ynh_secure_remove --file="$pyenv_install_dir" # Cleanup Python versions
fi ynh_cleanup_python
} }
# Remove no more needed versions of Python used by the app.
#
# This helper will check what Python version are no more required,
# and uninstall them
# If no app uses Python, pyenv will be also removed.
#
# usage: ynh_cleanup_python
ynh_cleanup_python () {
# List required Python version
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
local required_python_versions=""
for installed_app in $installed_apps
do
local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version")
if [[ $installed_app_python_version ]]
then
required_python_versions="${installed_app_python_version}\n${required_python_versions}"
fi
done
# Remove no more needed Python version
local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/')
for installed_python_version in $installed_python_versions
do
if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Python-$installed_python_version"
$pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version
fi
done
# If none Python version is required
if [[ ! $required_python_versions ]]
then
# Remove pyenv environment configuration
ynh_print_info --message="Removing of pyenv-$pyenv_version"
ynh_secure_remove --file="$pyenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/pyenv.sh"
fi
}

View file

@ -1,78 +0,0 @@
#!/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
}