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
Jean-Francois d86c45d52a Add RPC Password
Generates a RPC password and saves it as a setting. If no RPC password
is present (previous versions), generates one and saves it as a setting
as well.
2016-12-28 16:54:07 +01:00

68 lines
2.3 KiB
Bash

#!/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_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Remove trailing "/" for next commands
path=${path%/}
# Check port availability
sudo yunohost app checkport 9091
if [[ ! $? -eq 0 ]]; then
exit 1
fi
sudo yunohost app checkport 51413
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Open port in firewall
sudo yunohost firewall allow TCP 51413 > /dev/null 2>&1
# Install official debian package
sudo apt-get install transmission-daemon -y -qq
# Make directories and set rights
sudo mkdir -p /home/yunohost.transmission/{progress,completed}
sudo chown -R debian-transmission:www-data /home/yunohost.transmission/
sudo chown -R debian-transmission:debian-transmission /home/yunohost.transmission/progress
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
# Create RPC password
rpcpassword=$(ynh_string_random)
ynh_app_setting_set "$app" rpcpassword "$rpcpassword"
# Configure Transmission and reload
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 reload
# Monitor service
sudo yunohost service add transmission-daemon
# Patch sources to add a download button
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@<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
# 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