mirror of
https://github.com/YunoHost-Apps/transmission_ynh.git
synced 2024-09-04 01:46:12 +02:00
172493ec86
* Fix linter warnings * Update install
200 lines
7.9 KiB
Bash
200 lines
7.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=2
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
peer_port=$(ynh_app_setting_get --app=$app --key=peer_port)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=4
|
|
|
|
if [ -z "$port" ]; then
|
|
port=9091
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
fi
|
|
if [ -z "$peer_port" ]; then
|
|
peer_port=51413
|
|
ynh_app_setting_set --app=$app --key=peer_port --value=$peer_port
|
|
fi
|
|
|
|
# Add peer_port also on UDP.
|
|
ynh_exec_warn_less yunohost firewall allow UDP $peer_port
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
|
|
|
|
# Inform the backup/restore process that it should not save the data directory
|
|
# Use only for the previous backup script that doesn't set 'is_big'
|
|
ynh_app_setting_set $app backup_core_only 1
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
|
|
# Remove the option backup_core_only after the backup.
|
|
ynh_app_setting_delete $app backup_core_only
|
|
|
|
ynh_clean_setup () {
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=7
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# CREATE DIRECTORIES
|
|
#=================================================
|
|
|
|
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
|
|
|
|
#=================================================
|
|
# SECURING FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
chown -R debian-transmission:www-data /home/yunohost.transmission/
|
|
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
|
|
chmod -R 764 /home/yunohost.transmission
|
|
chmod -R 777 /home/yunohost.transmission/watched
|
|
|
|
#=================================================
|
|
# CONFIGURE TRANSMISSION
|
|
#=================================================
|
|
ynh_script_progression --message="Reconfiguring Transmission..." --weight=2
|
|
|
|
# Transmission has to be stopped before modifying its config
|
|
ynh_systemd_action --service_name=transmission-daemon --action=stop
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
ynh_backup_if_checksum_is_different --file=/etc/transmission-daemon/settings.json
|
|
|
|
# Create a RPC password
|
|
rpcpassword=$(ynh_string_random)
|
|
ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword"
|
|
|
|
ynh_replace_string --match_string="__RPC_PASSWORD_TO_CHANGE__" --replace_string="$rpcpassword" --target_file=../conf/settings.json
|
|
if [ "$path_url" != "/" ]
|
|
then
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url/" --target_file=../conf/settings.json
|
|
else
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/settings.json
|
|
fi
|
|
ynh_replace_string --match_string="__PEER_PORT__" --replace_string="$peer_port" --target_file=../conf/settings.json
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/settings.json
|
|
cp ../conf/settings.json /etc/transmission-daemon/settings.json
|
|
|
|
if [ -e /proc/sys/net/core/rmem_max ]
|
|
then
|
|
# Verify the checksum and backup the file if it's different
|
|
ynh_backup_if_checksum_is_different --file=/etc/sysctl.d/90-transmission.conf
|
|
|
|
cp ../conf/90-transmission.conf /etc/sysctl.d/90-transmission.conf
|
|
sysctl --load=/etc/sysctl.d/90-transmission.conf
|
|
fi
|
|
|
|
#=================================================
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
|
#=================================================
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum --file=/etc/transmission-daemon/settings.json
|
|
if [ -e /proc/sys/net/core/rmem_max ]
|
|
then
|
|
ynh_store_file_checksum --file=/etc/sysctl.d/90-transmission.conf
|
|
fi
|
|
|
|
#=================================================
|
|
# YUNOHOST MULTIMEDIA INTEGRATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding multimedia directories..." --weight=3
|
|
|
|
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="/home/yunohost.transmission" --dest_dir="share/Torrents"
|
|
# And share completed directory
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
|
|
# Share also watched directory, to allow to use it easily
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/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
|
|
if ! grep --quiet "Inserted by Yunohost install script" /usr/share/transmission/web/style/transmission/common.css
|
|
then
|
|
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
|
|
fi
|
|
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
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
|
|
|
|
#=================================================
|
|
# START TRANSMISSION
|
|
#=================================================
|
|
ynh_script_progression --message="Starting Transmission..." --weight=2
|
|
|
|
ynh_systemd_action --service_name=transmission-daemon --action=start
|
|
|
|
#=================================================
|
|
# GENERIC FINALISATION
|
|
#=================================================
|
|
# 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="Upgrade of $app completed" --last
|