2018-03-26 05:50:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2022-01-07 04:42:28 +01:00
|
|
|
source ynh_redis
|
2022-06-10 01:21:56 +02:00
|
|
|
source ynh_apps
|
2019-04-03 03:27:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2022-06-10 01:21:56 +02:00
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
2019-06-03 22:37:54 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2021-01-13 20:59:06 +01:00
|
|
|
rtmp_port=$(ynh_app_setting_get --app=$app --key=rtmp_port)
|
2021-02-26 03:34:51 +01:00
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2022-01-07 04:42:28 +01:00
|
|
|
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
|
2022-06-10 01:21:56 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2020-09-27 19:00:21 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2022-06-10 01:21:56 +02:00
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key="mail")
|
2021-12-24 09:22:23 +01:00
|
|
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2021-06-29 22:13:41 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
|
|
|
|
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-02-26 03:34:51 +01:00
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
db_name="peertube_${app}"
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
fi
|
|
|
|
|
2022-01-07 04:42:28 +01:00
|
|
|
# If db_user doesn't exist, create it
|
|
|
|
if [ -z "$db_user" ]; then
|
|
|
|
db_user=$app
|
|
|
|
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
|
|
|
|
fi
|
|
|
|
|
2021-02-26 03:34:51 +01:00
|
|
|
# If db_pwd doesn't exist, create it
|
|
|
|
if [ -z "$db_pwd" ]; then
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
2018-03-26 05:50:46 +02:00
|
|
|
fi
|
|
|
|
|
2021-12-24 09:22:23 +01:00
|
|
|
# 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
|
|
|
|
|
2020-09-27 19:00:21 +02:00
|
|
|
if [ -z "$datadir" ];
|
|
|
|
then
|
2021-02-26 03:34:51 +01:00
|
|
|
datadir="/home/yunohost.app/${app}/storage"
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
2020-09-27 19:00:21 +02:00
|
|
|
fi
|
|
|
|
|
2019-04-03 04:44:26 +02:00
|
|
|
# Close a port
|
|
|
|
if yunohost firewall list | grep -q "\- $port$"
|
|
|
|
then
|
2020-06-01 03:40:44 +02:00
|
|
|
ynh_script_progression --message="Closing port $port"
|
2019-04-03 04:44:26 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall disallow TCP $port
|
|
|
|
fi
|
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
# Add PostgreSQL extension for v1.0.0-beta.10.pre.1
|
2021-12-26 23:11:48 +01:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
|
|
|
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
|
|
|
|
2021-05-14 00:14:17 +02:00
|
|
|
# Remove not needed checksum
|
|
|
|
ynh_delete_file_checksum --file="../conf/msg_install"
|
|
|
|
|
2021-01-13 20:59:06 +01:00
|
|
|
if [ -z "$rtmp_port" ];
|
|
|
|
then
|
2021-02-26 03:34:51 +01:00
|
|
|
rtmp_port=1935
|
2022-01-11 19:57:09 +01:00
|
|
|
ynh_port_available --port=$rtmp_port || ynh_die --message="Port $rtmp_port is needs to be available for this app"
|
2021-02-26 03:34:51 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=rtmp_port --value=$rtmp_port
|
|
|
|
|
|
|
|
# Open the port
|
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
|
|
ynh_exec_warn_less yunohost firewall allow TCP $rtmp_port
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
2021-01-13 20:59:06 +01:00
|
|
|
fi
|
|
|
|
|
2021-03-01 02:27:44 +01:00
|
|
|
# Create a permission if needed
|
|
|
|
if ! ynh_permission_exists --permission="api"; then
|
|
|
|
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
|
|
|
|
fi
|
|
|
|
|
2022-01-30 21:34:03 +01:00
|
|
|
# Remove hook
|
|
|
|
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
|
|
|
|
yunohost tools regen-conf nginx
|
|
|
|
|
2022-02-08 01:41:44 +01:00
|
|
|
# Remove old log file
|
|
|
|
ynh_secure_remove --file="$datadir/logs"
|
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
|
2021-04-10 19:38:56 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2022-02-08 01:41:44 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
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
|
2022-06-10 01:21:56 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --keep="config/production.yaml config/local-production.json"
|
2019-06-03 22:37:54 +02:00
|
|
|
fi
|
2018-05-21 12:10:41 +02:00
|
|
|
|
2021-04-17 18:31:58 +02:00
|
|
|
chmod 750 "$final_path"
|
2021-04-10 19:38:56 +02:00
|
|
|
chmod -R o-rwx "$final_path"
|
2021-06-18 01:12:10 +02:00
|
|
|
chown -R $app:www-data "$final_path"
|
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-06-10 01:21:56 +02:00
|
|
|
ynh_install_apps --apps="$ynh_app_dependencies"
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
2019-04-03 02:43:43 +02:00
|
|
|
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
|
|
|
|
2022-06-10 01:21:56 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
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
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2021-06-29 22:13:41 +02:00
|
|
|
# CREATE DATA DIRECTORY
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2021-06-29 22:13:41 +02:00
|
|
|
ynh_script_progression --message="Creating a data directory..."
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2021-06-29 22:13:41 +02:00
|
|
|
mkdir -p $datadir
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2022-02-08 01:41:44 +01:00
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
chown -R $app:www-data "$datadir"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
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
|
|
|
#=================================================
|
2021-04-10 19:38:56 +02:00
|
|
|
ynh_script_progression --message="Updating a config file..."
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2021-02-26 03:48:49 +01:00
|
|
|
ynh_add_config --template="../conf/production.yaml" --destination="$final_path/config/production.yaml"
|
2020-06-01 03:40:44 +02:00
|
|
|
|
2021-04-10 19:38:56 +02:00
|
|
|
chmod 400 "$final_path/config/production.yaml"
|
|
|
|
chown $app:$app "$final_path/config/production.yaml"
|
|
|
|
|
2021-04-25 12:26:33 +02:00
|
|
|
chmod 600 "$final_path/config/local-production.json"
|
2021-04-10 19:38:56 +02:00
|
|
|
chown $app:$app "$final_path/config/local-production.json"
|
2019-06-06 23:16:31 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
#=================================================
|
|
|
|
# BUILD YARN DEPENDENCIES
|
|
|
|
#=================================================
|
2020-09-11 14:20:57 +02:00
|
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
2019-06-03 22:37:54 +02:00
|
|
|
|
|
|
|
pushd "$final_path"
|
2019-06-23 16:13:13 +02:00
|
|
|
ynh_use_nodejs
|
2022-01-30 21:34:03 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
2022-02-08 01:41:44 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean
|
2019-06-03 22:37:54 +02:00
|
|
|
popd
|
|
|
|
|
2022-01-10 20:47:14 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost"
|
|
|
|
|
2021-03-30 22:58:26 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL LDAP PLUGIN
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing LDAP plugin..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
2022-01-30 21:34:03 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-auth-ldap
|
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL PEERTUBE LIVECHAT PLUGIN
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing PeerTube livechat plugin..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/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..."
|
|
|
|
pushd "$final_path"
|
2022-01-30 21:34:03 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/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..."
|
|
|
|
pushd "$final_path"
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production $ynh_node dist/scripts/migrations/peertube-4.2.js
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2022-01-10 20:47:14 +01:00
|
|
|
# STOP SYSTEMD SERVICE
|
2018-03-26 05:50:46 +02:00
|
|
|
#=================================================
|
2022-01-10 20:47:14 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2019-04-03 01:30:38 +02:00
|
|
|
|
2022-01-10 20:47:14 +01:00
|
|
|
# Stop a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
2018-03-26 05:50:46 +02:00
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2021-01-02 20:17:30 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
2022-02-08 01:41:44 +01:00
|
|
|
yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $rtmp_port
|
2021-01-02 20:17:30 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
2021-03-30 22:58:26 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost"
|
2021-01-02 20:17:30 +01:00
|
|
|
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
2019-06-03 22:37:54 +02:00
|
|
|
# RELOAD NGINX
|
2019-04-03 02:30:56 +02:00
|
|
|
#=================================================
|
2020-09-11 14:20:57 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-04-03 02:30:56 +02:00
|
|
|
|
2019-06-03 22:37:54 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
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"
|