1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/transmission_ynh.git synced 2024-09-04 01:46:12 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2022-07-03 20:36:04 +02:00
parent 143a4eded5
commit 3ac30d2f81
19 changed files with 560 additions and 409 deletions

137
.github/workflows/updater.sh vendored Normal file
View file

@ -0,0 +1,137 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
# Remove this exit command when you are ready to run this Action
exit 1
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1)
assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'"))
# Later down the script, we assume the version has only digits and dots
# Sometimes the release name starts with a "v", so let's filter it out.
# You may need more tweaks here if the upstream repository has different naming conventions.
if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then
version=${version:1}
fi
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $version"
echo "VERSION=$version" >> $GITHUB_ENV
echo "REPO=$repo" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV
# Proceed only if the retrieved version is greater than the current one
if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then
echo "::warning ::No new version available"
exit 0
# Proceed only if a PR for this new version does not already exist
elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
echo "::warning ::A branch already exists for this update"
exit 0
fi
# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.)
echo "${#assets[@]} available asset(s)"
#=================================================
# UPDATE SOURCE FILES
#=================================================
# Here we use the $assets variable to get the resources published in the upstream release.
# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like.
# Let's loop over the array of assets URLs
for asset_url in ${assets[@]}; do
echo "Handling asset at $asset_url"
# Assign the asset to a source file in conf/ directory
# Here we base the source file name upon a unique keyword in the assets url (admin vs. update)
# Leave $src empty to ignore the asset
case $asset_url in
*"admin"*)
src="app"
;;
*"update"*)
src="app-upgrade"
;;
*)
src=""
;;
esac
# If $src is not empty, let's process the asset
if [ ! -z "$src" ]; then
# Create the temporary directory
tempdir="$(mktemp -d)"
# Download sources and calculate checksum
filename=${asset_url##*/}
curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
EOT
echo "... conf/$src.src updated"
else
echo "... asset ignored"
fi
done
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# Any action on the app's source code can be done.
# The GitHub Action workflow takes care of committing all changes after this script ends.
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
# No need to update the README, yunohost-bot takes care of it
# The Action will proceed only if the PROCEED environment variable is set to true
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

View file

@ -1,8 +1,7 @@
;; Test complet
auto_remove=1
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
domain="domain.tld"
path="/path"
; Checks
pkg_linter=1
setup_sub_dir=1
@ -11,14 +10,14 @@
setup_private=1
setup_public=0
upgrade=1
# 1.0
upgrade=1 from_commit=7d887f6bc1e29ce94de703517d5302580cbb8a7e
# 1.0~ynh4
upgrade=1 from_commit=c65b76e919089f3f88d2522cef2300db6f78201f
backup_restore=1
multi_instance=0
port_already_use=0
change_url=1
;;; Options
Email=
Notification=down
;;; Upgrade options
; commit=7d887f6bc1e29ce94de703517d5302580cbb8a7e
name= Add acl dependency. Mar 3, 2018
manifest_arg=domain=DOMAIN&path=PATH&
Notification=none

View file

@ -1,23 +1,29 @@
location __PATH__/transmission {
proxy_pass http://127.0.0.1:__PORT____PATH__/transmission;
proxy_pass http://127.0.0.1:__PORT____PATH__/transmission;
more_clear_input_headers 'Accept-Encoding';
client_max_body_size 8M;
client_max_body_size 8M;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
more_clear_input_headers 'Accept-Encoding';
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
location __PATH__/ {
proxy_pass http://127.0.0.1:__PORT__/;
proxy_pass http://127.0.0.1:__PORT____PATH__/;
more_clear_input_headers 'Accept-Encoding';
client_max_body_size 8M;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
location __PATH__/downloads/ {
alias /home/yunohost.transmission/completed/;
autoindex on;
autoindex_exact_size off;
alias __DATADIR__/completed/;
autoindex on;
autoindex_exact_size off;
more_clear_input_headers 'Accept-Encoding';
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
more_clear_input_headers 'Accept-Encoding';
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -12,7 +12,7 @@
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 4,
"dht-enabled": true,
"download-dir": "/home/yunohost.transmission/completed",
"download-dir": "__DATADIR__/completed",
"download-limit": 100,
"download-limit-enabled": 0,
"download-queue-enabled": true,
@ -20,7 +20,7 @@
"encryption": 1,
"idle-seeding-limit": 30,
"idle-seeding-limit-enabled": false,
"incomplete-dir": "/home/yunohost.transmission/progress",
"incomplete-dir": "__DATADIR__/progress",
"incomplete-dir-enabled": true,
"lpd-enabled": false,
"max-peers-global": 200,
@ -37,7 +37,7 @@
"pex-enabled": true,
"port-forwarding-enabled": false,
"preallocation": 1,
"prefetch-enabled": 1,
"prefetch-enabled": true,
"queue-stalled-enabled": true,
"queue-stalled-minutes": 30,
"ratio-limit": 2,
@ -48,9 +48,9 @@
"rpc-enabled": true,
"rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": false,
"rpc-password": "__RPC_PASSWORD_TO_CHANGE__",
"rpc-password": "__RPCPASSWORD__",
"rpc-port": __PORT__,
"rpc-url": "__PATH__transmission/",
"rpc-url": "__PATH_LESS__transmission/",
"rpc-username": "transmission",
"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": false,
@ -70,6 +70,6 @@
"upload-limit-enabled": 0,
"upload-slots-per-torrent": 14,
"utp-enabled": true,
"watch-dir": "/home/yunohost.transmission/watched",
"watch-dir": "__DATADIR__/watched",
"watch-dir-enabled": true
}

0
doc/.gitkeep Normal file
View file

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
Transmission is a fast, easy, and free BitTorrent client.

1
doc/DESCRIPTION_fr.md Normal file
View file

@ -0,0 +1 @@
Transmission est un client BitTorrent libre, efficace et simple.

21
doc/DISCLAIMER.md Normal file
View file

@ -0,0 +1,21 @@
## YunoHost specific features
* Integration with YunoHost Multimedia directories
## Additionnal informations
Alternative to WebUI :
You can use remote client on different platforms to manage your Transmission server:
* Dekstop: Transmission-remote-GUI: https://github.com/transmission-remote-gui/transgui
* Mobile: Transdroid: http://www.transdroid.org/
* More clients here: https://transmissionbt.com/resources/
You can use the following information to connect your server:
* Remote host: Your domain or IP address (don't add folder)
* Port: 443
* SSL: Enabled
* User: Your Yunohost Username
* Password: Password of the Yunohost User above
* RPC Path: /torrent/transmission/rpc (if you used the standard folder)

21
doc/DISCLAIMER_fr.md Normal file
View file

@ -0,0 +1,21 @@
## Caractéristiques spécifiques YunoHost
* Intégration avec les répertoires Multimédias de YunoHost
## Informations additionnelles
Alternative à WebUI :
Vous pouvez utiliser le client de contrôle à distance des différentes plateformes pour gérer votre serveur Transmission :
* Bureau : Transmission-remote-GUI : https://github.com/transmission-remote-gui/transgui
* Mobile : Transdroid : http://www.transdroid.org/
* Plus de clients ici : https://transmissionbt.com/resources/
Vous pouvez utiliser les informations suivantes pour vous connecter à votre serveur :
* Hôte distant : Votre domaine ou adresse IP (n'ajoutez pas le répertoire)
* Port : 443
* SSL : Activé
* Utilisateur : Votre nom d'utilisateur YunoHost
* Mot de passe : Le mot de passe de l'utilisateur YunoHost utilisé
* Répertoire RPC : `/torrent/transmission/rpc` (si vous utilisez le répertoire par défaut)

0
doc/screenshots/.gitkeep Normal file
View file

View file

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

View file

@ -1,39 +1,44 @@
{
"name": "Transmission",
"id": "transmission",
"packaging_format": 1,
"description": {
"en": "A Fast, Easy, and Free BitTorrent Client",
"fr": "Un client BitTorrent libre et rapide"
},
"version": "1.0~ynh4",
"url": "https://www.transmissionbt.com/",
"license": "GPL-3.0",
"maintainer": {
"name": "",
"email": ""
},
"requirements": {
"yunohost": ">= 4.1.7"
"name": "Transmission",
"id": "transmission",
"packaging_format": 1,
"description": {
"en": "A Fast, Easy, and Free BitTorrent Client",
"fr": "Un client BitTorrent libre et rapide"
},
"multi_instance": false,
"services": [
"nginx",
"transmission-daemon"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain",
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"example": "/transmission",
"default": "/transmission"
}
]
}
"version": "2.94~ynh1",
"url": "https://www.transmissionbt.com",
"upstream": {
"license": "GPL-3.0",
"website": "https://www.transmissionbt.com",
"admindoc": "https://github.com/transmission/transmission/wiki",
"code": "https://github.com/transmission/transmission"
},
"license": "GPL-3.0",
"maintainer": {
"name": "",
"email": ""
},
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": false,
"services": [
"nginx",
"transmission-daemon"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/transmission",
"default": "/transmission"
}
]
}
}

View file

@ -18,45 +18,3 @@ pkg_dependencies="transmission-daemon transmission-cli transmission-common acl"
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
# 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 2>&1
# 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"
}

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
@ -24,6 +25,7 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -31,7 +33,13 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP OF THE NGINX CONFIGURATION
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="$datadir" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
@ -39,24 +47,18 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP TRANSMISSION CONFIGURATION
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/transmission-daemon/settings.json"
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_backup --src_path="/etc/sysctl.d/90-transmission.conf"
ynh_backup --src_path="/etc/sysctl.d/90-transmission.conf"
fi
#=================================================
# BACKUP DATA
#=================================================
ynh_backup --src_path="/usr/share/transmission"
ynh_backup --src_path="/var/lib/transmission-daemon"
ynh_backup --src_path="/home/yunohost.transmission" --is_big
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -107,8 +107,12 @@ fi
# UPDATE TRANSMISSION CONFIGURATION
#=================================================
ynh_backup_if_checksum_is_different --file="/etc/transmission-daemon/settings.json"
ynh_replace_string --match_string="rpc-url\": \"${old_path%/}/transmission/" --replace_string="rpc-url\": \"${new_path%/}/transmission/" --target_file="/etc/transmission-daemon/settings.json"
ynh_store_file_checksum --file="/etc/transmission-daemon/settings.json"
#=================================================
# GENERIC FINALISATION
#=================================================

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,9 +10,12 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -25,8 +28,10 @@ path_url=$YNH_APP_ARG_PATH
app=$YNH_APP_INSTANCE_NAME
rpcpassword=$(ynh_string_random)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
@ -40,30 +45,30 @@ ynh_script_progression --message="Storing installation settings..." --weight=2
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=rpcpassword --value="$rpcpassword"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN PORTS
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=16
# Find a free port
# Find an available port
port=$(ynh_find_port --port=9091)
# Open this port
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_app_setting_set --app=$app --key=port --value=$port
# Find a free port
peer_port=$(ynh_find_port --port=51413)
# Open this port
ynh_exec_warn_less yunohost firewall allow Both $peer_port
ynh_app_setting_set --app=$app --key=peer_port --value=$peer_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 Both $peer_port
#=================================================
# INSTALL TRANSMISSION
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing Transmission..." --weight=16
ynh_script_progression --message="Installing dependencies..." --weight=16
ynh_install_app_dependencies $pkg_dependencies
@ -78,6 +83,23 @@ then
ynh_install_app_dependencies $pkg_dependencies --reinstall
fi
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir/{progress,completed,watched}
chmod -R 764 $datadir
chmod -R 777 $datadir/watched
chown -R debian-transmission:www-data "$datadir"
chown -R debian-transmission: $datadir/{progress,watched}
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -87,59 +109,33 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
# ADD A CONFIGURATION
#=================================================
# CREATE DIRECTORIES
#=================================================
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
chown -R debian-transmission:www-data /home/yunohost.transmission/
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
chmod -R 764 /home/yunohost.transmission
chmod -R 777 /home/yunohost.transmission/watched
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Configuring Transmission..." --weight=2
ynh_script_progression --message="Adding a configuration file..." --weight=2
# Transmission has to be stopped before modifying its config
ynh_systemd_action --service_name=transmission-daemon --action=stop
# Create a RPC password
rpcpassword=$(ynh_string_random)
ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword"
ynh_replace_string --match_string="__RPC_PASSWORD_TO_CHANGE__" --replace_string="$rpcpassword" --target_file=../conf/settings.json
if [ "$path_url" != "/" ]
then
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url/" --target_file=../conf/settings.json
path_less="$path_url/"
else
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/settings.json
path_less="$path_url"
fi
ynh_replace_string --match_string="__PEER_PORT__" --replace_string="$peer_port" --target_file=../conf/settings.json
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/settings.json
cp ../conf/settings.json /etc/transmission-daemon/settings.json
ynh_add_config --template="../conf/settings.json" --destination="/etc/transmission-daemon/settings.json"
chmod 400 "/etc/transmission-daemon/settings.json"
chown debian-transmission:debian-transmission "/etc/transmission-daemon/settings.json"
if [ -e /proc/sys/net/core/rmem_max ]
then
cp ../conf/90-transmission.conf /etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
ynh_add_config --template="../conf/90-transmission.conf" --destination="/etc/sysctl.d/90-transmission.conf"
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
chmod 400 "/etc/sysctl.d/90-transmission.conf"
chown debian-transmission:debian-transmission "/etc/sysctl.d/90-transmission.conf"
ynh_store_file_checksum --file=/etc/transmission-daemon/settings.json
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_store_file_checksum --file=/etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
#=================================================
@ -149,11 +145,11 @@ ynh_script_progression --message="Adding multimedia directories..." --weight=4
ynh_multimedia_build_main_dir
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir" --dest_dir="share/Torrents"
# And share completed directory
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir/completed" --dest_dir="share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
ynh_multimedia_addfolder --source_dir="$datadir/watched" --dest_dir="share/Torrent to download"
#=================================================
# PATCH SOURCE TO ADD A DOWNLOAD BUTTON
@ -163,21 +159,23 @@ cp ../sources/extra_files/app/toolbar-downloads.png /usr/share/transmission/web/
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
ynh_replace_string "<div id=\"toolbar-inspector\" title=\"Toggle Inspector\"></div>" "<div id=\"toolbar-inspector\" title=\"Toggle Inspector\"></div><div id=\"toolbar-separator\"></div><a href=\"../../downloads/\" id=\"toolbar-downloads\" title=\"Downloads\" target=\"_blank\"></a>" /usr/share/transmission/web/index.html
#=================================================
# START TRANSMISSION
#=================================================
ynh_script_progression --message="Starting Transmission..."
ynh_systemd_action --service_name=transmission-daemon --action=start
#=================================================
# GENERIC FINALISATION
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=transmission-daemon --action="start"
#=================================================
# RELOAD NGINX
#=================================================

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -19,29 +19,39 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
peer_port=$(ynh_app_setting_get --app=$app --key=peer_port)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if yunohost service status transmission-daemon >/dev/null 2>&1
then
ynh_script_progression --message="Removing $app service..." --weight=8
ynh_script_progression --message="Removing $app service integration..." --weight=8
yunohost service remove transmission-daemon
fi
#=================================================
# REMOVE TRANSMISSION-DAEMON
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing transmission..." --weight=9
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=9
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# CLOSE THE PORTS
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
@ -56,20 +66,12 @@ then
ynh_exec_warn_less yunohost firewall disallow Both $peer_port
fi
#=================================================
# REMOVE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE DATA
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing transmission data..."
ynh_script_progression --message="Removing various files..."
# Web interface
ynh_secure_remove --file=/usr/share/transmission
@ -78,16 +80,16 @@ ynh_secure_remove --file=/var/lib/transmission-daemon
# Kernel parameters
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_secure_remove --file=/etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
ynh_secure_remove --file=/etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
#=================================================
# GENERIC FINALISATION
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user"
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user
ynh_system_user_delete --username=debian-transmission

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
@ -13,13 +14,16 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@ -27,23 +31,69 @@ 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)
peer_port=$(ynh_app_setting_get --app=$app --key=peer_port)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..."
ynh_restore_file --origin_path="$datadir" --not_mandatory
mkdir -p $datadir/{progress,completed,watched}
chmod -R 764 $datadir
chmod -R 777 $datadir/watched
chown -R debian-transmission:www-data "$datadir"
chown -R debian-transmission: $datadir/{progress,watched}
#=================================================
# STANDARD RESTORE STEPS
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=16
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=2
# Transmission has to be stopped before modifying its config
ynh_systemd_action --service_name=transmission-daemon --action=stop
ynh_secure_remove --file=/etc/transmission-daemon/settings.json
ynh_restore_file --origin_path=/etc/transmission-daemon/settings.json
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_restore_file --origin_path="/etc/sysctl.d/90-transmission.conf"
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
ynh_secure_remove --file=/usr/share/transmission
ynh_restore_file --origin_path=/usr/share/transmission
ynh_secure_remove --file=/var/lib/transmission-daemon
ynh_restore_file --origin_path=/var/lib/transmission-daemon
#=================================================
# OPEN PORTS
#=================================================
@ -52,57 +102,6 @@ ynh_script_progression --message="Configuring firewall..." --weight=13
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_exec_warn_less yunohost firewall allow Both $peer_port
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL TRANSMISSION
#=================================================
ynh_script_progression --message="Reinstalling Transmission..." --weight=16
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE TRANSMISSION CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring Transmission configuration..." --weight=2
# Transmission has to be stopped before modifying its config
ynh_systemd_action --service_name=transmission-daemon --action=stop
ynh_secure_remove --file=/etc/transmission-daemon/settings.json
ynh_restore_file --origin_path=/etc/transmission-daemon/settings.json
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_restore_file --origin_path="/etc/sysctl.d/90-transmission.conf"
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
#=================================================
# RESTORE DATA
#=================================================
ynh_script_progression --message="Restoring transmission data..."
ynh_secure_remove --file=/usr/share/transmission
ynh_restore_file --origin_path=/usr/share/transmission
ynh_secure_remove --file=/var/lib/transmission-daemon
ynh_restore_file --origin_path=/var/lib/transmission-daemon
# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup.
ynh_restore_file --origin_path="/home/yunohost.transmission" --not_mandatory
#=================================================
# RESTORE USER RIGHTS
#=================================================
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
chown -R debian-transmission:www-data /home/yunohost.transmission/
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
chmod -R 640 /home/yunohost.transmission
chmod -R 777 /home/yunohost.transmission/watched
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
@ -110,25 +109,26 @@ ynh_script_progression --message="Adding multimedia directories..." --weight=4
ynh_multimedia_build_main_dir
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir" --dest_dir="share/Torrents"
# And share completed directory
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir/completed" --dest_dir="share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
ynh_multimedia_addfolder --source_dir="$datadir/watched" --dest_dir="share/Torrent to download"
#=================================================
# START TRANSMISSION
#=================================================
ynh_script_progression --message="Starting transmission..."
ynh_systemd_action --service_name=transmission-daemon --action=start
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=transmission-daemon --action=start
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -20,13 +20,40 @@ 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)
peer_port=$(ynh_app_setting_get --app=$app --key=peer_port)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
rpcpassword=$(ynh_app_setting_get --app=$app --key=rpcpassword)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
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)..." --weight=3
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# 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=transmission-daemon --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -37,6 +64,7 @@ if [ -z "$port" ]; then
ynh_app_setting_set --app=$app --key=port --value=$port
fi
if [ -z "$peer_port" ]; then
peer_port=51413
ynh_app_setting_set --app=$app --key=peer_port --value=$peer_port
@ -45,30 +73,23 @@ fi
# Add peer_port also on UDP.
ynh_exec_warn_less yunohost firewall allow UDP $peer_port
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
# Inform the backup/restore process that it should not save the data directory
# Use only for the previous backup script that doesn't set 'is_big'
ynh_app_setting_set $app backup_core_only 1
# Backup the current version of the app
ynh_backup_before_upgrade
# Remove the option backup_core_only after the backup.
ynh_app_setting_delete $app backup_core_only
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
# If datadir doesn't exist, create it
if [ -z "$datadir" ]; then
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mv /home/yunohost.transmission/progress $datadir/progress
mv /home/yunohost.transmission/completed $datadir/completed
mv /home/yunohost.transmission/watched $datadir/watched
ynh_secure_remove --file="/home/yunohost.transmission/"
fi
#=================================================
# STANDARD UPGRADE STEPS
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -77,74 +98,48 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# CREATE DIRECTORIES
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
mkdir -p $datadir/{progress,completed,watched}
chmod -R 764 $datadir
chmod -R 777 $datadir/watched
chown -R debian-transmission:www-data "$datadir"
chown -R debian-transmission: $datadir/{progress,watched}
#=================================================
# SECURING FILES AND DIRECTORIES
# UPDATE A CONFIG FILE
#=================================================
chown -R debian-transmission:www-data /home/yunohost.transmission/
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
chmod -R 764 /home/yunohost.transmission
chmod -R 777 /home/yunohost.transmission/watched
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Reconfiguring Transmission..." --weight=2
ynh_script_progression --message="Updating a configuration file..." --weight=2
# Transmission has to be stopped before modifying its config
ynh_systemd_action --service_name=transmission-daemon --action=stop
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different --file=/etc/transmission-daemon/settings.json
# Create a RPC password
rpcpassword=$(ynh_string_random)
ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword"
ynh_replace_string --match_string="__RPC_PASSWORD_TO_CHANGE__" --replace_string="$rpcpassword" --target_file=../conf/settings.json
if [ "$path_url" != "/" ]
then
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url/" --target_file=../conf/settings.json
path_less="$path_url/"
else
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/settings.json
path_less="$path_url"
fi
ynh_replace_string --match_string="__PEER_PORT__" --replace_string="$peer_port" --target_file=../conf/settings.json
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/settings.json
cp ../conf/settings.json /etc/transmission-daemon/settings.json
ynh_add_config --template="../conf/settings.json" --destination="/etc/transmission-daemon/settings.json"
chmod 400 "/etc/transmission-daemon/settings.json"
chown debian-transmission:debian-transmission "/etc/transmission-daemon/settings.json"
if [ -e /proc/sys/net/core/rmem_max ]
then
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different --file=/etc/sysctl.d/90-transmission.conf
ynh_add_config --template="../conf/90-transmission.conf" --destination="/etc/sysctl.d/90-transmission.conf"
cp ../conf/90-transmission.conf /etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
chmod 400 "/etc/sysctl.d/90-transmission.conf"
chown debian-transmission:debian-transmission "/etc/sysctl.d/90-transmission.conf"
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum --file=/etc/transmission-daemon/settings.json
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_store_file_checksum --file=/etc/sysctl.d/90-transmission.conf
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
#=================================================
@ -154,11 +149,11 @@ ynh_script_progression --message="Adding multimedia directories..." --weight=3
ynh_multimedia_build_main_dir
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir" --dest_dir="share/Torrents"
# And share completed directory
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
ynh_multimedia_addfolder --source_dir="$datadir/completed" --dest_dir="share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
ynh_multimedia_addfolder --source_dir="$datadir/watched" --dest_dir="share/Torrent to download"
#=================================================
# PATCH SOURCE TO ADD A DOWNLOAD BUTTON
@ -167,25 +162,26 @@ ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --de
cp ../sources/extra_files/app/toolbar-downloads.png /usr/share/transmission/web/style/transmission/images/toolbar-downloads.png
if ! grep --quiet "Inserted by Yunohost install script" /usr/share/transmission/web/style/transmission/common.css
then
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
fi
ynh_replace_string "<div id=\"toolbar-inspector\" title=\"Toggle Inspector\"></div>$" "<div id=\"toolbar-inspector\" title=\"Toggle Inspector\"></div><div id=\"toolbar-separator\"></div><a href=\"../../downloads/\" id=\"toolbar-downloads\" title=\"Downloads\" target=\"_blank\"></a>" /usr/share/transmission/web/index.html
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
#=================================================
# START TRANSMISSION
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting Transmission..." --weight=2
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=transmission-daemon --action=start
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================