2018-04-14 09:33:23 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2018-04-24 17:45:19 +02:00
|
|
|
source _common.sh
|
2020-04-27 13:41:00 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
if [ "${PACKAGE_CHECK_EXEC:-0}" -ne 1 ]; then
|
|
|
|
# Check memory requirements
|
|
|
|
check_memory_requirements
|
2021-06-27 14:08:14 +02:00
|
|
|
fi
|
2018-04-30 18:53:20 +02:00
|
|
|
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
# INITIALIZE AND STORE SETTINGS
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
relative_url_root=${path%/}
|
|
|
|
secret="$(ynh_string_random)"
|
2020-02-15 19:06:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE MAINTENANCE MODE
|
|
|
|
#=================================================
|
2020-05-30 17:05:03 +02:00
|
|
|
ynh_script_progression --message="Enabling maintenance mode..."
|
2020-02-15 19:06:13 +01:00
|
|
|
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-30 17:05:03 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2024-08-30 15:00:35 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="$install_dir/discourse/log/unicorn.stdout.log"
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2022-05-29 17:36:13 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
|
|
|
# If unicorn_workers doesn't exist, create it
|
2024-01-26 22:16:29 +01:00
|
|
|
if [ -z "$unicorn_workers" ]; then
|
|
|
|
# We assume for the moment that ARM devices are only dual core, so
|
|
|
|
# we restrict the number of workers to 2 (the default is 3)
|
|
|
|
if dpkg --print-architecture | grep -q "arm"; then
|
|
|
|
unicorn_workers=2
|
|
|
|
else
|
|
|
|
unicorn_workers=3
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set --app="$app" --key="unicorn_workers" --value="$unicorn_workers"
|
2022-05-29 17:36:13 +02:00
|
|
|
fi
|
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
if [ -f "$install_dir/tmp/sockets/unicorn.sock" ]; then
|
|
|
|
# Move sources into the discourse subdir.
|
|
|
|
mkdir -p "$install_dir/__new__"
|
|
|
|
find "$install_dir" -mindepth 1 -maxdepth 1 -not -name "__new__" -print0 | xargs -0 mv -t "$install_dir/__new__"
|
|
|
|
mv "$install_dir/__new__" "$install_dir/discourse"
|
|
|
|
fi
|
|
|
|
|
2024-08-30 13:28:50 +02:00
|
|
|
# See https://github.com/jonmbake/discourse-ldap-auth/issues/77
|
|
|
|
if [ -d "$install_dir/discourse/plugins/discourse-ldap-auth" ]; then
|
|
|
|
mv "$install_dir/discourse/plugins/discourse-ldap-auth" "$install_dir/discourse/plugins/ldap"
|
|
|
|
fi
|
|
|
|
|
2021-04-10 01:48:01 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
# UPGRADING DEPENDENCIES
|
2021-04-10 01:48:01 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Upgrading Ruby..."
|
|
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
|
2021-04-10 01:48:01 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Upgrading NodeJS..."
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2021-04-10 01:48:01 +02:00
|
|
|
|
2024-08-30 13:41:34 +02:00
|
|
|
ynh_script_progression --message="Building and upgrading ImageMagick v7..."
|
|
|
|
install_imagemagick
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrading Oxipng..."
|
|
|
|
install_oxipng
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Specific actions on ARM architecture
|
|
|
|
if dpkg --print-architecture | grep -q "arm"; then
|
|
|
|
# Unapply commit cf9b4a789b855b5199e98a13424e409854a8e848 that breaks ARM
|
|
|
|
# compatibility by pointing to a recent libv8 version
|
|
|
|
# This is due to this libv8 issue (https://github.com/cowboyd/libv8/issues/261)
|
|
|
|
# that prevents it from being compiled on ARM hence no binary gem is available yet
|
|
|
|
cp ../sources/patches_arm/* ../sources/patches
|
2020-05-30 17:32:33 +02:00
|
|
|
fi
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Small trick to backup non-core plugins
|
2024-08-29 12:47:51 +02:00
|
|
|
mv "$install_dir/discourse/plugins" "$install_dir/discourse/plugins_old"
|
2021-04-10 01:48:01 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2024-08-29 12:47:51 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/discourse" --full_replace=1 \
|
2024-01-26 22:16:29 +01:00
|
|
|
--keep="config/discourse.conf plugins_old public/uploads public/backups log"
|
2022-07-19 00:04:56 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Restore all non-core plugins
|
2024-08-29 12:47:51 +02:00
|
|
|
for plugin_dir in "$install_dir/discourse/plugins_old"/*; do
|
2024-01-26 22:16:29 +01:00
|
|
|
plugin_name=$(basename "$plugin_dir")
|
2024-08-29 12:47:51 +02:00
|
|
|
if [ ! -d "$install_dir/discourse/plugins/$plugin_name" ]; then
|
|
|
|
mv "$plugin_dir" "$install_dir/discourse/plugins/$plugin_name"
|
2024-01-26 22:16:29 +01:00
|
|
|
fi
|
|
|
|
done
|
2024-05-23 14:19:19 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
ynh_secure_remove --file="$install_dir/discourse/plugins_old"
|
2022-07-19 00:04:56 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Install LDAP plugin
|
2024-08-30 13:28:50 +02:00
|
|
|
ynh_setup_source --source_id=ldap-auth --dest_dir="$install_dir/discourse/plugins/ldap" --full_replace=1 \
|
2024-01-26 22:16:29 +01:00
|
|
|
--keep="config/settings.yml"
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Add a pids and socket directory for the systemd script.
|
2024-08-29 12:47:51 +02:00
|
|
|
mkdir -p "$install_dir/discourse/tmp/pids"
|
|
|
|
mkdir -p "$install_dir/discourse/tmp/sockets"
|
|
|
|
mkdir -p "$install_dir/discourse/public/forum"
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Create specific folders and links for subfolder compatibility
|
|
|
|
# (see: https://meta.discourse.org/t/subfolder-support-with-docker/30507)
|
2024-08-29 12:47:51 +02:00
|
|
|
ln -s "$install_dir/discourse/public/uploads" "$install_dir/discourse/public/forum/uploads"
|
|
|
|
ln -s "$install_dir/discourse/public/backups" "$install_dir/discourse/public/forum/backups"
|
2024-01-26 22:16:29 +01:00
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-05-29 17:36:13 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Updating $app's config file..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
ynh_add_config --template="discourse_defaults.conf" --destination="$install_dir/discourse/config/discourse.conf"
|
|
|
|
ynh_add_config --template="secrets.yml" --destination="$install_dir/discourse/config/secrets.yml"
|
2024-08-30 13:28:50 +02:00
|
|
|
ynh_add_config --template="settings.yml" --destination="$install_dir/discourse/plugins/ldap/config/settings.yml"
|
2020-05-30 17:32:33 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Disable svgo worker
|
2024-08-29 12:47:51 +02:00
|
|
|
echo "svgo: false" | ynh_exec_as "$app" tee "$install_dir/discourse/.image_optim.yml" >/dev/null
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP UNICORN, A RUBY SERVER
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Setting up Unicorn..."
|
|
|
|
|
2024-05-24 15:22:42 +02:00
|
|
|
# Do it after setup_source because .ruby-version is stored in cwd
|
|
|
|
ynh_use_ruby
|
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Make a backup of the original config file if modified
|
2024-08-29 12:47:51 +02:00
|
|
|
unicorn_config_file="$install_dir/discourse/config/unicorn.conf.rb"
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_backup_if_checksum_is_different "$unicorn_config_file"
|
|
|
|
ynh_store_file_checksum --file="$unicorn_config_file"
|
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
pushd "$install_dir/discourse"
|
2024-01-26 22:16:29 +01:00
|
|
|
# Install bundler, a gems installer
|
|
|
|
ynh_gem install bundler
|
|
|
|
# Install without documentation
|
2024-05-23 14:21:44 +02:00
|
|
|
echo "gem: --no-ri --no-rdoc" | ynh_exec_as "$app" tee "$install_dir/.gemrc" >/dev/null
|
2024-01-26 22:16:29 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
# Specific actions on ARM architecture
|
|
|
|
if dpkg --print-architecture | grep -q "arm"; then
|
|
|
|
# Define the platform specifically to retrieve binaries
|
|
|
|
# for libv8 because it currently doesn't compile on ARM devices
|
2024-08-30 11:22:21 +02:00
|
|
|
_exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config specific_platform arm-linux
|
2024-01-26 22:16:29 +01:00
|
|
|
fi
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Install dependencies
|
2024-08-30 11:22:21 +02:00
|
|
|
_exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set path 'vendor/bundle'
|
|
|
|
_exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set with 'development'
|
|
|
|
_exec_as_app_with_ruby_node MAKEFLAGS=-j2 "$install_dir/discourse/bin/bundle" install --jobs 2
|
2024-01-26 22:16:29 +01:00
|
|
|
|
|
|
|
# On ARM architecture, replace bundled libpsl by system native libpsl
|
|
|
|
# because the provided binary isn't compatible
|
|
|
|
if dpkg --print-architecture | grep -q "arm"; then
|
|
|
|
(
|
2024-08-29 12:47:51 +02:00
|
|
|
cd "$install_dir/discourse/vendor/bundle/ruby"/*/"gems/mini_suffix-*/vendor"
|
2024-01-26 22:16:29 +01:00
|
|
|
rm libpsl.so
|
|
|
|
ln -s "$(ldconfig -p | grep libpsl | awk 'END {print $NF}')" libpsl.so
|
|
|
|
)
|
2018-04-29 11:28:38 +02:00
|
|
|
fi
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
pushd "$install_dir/discourse"
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_npm install --location=global terser
|
|
|
|
ynh_npm install --location=global uglify-js
|
2024-08-30 11:22:21 +02:00
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node yarn install --production --frozen-lockfile
|
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node yarn cache clean
|
2024-01-26 22:16:29 +01:00
|
|
|
popd
|
|
|
|
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# PREPARE THE DATABASE
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Preparing the database..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
pushd "$install_dir/discourse"
|
2024-08-30 11:22:21 +02:00
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake db:migrate
|
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake themes:update assets:precompile
|
2024-08-29 12:47:51 +02:00
|
|
|
popd
|
2022-06-03 01:08:53 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PLUGINS
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Configuring plugins..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder
|
|
|
|
# (Can only do that now because we are patching dependencies which have just been downloaded)
|
|
|
|
# Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16
|
2024-08-30 13:28:50 +02:00
|
|
|
patch -p1 -d "$install_dir/discourse/plugins/ldap/gems/$ruby_version/gems/omniauth-ldap"*/ \
|
2024-01-26 22:16:29 +01:00
|
|
|
< "../conf/ldap-auth-fix-subfolder.patch"
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2021-03-07 01:39:02 +01:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
# Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191
|
|
|
|
if [ "$path" != "/" ] ; then
|
|
|
|
ynh_replace_string --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" \
|
|
|
|
--match_string='$proxy_add_x_forwarded_for' \
|
|
|
|
--replace_string='$http_your_original_ip_header'
|
2020-05-30 17:32:33 +02:00
|
|
|
fi
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
additional_env="UNICORN_WORKERS=$unicorn_workers"
|
|
|
|
ynh_add_systemd_config
|
2024-08-29 12:47:51 +02:00
|
|
|
yunohost service add "$app" --log "$install_dir/discourse/log/unicorn.stderr.log" "$install_dir/discourse/log/unicorn.stdout.log" "$install_dir/discourse/log/production.log"
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2021-03-07 01:39:02 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2024-08-29 12:47:51 +02:00
|
|
|
ynh_use_logrotate --logfile="$install_dir/discourse/log/unicorn.stderr.log"
|
|
|
|
ynh_use_logrotate --logfile="$install_dir/discourse/log/unicorn.stdout.log"
|
|
|
|
ynh_use_logrotate --logfile="$install_dir/discourse/log/production.log"
|
2020-12-03 19:30:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2018-04-14 09:33:23 +02:00
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..."
|
2018-04-14 09:33:23 +02:00
|
|
|
|
2024-08-30 15:00:35 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/discourse/log/unicorn.stdout.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready"
|
2018-06-03 17:21:50 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DISABLE MAINTENANCE MODE
|
|
|
|
#=================================================
|
2020-05-30 17:05:03 +02:00
|
|
|
ynh_script_progression --message="Disabling maintenance mode..."
|
2018-06-03 17:21:50 +02:00
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-30 17:05:03 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|