#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh 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 #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH app=$YNH_APP_INSTANCE_NAME rpcpassword=$(ynh_string_random) #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= 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 A PORT #================================================= ynh_script_progression --message="Finding an available port..." --weight=16 # Find an available port port=$(ynh_find_port --port=9091) ynh_app_setting_set --app=$app --key=port --value=$port peer_port=$(ynh_find_port --port=51413) 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 DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=16 ynh_install_app_dependencies $pkg_dependencies # 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_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 #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # ADD A CONFIGURATION #================================================= 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 if [ "$path_url" != "/" ] then path_less="$path_url/" else path_less="$path_url" fi 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 ynh_add_config --template="../conf/90-transmission.conf" --destination="/etc/sysctl.d/90-transmission.conf" chmod 400 "/etc/sysctl.d/90-transmission.conf" chown debian-transmission:debian-transmission "/etc/sysctl.d/90-transmission.conf" sysctl --load=/etc/sysctl.d/90-transmission.conf fi #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= 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="$datadir" --dest_dir="share/Torrents" # And share completed directory 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="$datadir/watched" --dest_dir="share/Torrent to download" #================================================= # PATCH SOURCE TO ADD A DOWNLOAD BUTTON #================================================= 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 ynh_replace_string "
" "" /usr/share/transmission/web/index.html #================================================= # GENERIC FINALISATION #================================================= # 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 #================================================= ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last