2018-03-26 05:50:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2019-04-03 02:43:43 +02:00
|
|
|
source ynh_add_secure_repos__3
|
2019-04-03 03:21:30 +02:00
|
|
|
source ynh_systemd_action
|
2019-04-03 03:27:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Loading installation settings..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-03-26 05:50:46 +02:00
|
|
|
path_url="/"
|
2018-03-29 23:53:32 +02:00
|
|
|
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)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Ensuring downward compatibility..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 1
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 0
|
2018-03-26 05:50:46 +02:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
# 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
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Remove repository
|
|
|
|
ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list
|
|
|
|
ynh_secure_remove /etc/apt/sources.list.d/yarn.list
|
|
|
|
|
2018-03-29 23:38:29 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Backing up the app before upgrading (may take a while)..."
|
2018-03-29 23:38:29 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
2019-04-03 03:21:30 +02:00
|
|
|
ynh_clean_check_starting
|
2018-03-29 23:38:29 +02:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP PEERTUBE FOR UPGRADE
|
|
|
|
#=================================================
|
|
|
|
|
2019-04-03 03:21:30 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
2018-05-31 00:33:14 +02:00
|
|
|
|
2018-07-29 17:18:55 +02:00
|
|
|
#===================================================
|
|
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
|
|
|
#===================================================
|
|
|
|
|
2018-08-03 11:45:44 +02:00
|
|
|
ynh_psql_execute_as_root "\connect $db_name
|
|
|
|
CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
2018-07-29 17:18:55 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# REMOVE APP MAIN DIR
|
|
|
|
#=================================================
|
2018-06-14 16:11:29 +02:00
|
|
|
|
2018-04-11 17:51:42 +02:00
|
|
|
# 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"
|
2018-03-26 05:50:46 +02:00
|
|
|
# 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"
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2018-05-21 12:10:41 +02:00
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2018-05-21 12:10:41 +02:00
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Upgrading source files..."
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
2019-04-03 04:44:26 +02:00
|
|
|
|
2018-03-29 23:53:32 +02:00
|
|
|
cp ../conf/production.yaml "$final_path/config/production.yaml"
|
2018-04-11 17:51:42 +02:00
|
|
|
|
|
|
|
#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"
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Upgrading nginx web server configuration..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Upgrading dependencies..."
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install nodejs
|
2019-04-03 02:30:56 +02:00
|
|
|
ynh_install_nodejs 8
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
# Install ffmpeg from backports for Debian Jessie and from main for others
|
2019-04-03 02:30:56 +02:00
|
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
2019-04-03 02:43:43 +02:00
|
|
|
ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg"
|
|
|
|
else
|
|
|
|
ynh_add_app_dependencies --package="ffmpeg"
|
2019-04-03 02:30:56 +02:00
|
|
|
fi
|
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# 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"
|
2019-04-03 02:30:56 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create "$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2019-04-03 04:44:26 +02:00
|
|
|
# BUILD YARN DEPENDENCIES
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
pushd "$final_path"
|
|
|
|
yarn install --production --pure-lockfile
|
|
|
|
popd
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
ynh_backup_if_checksum_is_different "$final_path/config/production.yaml"
|
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
2018-03-26 05:50:46 +02:00
|
|
|
ynh_store_file_checksum "$final_path/config/production.yaml"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Upgrading logrotate configuration..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Upgrading systemd configuration..."
|
|
|
|
|
2018-10-01 00:20:48 +02:00
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
2018-03-26 05:50:46 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
# Set permissions on app files
|
|
|
|
chown -R "$app":"$app" "$final_path"
|
|
|
|
chown -R "$app":"$app" "$datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Upgrading SSOwat configuration..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
# Make app public if necessary
|
2018-05-21 11:50:03 +02:00
|
|
|
if [ "$is_public" -eq 1 ]
|
2018-03-26 05:50:46 +02:00
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2018-03-29 23:53:32 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2018-03-26 05:50:46 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-04-03 01:30:38 +02:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
systemctl reload nginx
|
2019-04-03 02:30:56 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Start service..."
|
|
|
|
|
2019-04-03 03:21:30 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
2019-04-03 01:30:38 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|