2016-05-17 22:13:59 +02:00
|
|
|
#!/bin/bash
|
2016-05-14 09:56:38 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=2
|
2016-05-14 09:56:38 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
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)
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# CHECK VERSION
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=4
|
|
|
|
|
|
|
|
if [ -z "$port" ]; then
|
2017-06-15 00:33:49 +02:00
|
|
|
port=9091
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
fi
|
2019-05-01 13:24:56 +02:00
|
|
|
if [ -z "$peer_port" ]; then
|
2017-06-15 00:33:49 +02:00
|
|
|
peer_port=51413
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=peer_port --value=$peer_port
|
2017-06-13 23:37:51 +02:00
|
|
|
fi
|
|
|
|
|
2018-03-03 18:53:33 +01:00
|
|
|
# Add peer_port also on UDP.
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall allow UDP $peer_port
|
2018-03-03 18:53:33 +01:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
|
2016-12-28 16:54:07 +01:00
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
# Inform the backup/restore process that it should not save the data directory
|
2019-05-01 13:24:56 +02:00
|
|
|
# Use only for the previous backup script that doesn't set 'is_big'
|
2017-08-27 22:01:10 +02:00
|
|
|
ynh_app_setting_set $app backup_core_only 1
|
2019-05-01 13:24:56 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
ynh_clean_setup () {
|
2019-05-01 13:24:56 +02:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-06-13 23:37:51 +02:00
|
|
|
}
|
2019-05-01 13:24:56 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
# Normalize the URL path syntax
|
2019-05-01 13:24:56 +02:00
|
|
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
2013-10-29 14:51:24 +01:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
# Create a dedicated nginx config
|
2017-08-27 22:01:10 +02:00
|
|
|
ynh_add_nginx_config
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2018-03-03 18:39:57 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=7
|
2018-03-03 18:39:57 +01:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2018-03-03 18:39:57 +01:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# CREATE DIRECTORIES
|
|
|
|
#=================================================
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
chown -R debian-transmission:www-data /home/yunohost.transmission/
|
|
|
|
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
|
2017-11-22 19:02:51 +01:00
|
|
|
chmod -R 764 /home/yunohost.transmission
|
2017-08-27 22:01:10 +02:00
|
|
|
chmod -R 777 /home/yunohost.transmission/watched
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE TRANSMISSION
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Reconfiguring transmission..." --weight=2
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
# Transmission has to be stopped before modifying its config
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_systemd_action --service_name=transmission-daemon --action=stop
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
# Verify the checksum and backup the file if it's different
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_backup_if_checksum_is_different --file=/etc/transmission-daemon/settings.json
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
# Create a RPC password
|
|
|
|
rpcpassword=$(ynh_string_random)
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=rpcpassword --value="$rpcpassword"
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_replace_string --match_string="__RPC_PASSWORD_TO_CHANGE__" --replace_string="$rpcpassword" --target_file=../conf/settings.json
|
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/settings.json
|
|
|
|
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
|
2017-08-27 22:01:10 +02:00
|
|
|
cp ../conf/settings.json /etc/transmission-daemon/settings.json
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
# Recalculate and store the config file checksum into the app settings
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_store_file_checksum --file=/etc/transmission-daemon/settings.json
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# YUNOHOST MULTIMEDIA INTEGRATION
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Adding multimedia directories..." --weight=3
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2017-06-18 15:57:00 +02:00
|
|
|
ynh_multimedia_build_main_dir
|
2017-04-01 20:41:34 +02:00
|
|
|
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
|
2017-04-01 20:41:34 +02:00
|
|
|
# And share completed directory
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
|
2017-06-13 23:37:51 +02:00
|
|
|
# Share also watched directory, to allow to use it easily
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PATCH SOURCE TO ADD A DOWNLOAD BUTTON
|
|
|
|
#=================================================
|
2017-04-01 20:41:34 +02:00
|
|
|
|
2017-08-27 22:01:10 +02:00
|
|
|
cp ../sources/extra_files/app/toolbar-downloads.png /usr/share/transmission/web/style/transmission/images/toolbar-downloads.png
|
2017-06-13 23:37:51 +02:00
|
|
|
if ! grep --quiet "Inserted by Yunohost install script" /usr/share/transmission/web/style/transmission/common.css
|
|
|
|
then
|
2017-08-27 22:01:10 +02:00
|
|
|
cat ../sources/extra_files/app/ynh_common.css >> /usr/share/transmission/web/style/transmission/common.css
|
2016-12-28 16:54:07 +01:00
|
|
|
fi
|
2017-06-13 23:37:51 +02:00
|
|
|
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
|
2016-12-28 16:54:07 +01:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# START TRANSMISSION
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Starting transmission..." --weight=2
|
2013-10-29 14:26:46 +01:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_systemd_action --service_name=transmission-daemon --action=start
|
2014-11-11 17:00:05 +01:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# END OF SCRIPT
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2014-11-11 16:55:15 +01:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|