#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) port=$(ynh_app_setting_get $app port) peer_port=$(ynh_app_setting_get $app peer_port) #================================================= # FIX OLD THINGS #================================================= if [ -z $port ]; then port=9091 ynh_app_setting_set $app port $port fi if [ -z $peer_port ]; then peer_port=51413 ynh_app_setting_set $app peer_port $peer_port fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= # Inform the backup/restore process that it should not save the data directory ynh_app_setting_set $app backup_core_only 1 ynh_backup_before_upgrade # Backup the current version of the app ynh_clean_setup () { ynh_restore_upgradebackup # restore it if the upgrade fails } ynh_abort_if_errors # Exit if an error occurs during the execution of the script #================================================= # CHECK THE PATH #================================================= # Normalize the URL path syntax path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= # NGINX CONFIGURATION #================================================= # Add a "/" at the end of path_url for next commands # To avoid a double / in the nginx config file. [ "$path_url" = "/" ] || path_url=${path_url}/ ynh_add_nginx_config #================================================= # 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 #================================================= # Transmission has to be stopped before modifying its config systemctl stop transmission-daemon # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different /etc/transmission-daemon/settings.json # Create a RPC password rpcpassword=$(ynh_string_random) ynh_app_setting_set $app rpcpassword "$rpcpassword" ynh_replace_string "__RPC_PASSWORD_TO_CHANGE__" "$rpcpassword" ../conf/settings.json ynh_replace_string "__PATH__" "$path_url" ../conf/settings.json ynh_replace_string "__PEER_PORT__" "$peer_port" ../conf/settings.json ynh_replace_string "__PORT__" "$port" ../conf/settings.json cp ../conf/settings.json /etc/transmission-daemon/settings.json #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum /etc/transmission-daemon/settings.json #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= 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 "/home/yunohost.transmission" "share/Torrents" # And share completed directory ynh_multimedia_addfolder "/home/yunohost.transmission/completed" "share/Torrents" # Share also watched directory, to allow to use it easily ynh_multimedia_addfolder "/home/yunohost.transmission/watched" "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 "
$" "
" /usr/share/transmission/web/index.html #================================================= # START TRANSMISSION #================================================= systemctl start transmission-daemon #================================================= # RELOAD NGINX #================================================= systemctl reload nginx #================================================= # REMOVE BACKUP_CORE_ONLY #================================================= ynh_app_setting_delete $app backup_core_only