2018-03-26 05:50:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2019-04-03 03:27:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
|
2022-06-10 01:21:56 +02:00
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key="mail")
|
2019-06-03 22:37:54 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2021-02-26 04:16:57 +01:00
|
|
|
ynh_app_setting_delete --app=$app --key=admin_pass
|
2022-06-10 01:21:56 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=admin_mail
|
2021-02-26 04:16:57 +01:00
|
|
|
|
2021-12-24 09:22:23 +01:00
|
|
|
# If redis_db doesn't exist, create it
|
2023-12-27 18:10:54 +01:00
|
|
|
if [ -z "${redis_db:-}" ]; then
|
2021-12-24 09:22:23 +01:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
fi
|
|
|
|
|
2023-12-27 18:10:54 +01:00
|
|
|
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
|
2019-04-03 04:44:26 +02:00
|
|
|
fi
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
2023-12-27 21:35:53 +01:00
|
|
|
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
|
2019-06-03 22:37:54 +02:00
|
|
|
|
2019-04-03 02:43:43 +02:00
|
|
|
# Remove repository
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list"
|
2019-04-03 02:43:43 +02:00
|
|
|
|
2022-01-30 21:34:03 +01:00
|
|
|
# Remove hook
|
2023-12-27 18:10:54 +01:00
|
|
|
if [[ -e "/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" ]]
|
2021-01-13 20:59:06 +01:00
|
|
|
then
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
|
|
|
|
yunohost tools regen-conf nginx
|
2021-01-13 20:59:06 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-08 01:41:44 +01:00
|
|
|
# Remove old log file
|
2023-03-21 23:33:23 +01:00
|
|
|
ynh_secure_remove --file="$data_dir/logs"
|
2023-08-04 02:20:17 +02:00
|
|
|
|
2021-04-10 19:38:56 +02:00
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
# STOP SYSTEMD SERVICE
|
2021-04-10 19:38:56 +02:00
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped"
|
2022-02-08 01:41:44 +01:00
|
|
|
|
2023-12-27 21:35:18 +01:00
|
|
|
# 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
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2019-04-03 06:24:02 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2019-04-03 06:24:02 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2021-02-26 03:34:51 +01:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-03-21 23:12:02 +01:00
|
|
|
ynh_setup_source --full_replace=1 --dest_dir="$install_dir" \
|
2022-11-18 13:54:59 +01:00
|
|
|
--keep="config/production.yaml config/local-production.json config/local.yaml"
|
2019-06-03 22:37:54 +02:00
|
|
|
fi
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-04-10 19:38:56 +02:00
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2022-07-31 19:15:34 +02:00
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations..."
|
2020-06-01 03:40:44 +02:00
|
|
|
|
2022-06-10 01:21:56 +02:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-02-06 02:01:51 +01:00
|
|
|
|
2023-09-13 18:43:40 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2023-09-13 18:43:40 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2023-09-13 18:43:40 +02:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2022-12-15 11:11:11 +01:00
|
|
|
|
2023-12-27 17:23:14 +01:00
|
|
|
yunohost service add $app --description="Federated video streaming platform" --log="/var/log/$app/$app.log" --needs_exposed_ports $port_rtmp
|
2022-12-15 11:11:11 +01:00
|
|
|
|
2022-07-31 19:15:34 +02:00
|
|
|
#=================================================
|
|
|
|
# BUILD YARN DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
pushd "$install_dir"
|
2022-07-31 19:15:34 +02:00
|
|
|
ynh_use_nodejs
|
2023-12-27 18:56:49 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn config set network-timeout 300000
|
2022-07-31 19:15:34 +02:00
|
|
|
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
|
|
|
|
|
2019-06-06 23:16:31 +02:00
|
|
|
#=================================================
|
2021-04-10 19:38:56 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
2019-06-06 23:16:31 +02:00
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Updating configuration file..."
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2023-12-27 17:34:15 +01:00
|
|
|
ynh_add_config --template="production.yaml" --destination="$install_dir/config/production.yaml"
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod 400 "$install_dir/config/production.yaml"
|
|
|
|
chown $app:$app "$install_dir/config/production.yaml"
|
2020-06-01 03:40:44 +02:00
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
chmod 600 "$install_dir/config/local-production.json"
|
|
|
|
chown $app:$app "$install_dir/config/local-production.json"
|
2022-01-10 20:47:14 +01:00
|
|
|
|
2021-03-30 22:58:26 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL LDAP PLUGIN
|
|
|
|
#=================================================
|
2023-09-13 18:43:40 +02:00
|
|
|
ynh_script_progression --message="Installing $app plugin..."
|
2022-01-30 21:34:03 +01:00
|
|
|
|
2023-03-21 23:12:02 +01:00
|
|
|
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
|
2023-12-27 18:10:54 +01:00
|
|
|
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
|
2021-03-30 22:58:26 +02:00
|
|
|
popd
|
|
|
|
|
2022-01-07 04:42:28 +01:00
|
|
|
#=================================================
|
2022-06-10 01:21:56 +02:00
|
|
|
# PEERTUBE UPGRADE MIGRATION SCRIPT
|
2022-01-07 04:42:28 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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..."
|
2023-03-21 23:12:02 +01:00
|
|
|
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
|
2022-01-07 04:42:28 +01:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2022-06-10 00:45:32 +02:00
|
|
|
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..."
|
2023-03-21 23:12:02 +01:00
|
|
|
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
|
2022-06-10 00:45:32 +02:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2021-01-02 20:17:30 +01:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-12-27 18:10:54 +01:00
|
|
|
ynh_script_progression --message="Starting systemd service..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2023-12-27 18:53:30 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on 127.0.0.1"
|
2019-04-03 01:30:38 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|