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

193 lines
7.5 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
#=================================================
2019-05-01 13:24:56 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-06-13 23:37:51 +02:00
2017-08-27 22:01:10 +02:00
# Register (book) web path
2019-05-01 13:24:56 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-05-01 13:24:56 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2013-10-29 14:14:27 +01:00
2019-05-01 13:24:56 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
2013-10-29 14:14:27 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN PORTS
#=================================================
2019-05-01 13:24:56 +02:00
ynh_script_progression --message="Configuring firewall..." --weight=16
2013-10-29 14:51:24 +01:00
2017-08-27 22:01:10 +02:00
# Find a free port
2019-05-01 13:24:56 +02:00
port=$(ynh_find_port --port=9091)
2017-08-27 22:01:10 +02:00
# Open this port
2019-05-01 13:24:56 +02:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_app_setting_set --app=$app --key=port --value=$port
2013-10-29 14:14:27 +01:00
2017-08-27 22:01:10 +02:00
# Find a free port
2019-05-01 13:24:56 +02:00
peer_port=$(ynh_find_port --port=51413)
2017-08-27 22:01:10 +02:00
# Open this port
2019-05-01 13:24:56 +02:00
ynh_exec_warn_less yunohost firewall allow Both $peer_port
ynh_app_setting_set --app=$app --key=peer_port --value=$peer_port
2017-06-13 23:37:51 +02:00
#=================================================
# INSTALL TRANSMISSION
#=================================================
2020-12-14 11:36:02 +01:00
ynh_script_progression --message="Installing Transmission..." --weight=16
2017-06-13 23:37:51 +02:00
2019-05-01 13:24:56 +02:00
ynh_install_app_dependencies $pkg_dependencies
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 packages fixes the issue :|
if [ ! -d /usr/share/transmission/ ]
then
ynh_package_install $pkg_dependencies --reinstall
fi
2017-06-13 23:37:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-14 11:36:02 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2017-06-13 23:37:51 +02:00
2020-12-14 11:36:02 +01:00
# Create a dedicated NGINX config
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
#=================================================
2020-12-14 11:36:02 +01:00
ynh_script_progression --message="Configuring Transmission..." --weight=2
2017-06-13 23:37:51 +02:00
# Transmission has to be stopped before modifying its config
2019-05-01 13:24:56 +02:00
ynh_systemd_action --service_name=transmission-daemon --action=stop
2017-06-13 23:37:51 +02:00
# Create a RPC password
rpcpassword=$(ynh_string_random)
2019-05-01 13:24:56 +02:00
ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword"
2017-06-13 23:37:51 +02:00
2019-05-01 13:24:56 +02:00
ynh_replace_string --match_string="__RPC_PASSWORD_TO_CHANGE__" --replace_string="$rpcpassword" --target_file=../conf/settings.json
2019-05-01 19:39:41 +02:00
if [ "$path_url" != "/" ]
then
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url/" --target_file=../conf/settings.json
else
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/settings.json
fi
2019-05-01 13:24:56 +02:00
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
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
2020-03-03 19:06:26 +01:00
if [ -e /proc/sys/net/core/rmem_max ]
then
cp ../conf/90-transmission.conf /etc/sysctl.d/90-transmission.conf
2019-05-09 12:25:08 +02:00
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
2019-05-09 11:07:57 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
2019-05-01 13:24:56 +02:00
ynh_store_file_checksum --file=/etc/transmission-daemon/settings.json
2020-03-03 19:06:26 +01:00
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_store_file_checksum --file=/etc/sysctl.d/90-transmission.conf
fi
2017-06-13 23:37:51 +02:00
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
2019-05-01 13:24:56 +02:00
ynh_script_progression --message="Adding multimedia directories..." --weight=4
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)
2019-05-01 13:24:56 +02:00
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
# And share completed directory
2019-05-01 13:24:56 +02:00
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
2017-06-13 23:37:51 +02:00
# Share also watched directory, to allow to use it easily
2019-05-01 13:24:56 +02:00
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="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
2019-05-01 13:24:56 +02:00
#=================================================
# START TRANSMISSION
#=================================================
2020-12-14 11:36:02 +01:00
ynh_script_progression --message="Starting Transmission..."
2019-05-01 13:24:56 +02:00
ynh_systemd_action --service_name=transmission-daemon --action=start
2017-06-13 23:37:51 +02:00
#=================================================
# GENERIC FINALISATION
#=================================================
2019-05-01 13:24:56 +02:00
# ADVERTISE SERVICE IN ADMIN PANEL
2017-06-13 23:37:51 +02:00
#=================================================
2013-10-29 14:14:27 +01:00
2020-12-14 11:36:02 +01:00
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog"
2013-12-07 10:10:55 +01:00
2017-06-13 23:37:51 +02:00
#=================================================
2019-05-01 13:24:56 +02:00
# RELOAD NGINX
2017-06-13 23:37:51 +02:00
#=================================================
2020-12-14 11:36:02 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-06-13 23:37:51 +02:00
2019-05-01 13:24:56 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2017-06-13 23:37:51 +02:00
#=================================================
2019-05-01 13:24:56 +02:00
# END OF SCRIPT
2017-06-13 23:37:51 +02:00
#=================================================
2014-11-11 16:22:53 +01:00
2019-05-01 13:24:56 +02:00
ynh_script_progression --message="Installation of $app completed" --last