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

170 lines
6 KiB
Text
Raw Normal View History

2014-11-11 16:39:27 +01:00
#!/bin/bash
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-06-13 23:37:51 +02:00
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
2017-08-27 22:01:10 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-06-13 23:37:51 +02:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
2017-06-13 23:37:51 +02:00
path_url=$YNH_APP_ARG_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2017-08-27 22:01:10 +02:00
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN PORTS
#=================================================
2013-10-29 14:51:24 +01:00
2017-08-27 22:01:10 +02:00
# Find a free port
port=$(ynh_find_port 9091)
# Open this port
yunohost firewall allow --no-upnp TCP $port >/dev/null 2>&1
2017-06-13 23:37:51 +02:00
ynh_app_setting_set $app port $port
2013-10-29 14:14:27 +01:00
2017-08-27 22:01:10 +02:00
# Find a free port
peer_port=$(ynh_find_port 51413)
# Open this port
2018-03-03 18:53:33 +01:00
yunohost firewall allow Both $peer_port >/dev/null 2>&1
2017-06-13 23:37:51 +02:00
ynh_app_setting_set $app peer_port $peer_port
#=================================================
# INSTALL TRANSMISSION
#=================================================
2018-03-03 18:39:57 +01:00
ynh_install_app_dependencies transmission-daemon acl
2017-06-13 23:37:51 +02:00
# Fix a stupid issue which happens sometimes ...
# transmission-common is installed (it's a dependency of
# transmission-daemon) but somehow the files it's supposed
# to add ain't there ... and possibly also the transmission user
# is missing.
# Explicitly reinstalling the package fixes the issue :|
if [ ! -d /usr/share/transmission/ ]
then
ynh_package_install transmission-common --reinstall
fi
2017-06-13 23:37:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
# Add a "/" at the end of path_url for next commands
2017-06-18 15:57:00 +02:00
# To avoid a double / in the nginx config file.
2017-06-13 23:37:51 +02:00
[ "$path_url" = "/" ] || path_url=${path_url}/
2017-08-27 22:01:10 +02:00
ynh_add_nginx_config
2017-06-13 23:37:51 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DIRECTORIES
#=================================================
2013-10-29 14:14:27 +01:00
2017-08-27 22:01:10 +02:00
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
2017-06-13 23:37:51 +02:00
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2017-08-27 22:01:10 +02:00
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
2017-06-13 23:37:51 +02:00
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
# Transmission has to be stopped before modifying its config
2017-08-27 22:01:10 +02:00
systemctl stop transmission-daemon
2017-06-13 23:37:51 +02:00
# Create a RPC password
rpcpassword=$(ynh_string_random)
ynh_app_setting_set $app rpcpassword "$rpcpassword"
ynh_replace_string "__RPC_PASSWORD_TO_CHANGE__" "$rpcpassword" ../conf/settings.json
ynh_replace_string "__PATH__" "$path_url" ../conf/settings.json
ynh_replace_string "__PEER_PORT__" "$peer_port" ../conf/settings.json
ynh_replace_string "__PORT__" "$port" ../conf/settings.json
2017-08-27 22:01:10 +02:00
cp ../conf/settings.json /etc/transmission-daemon/settings.json
2017-06-13 23:37:51 +02:00
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
ynh_store_file_checksum /etc/transmission-daemon/settings.json
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
2013-10-29 14:14:27 +01:00
2017-06-18 15:57:00 +02:00
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)
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission" "share/Torrents"
# And share completed directory
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission/completed" "share/Torrents"
2017-06-13 23:37:51 +02:00
# Share also watched directory, to allow to use it easily
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission/watched" "share/Torrent to download"
2017-06-13 23:37:51 +02:00
#=================================================
# PATCH SOURCE TO ADD A DOWNLOAD BUTTON
#=================================================
2017-08-27 22:01:10 +02:00
cp ../sources/extra_files/app/toolbar-downloads.png /usr/share/transmission/web/style/transmission/images/toolbar-downloads.png
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
2017-06-13 23:37:51 +02:00
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
#=================================================
# GENERIC FINALISATION
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
2013-10-29 14:14:27 +01:00
2017-08-27 22:01:10 +02:00
yunohost service add transmission-daemon --log "/var/log/syslog"
2013-12-07 10:10:55 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# START TRANSMISSION
#=================================================
2017-08-27 22:01:10 +02:00
systemctl start transmission-daemon
2017-06-13 23:37:51 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2014-11-11 16:22:53 +01:00
2017-08-27 22:01:10 +02:00
systemctl reload nginx