mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
236 lines
7.7 KiB
Bash
236 lines
7.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_add_extra_apt_repos__3
|
|
source ynh_systemd_action
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_print_info "Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
admin_email=$(ynh_app_setting_get "$app" admin_email)
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
port=$(ynh_app_setting_get "$app" port)
|
|
db_name=$(ynh_app_setting_get "$app" psql_db)
|
|
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_print_info "Ensuring downward compatibility..."
|
|
|
|
# Fix is_public as a boolean value
|
|
if [ "$is_public" = "Yes" ]; then
|
|
ynh_app_setting_set "$app" is_public 1
|
|
is_public=1
|
|
elif [ "$is_public" = "No" ]; then
|
|
ynh_app_setting_set "$app" is_public 0
|
|
is_public=0
|
|
fi
|
|
|
|
# Close a port
|
|
if yunohost firewall list | grep -q "\- $port$"
|
|
then
|
|
ynh_print_info "Closing port $port"
|
|
ynh_exec_warn_less yunohost firewall disallow TCP $port
|
|
fi
|
|
|
|
# Remove repository
|
|
ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list
|
|
ynh_secure_remove /etc/apt/sources.list.d/yarn.list
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_print_info "Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
# restore it if the upgrade fails
|
|
ynh_clean_check_starting
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STOP PEERTUBE FOR UPGRADE
|
|
#=================================================
|
|
ynh_print_info "Stop $app service..."
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
|
|
|
#===================================================
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
|
#===================================================
|
|
|
|
ynh_psql_execute_as_root "\connect $db_name
|
|
CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
|
|
#=================================================
|
|
# REMOVE APP MAIN DIR
|
|
#=================================================
|
|
|
|
# Create a temporary directory
|
|
tmpdir="$(mktemp -d)"
|
|
# Backup the config file in the temp dir
|
|
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
|
|
# Remove the app directory securely
|
|
ynh_secure_remove "$final_path"
|
|
|
|
# Define app's data directory
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
# Create app folders
|
|
mkdir -p "$datadir"
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_print_info "Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source "$final_path"
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
cp ../conf/production.yaml "$final_path/config/production.yaml"
|
|
ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml"
|
|
ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml"
|
|
ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml"
|
|
ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.yaml"
|
|
ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml"
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml"
|
|
|
|
#Copy the admin saved settings from tmp directory to final path
|
|
cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json"
|
|
|
|
# Remove the tmp directory securely
|
|
ynh_secure_remove "$tmpdir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_print_info "Upgrading nginx web server configuration..."
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_print_info "Upgrading dependencies..."
|
|
|
|
# Install nodejs
|
|
ynh_install_nodejs 8
|
|
|
|
# Install dependencies
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
else
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
|
fi
|
|
|
|
# Install Yarn
|
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
|
|
|
# Create a system user
|
|
ynh_system_user_create "$app"
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
|
|
pushd "$final_path"
|
|
yarn install --production --pure-lockfile
|
|
popd
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/config/production.yaml"
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
ynh_store_file_checksum "$final_path/config/production.yaml"
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_print_info "Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_print_info "Upgrading systemd configuration..."
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions on app files
|
|
chown -R "$app":"$app" "$final_path"
|
|
chown -R "$app":"$app" "$datadir"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_print_info "Upgrading SSOwat configuration..."
|
|
|
|
# Make app public if necessary
|
|
if [ "$is_public" -eq 1 ]
|
|
then
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_print_info "Reloading nginx web server..."
|
|
|
|
systemctl reload nginx
|
|
|
|
#=================================================
|
|
# START SERVICE
|
|
#=================================================
|
|
ynh_print_info "Start $app service..."
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on localhost"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|