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

120 lines
4.6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
rpcpassword=$(ynh_string_random)
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DATA DIRECTORY PERMISSIONS
#=================================================
ynh_script_progression --message="Set data directory permissions..."
chmod -R 775 $data_dir
chmod -R 775 $data_dir/watched
chown -R debian-transmission:www-data "$data_dir"
chown -R debian-transmission: "$data_dir"/{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" != "/" ]
then
path_less="$path/"
else
path_less="$path"
fi
ynh_add_config --template="../conf/settings.json" --destination="$SETTINGS_FILE"
chmod 400 "$SETTINGS_FILE"
chown debian-transmission:debian-transmission "$SETTINGS_FILE"
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="$data_dir" --dest_dir="share/Torrents"
# And share completed directory
ynh_multimedia_addfolder --source_dir="$data_dir/completed" --dest_dir="share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder --source_dir="$data_dir/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 "<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
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port_peer"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=transmission-daemon --action="start" --log_path="systemd"
#=================================================
# RETRIEVE HASHED PASSWORD
#=================================================
ynh_script_progression --message="Saving the encrypted password..."
_wait_and_save_rcp_password_hash
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last