mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
190 lines
7.3 KiB
Bash
190 lines
7.3 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key="mail")
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
ynh_app_setting_delete --app=$app --key=admin_pass
|
|
ynh_app_setting_delete --app=$app --key=admin_mail
|
|
|
|
# If redis_db doesn't exist, create it
|
|
if [ -z "${redis_db:-}" ]; then
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
fi
|
|
|
|
if [ -z "${secrets_peertube:-}" ]; then
|
|
ynh_print_info --message="Generating and storing PeerTube secrets..."
|
|
secrets_peertube=$(ynh_string_random --length=24)
|
|
ynh_app_setting_set --app=$app --key=secrets_peertube --value=$secrets_peertube
|
|
fi
|
|
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
|
ynh_exec_warn_less ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
|
ynh_exec_warn_less ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
# Remove repository
|
|
ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list"
|
|
|
|
# Remove hook
|
|
if [[ -e "/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" ]]
|
|
then
|
|
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
|
|
yunohost tools regen-conf nginx
|
|
fi
|
|
|
|
# Remove old log file
|
|
ynh_secure_remove --file="$data_dir/logs"
|
|
|
|
# directory on filesystem must be renamed from videos/ to web-videos/ to represent the value of storage.web_videos
|
|
if [ -d "$data_dir/storage/videos" ]; then
|
|
mv $data_dir/storage/videos $data_dir/storage/web-videos
|
|
fi
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
|
|
|
# In the past, the db was called peertube_peertube >_>
|
|
if [[ "${db_name:-}" == "peertube_peertube" ]]
|
|
then
|
|
ynh_print_info --message="Renaming database..."
|
|
ynh_psql_execute_as_root --sql="ALTER DATABASE $db_name RENAME TO $app;"
|
|
db_name="$app"
|
|
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
|
|
fi
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --full_replace=1 --dest_dir="$install_dir" \
|
|
--keep="config/production.yaml config/local-production.json config/local.yaml"
|
|
fi
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
chown -R $app:www-data "$data_dir"
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
mkdir -p "/var/log/$app"
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
yunohost service add $app --description="Federated video streaming platform" --log="/var/log/$app/$app.log" --needs_exposed_ports $port_rtmp
|
|
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
|
|
|
pushd "$install_dir"
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn config set network-timeout 300000
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean
|
|
popd
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating configuration file..."
|
|
|
|
ynh_add_config --template="production.yaml" --destination="$install_dir/config/production.yaml"
|
|
chmod 400 "$install_dir/config/production.yaml"
|
|
chown $app:$app "$install_dir/config/production.yaml"
|
|
|
|
chmod 600 "$install_dir/config/local-production.json"
|
|
chown $app:$app "$install_dir/config/local-production.json"
|
|
|
|
#=================================================
|
|
# INSTALL LDAP PLUGIN
|
|
#=================================================
|
|
ynh_script_progression --message="Installing $app plugin..."
|
|
|
|
pushd "$install_dir"
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-auth-ldap
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-livechat
|
|
popd
|
|
|
|
#=================================================
|
|
# PEERTUBE UPGRADE MIGRATION SCRIPT
|
|
#=================================================
|
|
|
|
if ynh_compare_current_package_version --comparison lt --version 4.0.0~ynh1; then
|
|
ynh_script_progression --message="Running Peertube 4.0.0 migration script..."
|
|
pushd "$install_dir"
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_node dist/scripts/migrations/peertube-4.0.js
|
|
popd
|
|
fi
|
|
|
|
if ynh_compare_current_package_version --comparison lt --version 4.2.0~ynh1; then
|
|
ynh_script_progression --message="Running Peertube 4.2.0 migration script..."
|
|
pushd "$install_dir"
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_node dist/scripts/migrations/peertube-4.2.js
|
|
popd
|
|
fi
|
|
|
|
if ynh_compare_current_package_version --comparison lt --version 5.0.0~ynh1; then
|
|
ynh_script_progression --message="Running Peertube 5.0.0 migration script..."
|
|
pushd "$install_dir"
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_node dist/scripts/migrations/peertube-5.0.js
|
|
popd
|
|
fi
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on 127.0.0.1"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|