#!/bin/bash # Exit on command errors and treat unset variables as an error set -eu # Get app instance name app=$YNH_APP_INSTANCE_NAME # Source app helpers . /usr/share/yunohost/helpers # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) rpcpassword=$(ynh_app_setting_get "$app" rpcpassword) watchdir=$(ynh_app_setting_get "$app" watchdir) # Remove trailing "/" for next commands path=${path%/} # Open port in firewall sudo yunohost firewall allow TCP 51413 > /dev/null 2>&1 # Upgrade official debian package sudo apt-get install transmission-daemon -y -qq # Make directories and set rights sudo mkdir -p /home/yunohost.transmission/{progress,completed,watched} sudo chown -R debian-transmission:www-data /home/yunohost.transmission/ sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmission/progress /home/yunohost.transmission/watched sudo find /home/yunohost.transmission/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done sudo find /home/yunohost.transmission/ -type d | while read LINE; do sudo chmod 750 "$LINE" ; done sudo find /home/yunohost.transmission/watched -type d | while read LINE; do sudo chmod 770 "$LINE" ; done # Add watchdir in settings if it does not exist yet (previous versions) if [ -z "$watchdir" ]; then ynh_app_setting_set "$app" watchdir "/home/yunohost.transmission/watched" fi # YunoHost multimedia wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip unzip -qq master.zip sudo ./yunohost.multimedia-master/script/ynh_media_build.sh # Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move) sudo ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="/home/yunohost.transmission" --dest="share/Torrents" # And share completed directory sudo ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="/home/yunohost.transmission/completed" --dest="share/Torrents" # Create RPC password if none exists if [ -z "$rpcpassword" ]; then rpcpassword=$(ynh_string_random) ynh_app_setting_set "$app" rpcpassword "$rpcpassword" fi # Configure Transmission and reload sudo service transmission-daemon stop sed -i "s@RPCPASSWORDTOCHANGE@$rpcpassword@g" ../conf/settings.json sed -i "s@PATHTOCHANGE@$path@g" ../conf/settings.json sudo cp ../conf/settings.json /etc/transmission-daemon/settings.json sudo service transmission-daemon start # Patch sources to add a download button if ! grep 'toolbar-downloads' /usr/share/transmission/web/index.html --quiet; then sudo cp ../sources/toolbar-downloads.png /usr/share/transmission/web/style/transmission/images/toolbar-downloads.png sudo bash -c 'cat ../sources/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css' sudo sed -i "s@
@
@g" /usr/share/transmission/web/index.html fi # Configure Nginx and reload sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf sudo service nginx reload