2016-05-17 22:13:59 +02:00
|
|
|
#!/bin/bash
|
2016-05-14 09:56:38 +02:00
|
|
|
|
2016-05-17 22:13:59 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
2016-05-14 09:56:38 +02:00
|
|
|
|
|
|
|
# Get app instance name
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2016-12-28 16:54:07 +01:00
|
|
|
# Source app helpers
|
|
|
|
. /usr/share/yunohost/helpers
|
|
|
|
|
2013-10-29 14:26:46 +01:00
|
|
|
# Retrieve arguments
|
2016-12-28 16:54:07 +01:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
|
|
rpcpassword=$(ynh_app_setting_get "$app" rpcpassword)
|
2016-12-28 17:23:48 +01:00
|
|
|
watchdir=$(ynh_app_setting_get "$app" watchdir)
|
2013-10-29 14:26:46 +01:00
|
|
|
|
|
|
|
# Remove trailing "/" for next commands
|
|
|
|
path=${path%/}
|
|
|
|
|
2013-10-29 14:51:24 +01:00
|
|
|
# Open port in firewall
|
|
|
|
sudo yunohost firewall allow TCP 51413 > /dev/null 2>&1
|
|
|
|
|
2013-10-29 14:26:46 +01:00
|
|
|
# Upgrade official debian package
|
2014-11-11 16:39:27 +01:00
|
|
|
sudo apt-get install transmission-daemon -y -qq
|
2013-10-29 14:26:46 +01:00
|
|
|
|
|
|
|
# Make directories and set rights
|
2016-12-28 17:23:48 +01:00
|
|
|
sudo mkdir -p /home/yunohost.transmission/{progress,completed,watched}
|
2014-12-04 11:48:27 +01:00
|
|
|
sudo chown -R debian-transmission:www-data /home/yunohost.transmission/
|
2016-12-28 17:23:48 +01:00
|
|
|
sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmission/progress /home/yunohost.transmission/watched
|
2014-12-04 11:44:02 +01:00
|
|
|
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
|
2016-12-28 17:23:48 +01:00
|
|
|
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
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2017-04-01 20:41:34 +02:00
|
|
|
# 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"
|
|
|
|
|
2016-12-28 16:54:07 +01:00
|
|
|
# Create RPC password if none exists
|
|
|
|
if [ -z "$rpcpassword" ]; then
|
|
|
|
rpcpassword=$(ynh_string_random)
|
|
|
|
ynh_app_setting_set "$app" rpcpassword "$rpcpassword"
|
|
|
|
fi
|
|
|
|
|
2013-10-29 14:26:46 +01:00
|
|
|
# Configure Transmission and reload
|
2016-12-28 17:23:48 +01:00
|
|
|
sudo service transmission-daemon stop
|
2016-12-28 16:54:07 +01:00
|
|
|
sed -i "s@RPCPASSWORDTOCHANGE@$rpcpassword@g" ../conf/settings.json
|
2013-10-29 14:51:24 +01:00
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/settings.json
|
2013-10-29 14:26:46 +01:00
|
|
|
sudo cp ../conf/settings.json /etc/transmission-daemon/settings.json
|
2016-12-28 17:23:48 +01:00
|
|
|
sudo service transmission-daemon start
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2014-11-11 16:25:08 +01:00
|
|
|
# Patch sources to add a download button
|
2014-11-11 17:00:05 +01:00
|
|
|
if ! grep 'toolbar-downloads' /usr/share/transmission/web/index.html --quiet; then
|
|
|
|
|
2014-11-11 16:55:15 +01:00
|
|
|
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'
|
2014-12-04 11:42:49 +01:00
|
|
|
sudo sed -i "s@<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>@g" /usr/share/transmission/web/index.html
|
2014-11-11 16:55:15 +01:00
|
|
|
fi
|
|
|
|
|
2013-10-29 14:26:46 +01:00
|
|
|
# Configure Nginx and reload
|
2013-10-29 14:51:24 +01:00
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
2016-05-14 09:56:38 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2013-10-29 14:26:46 +01:00
|
|
|
sudo service nginx reload
|