mirror of
https://github.com/YunoHost-Apps/discourse_ynh.git
synced 2024-09-03 18:26:18 +02:00
Make upgrade only if needed
This commit is contained in:
parent
678f94b2c9
commit
35882c6884
1 changed files with 183 additions and 146 deletions
|
@ -88,6 +88,9 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/l
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Upgrading source files..."
|
ynh_script_progression --message="Upgrading source files..."
|
||||||
|
|
||||||
# Specific actions on ARM architecture
|
# Specific actions on ARM architecture
|
||||||
|
@ -143,6 +146,7 @@ cp -p $tmpdir/discourse.conf $final_path/config
|
||||||
ynh_secure_remove --file="$final_path/plugins/discourse-ldap-auth"
|
ynh_secure_remove --file="$final_path/plugins/discourse-ldap-auth"
|
||||||
mkdir -p "$final_path/plugins/discourse-ldap-auth"
|
mkdir -p "$final_path/plugins/discourse-ldap-auth"
|
||||||
ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth
|
ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
@ -185,17 +189,21 @@ ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE DISCOURSE
|
# CONFIGURE DISCOURSE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Configuring Discourse..."
|
ynh_script_progression --message="Configuring Discourse..."
|
||||||
|
|
||||||
# Make a backup of the original config file if modified
|
# Configure Discourse
|
||||||
ynh_backup_if_checksum_is_different --file="$final_path/config/discourse.conf"
|
|
||||||
# Configure database
|
|
||||||
discourse_config_file="$final_path/config/discourse.conf"
|
discourse_config_file="$final_path/config/discourse.conf"
|
||||||
|
# Make a backup of the original config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different --file="$discourse_config_file"
|
||||||
|
|
||||||
cp $final_path/config/discourse_defaults.conf $discourse_config_file
|
cp $final_path/config/discourse_defaults.conf $discourse_config_file
|
||||||
|
|
||||||
ynh_replace_string --match_string="db_name = discourse" --replace_string="db_name = $db_name" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="db_name = discourse" --replace_string="db_name = $db_name" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="db_username = discourse" --replace_string="db_username = $db_name" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="db_username = discourse" --replace_string="db_username = $db_name" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="db_password =" --replace_string="db_password = $db_pwd" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="db_password =" --replace_string="db_password = $db_pwd" --target_file="$discourse_config_file"
|
||||||
|
|
||||||
# Configure hostname
|
# Configure hostname
|
||||||
ynh_replace_string --match_string="hostname = \"www.example.com\"" --replace_string="hostname = \"$domain\"" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="hostname = \"www.example.com\"" --replace_string="hostname = \"$domain\"" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="relative_url_root =" --replace_string="relative_url_root = ${path_url%/}" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="relative_url_root =" --replace_string="relative_url_root = ${path_url%/}" --target_file="$discourse_config_file"
|
||||||
|
@ -203,63 +211,76 @@ ynh_replace_string --match_string="relative_url_root =" --replace_string="relati
|
||||||
ynh_replace_string --match_string="serve_static_assets = false" --replace_string="serve_static_assets = true" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="serve_static_assets = false" --replace_string="serve_static_assets = true" --target_file="$discourse_config_file"
|
||||||
# Don't show miniprofiler
|
# Don't show miniprofiler
|
||||||
ynh_replace_string --match_string="load_mini_profiler = true" --replace_string="load_mini_profiler = false" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="load_mini_profiler = true" --replace_string="load_mini_profiler = false" --target_file="$discourse_config_file"
|
||||||
|
|
||||||
|
|
||||||
# Configure e-mail server
|
# Configure e-mail server
|
||||||
admin_mail=$(ynh_user_get_info "$admin" mail)
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
||||||
ynh_replace_string --match_string="developer_emails =" --replace_string="developer_emails = $admin_mail" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="developer_emails =" --replace_string="developer_emails = $admin_mail" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="smtp_address =" --replace_string="smtp_address = localhost" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="smtp_address =" --replace_string="smtp_address = localhost" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="smtp_domain =" --replace_string="smtp_domain = $domain" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="smtp_domain =" --replace_string="smtp_domain = $domain" --target_file="$discourse_config_file"
|
||||||
ynh_replace_string --match_string="smtp_enable_start_tls = true" --replace_string="smtp_enable_start_tls = false" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="smtp_enable_start_tls = true" --replace_string="smtp_enable_start_tls = false" --target_file="$discourse_config_file"
|
||||||
|
|
||||||
# Configure redis
|
# Configure redis
|
||||||
ynh_replace_string --match_string="redis_db = 0" --replace_string="redis_db = $redis_db" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="redis_db = 0" --replace_string="redis_db = $redis_db" --target_file="$discourse_config_file"
|
||||||
|
|
||||||
# Don't notify on new versions (handled by the YunoHost package)
|
# Don't notify on new versions (handled by the YunoHost package)
|
||||||
ynh_replace_string --match_string="new_version_emails = true" --replace_string="new_version_emails = false" --target_file="$discourse_config_file"
|
ynh_replace_string --match_string="new_version_emails = true" --replace_string="new_version_emails = false" --target_file="$discourse_config_file"
|
||||||
|
|
||||||
# Calculate and store the config file checksum
|
# Calculate and store the config file checksum
|
||||||
ynh_store_file_checksum --file="$discourse_config_file"
|
ynh_store_file_checksum --file="$discourse_config_file"
|
||||||
|
|
||||||
# Make a backup of the original config file if modified
|
|
||||||
ynh_backup_if_checksum_is_different "$final_path/plugins/discourse-ldap-auth/config/settings.yml"
|
|
||||||
|
|
||||||
# Configure LDAP plugin
|
# Configure LDAP plugin
|
||||||
ldap_config_file="$final_path/plugins/discourse-ldap-auth/config/settings.yml"
|
ldap_config_file="$final_path/plugins/discourse-ldap-auth/config/settings.yml"
|
||||||
|
# Make a backup of the original config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different "$ldap_config_file"
|
||||||
|
|
||||||
ynh_replace_string --match_string="adfs.example.com" --replace_string="localhost" --target_file="$ldap_config_file"
|
ynh_replace_string --match_string="adfs.example.com" --replace_string="localhost" --target_file="$ldap_config_file"
|
||||||
ynh_replace_string --match_string="dc=example,dc=com" --replace_string="ou=users,dc=yunohost,dc=org" --target_file="$ldap_config_file"
|
ynh_replace_string --match_string="dc=example,dc=com" --replace_string="ou=users,dc=yunohost,dc=org" --target_file="$ldap_config_file"
|
||||||
ynh_replace_string --match_string="sAMAccountName" --replace_string="uid" --target_file="$ldap_config_file"
|
ynh_replace_string --match_string="sAMAccountName" --replace_string="uid" --target_file="$ldap_config_file"
|
||||||
|
|
||||||
|
# Calculate and store the config file checksum
|
||||||
ynh_store_file_checksum --file="$ldap_config_file"
|
ynh_store_file_checksum --file="$ldap_config_file"
|
||||||
|
|
||||||
# Disable svgo worker
|
# Disable svgo worker
|
||||||
echo "svgo: false" > $final_path/.image_optim.yml
|
echo "svgo: false" > $final_path/.image_optim.yml
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP UNICORN, A RUBY SERVER
|
# SETUP UNICORN, A RUBY SERVER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Setting up Unicorn..."
|
ynh_script_progression --message="Setting up Unicorn..."
|
||||||
|
|
||||||
unicorn_config_file="$final_path/config/unicorn.conf.rb"
|
unicorn_config_file="$final_path/config/unicorn.conf.rb"
|
||||||
|
# Make a backup of the original config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different "$unicorn_config_file"
|
||||||
|
|
||||||
# Use socket connection
|
# Use socket connection
|
||||||
ynh_replace_string --match_string='listen (ENV\["UNICORN_PORT"\] || 3000).to_i' --replace_string='# listen (ENV["UNICORN_PORT"] || 3000).to_i' --target_file="$unicorn_config_file"
|
ynh_replace_string --match_string='listen (ENV\["UNICORN_PORT"\] || 3000).to_i' --replace_string='# listen (ENV["UNICORN_PORT"] || 3000).to_i' --target_file="$unicorn_config_file"
|
||||||
ynh_replace_string --match_string='# listen "#{discourse_path}/tmp/sockets/unicorn.sock"' --replace_string='listen "#{discourse_path}/tmp/sockets/unicorn.sock"' --target_file="$unicorn_config_file"
|
ynh_replace_string --match_string='# listen "#{discourse_path}/tmp/sockets/unicorn.sock"' --replace_string='listen "#{discourse_path}/tmp/sockets/unicorn.sock"' --target_file="$unicorn_config_file"
|
||||||
|
|
||||||
# Calculate and store the config file checksum
|
# Calculate and store the config file checksum
|
||||||
ynh_store_file_checksum --file="$unicorn_config_file"
|
ynh_store_file_checksum --file="$unicorn_config_file"
|
||||||
|
|
||||||
|
secret_config_file="$final_path/config/secrets.yml"
|
||||||
|
# Make a backup of the original config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different "$secret_config_file"
|
||||||
|
|
||||||
# Set a secret value
|
# Set a secret value
|
||||||
cp ../conf/secrets.yml "$final_path/config/secrets.yml"
|
cp ../conf/secrets.yml "$final_path/config/secrets.yml"
|
||||||
ynh_replace_string --match_string="__SECRET__" --replace_string="$(ynh_string_random)" --target_file="$final_path/config/secrets.yml"
|
ynh_replace_string --match_string="__SECRET__" --replace_string="$(ynh_string_random)" --target_file="$secret_config_file"
|
||||||
|
|
||||||
# Calculate and store the config file checksum
|
# Calculate and store the config file checksum
|
||||||
ynh_store_file_checksum --file="$final_path/config/secrets.yml"
|
ynh_store_file_checksum --file="$secret_config_file"
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown -R $app: $final_path
|
chown -R $app: $final_path
|
||||||
|
|
||||||
(cd "$final_path"
|
(
|
||||||
|
cd "$final_path"
|
||||||
# Install bundler, a gems installer
|
# Install bundler, a gems installer
|
||||||
gem install bundler
|
gem install bundler
|
||||||
# Install without documentation
|
# Install without documentation
|
||||||
exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc")
|
exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
||||||
|
)
|
||||||
# Specific actions on ARM architecture
|
# Specific actions on ARM architecture
|
||||||
if [ -n "$(uname -m | grep arm)" ] ; then
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
||||||
# Define the platform specifically to retrieve binaries
|
# Define the platform specifically to retrieve binaries
|
||||||
|
@ -274,34 +295,49 @@ exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2
|
||||||
# On ARM architecture, replace bundled libpsl by system native libpsl
|
# On ARM architecture, replace bundled libpsl by system native libpsl
|
||||||
# because the provided binary isn't compatible
|
# because the provided binary isn't compatible
|
||||||
if [ -n "$(uname -m | grep arm)" ] ; then
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
||||||
(cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor
|
(
|
||||||
|
cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor
|
||||||
rm libpsl.so
|
rm libpsl.so
|
||||||
ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so)
|
ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so
|
||||||
|
)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PREPARE THE DATABASE
|
# PREPARE THE DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Preparing the database..."
|
ynh_script_progression --message="Preparing the database..."
|
||||||
|
|
||||||
rake_exec="exec_login_as $app RAILS_ENV=production bin/rake"
|
rake_exec="exec_login_as $app RAILS_ENV=production bin/rake"
|
||||||
$rake_exec db:migrate
|
$rake_exec db:migrate
|
||||||
$rake_exec assets:precompile
|
$rake_exec assets:precompile
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE PLUGINS
|
# CONFIGURE PLUGINS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Configuring plugins..."
|
ynh_script_progression --message="Configuring plugins..."
|
||||||
|
|
||||||
# Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder
|
# 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)
|
# (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
|
# Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16
|
||||||
(cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/
|
(
|
||||||
patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch)
|
cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/
|
||||||
|
patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
|
then
|
||||||
ynh_script_progression --message="Configuring a systemd service..."
|
ynh_script_progression --message="Configuring a systemd service..."
|
||||||
|
|
||||||
ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service"
|
ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service"
|
||||||
|
@ -310,6 +346,7 @@ additional_env="UNICORN_WORKERS=$unicorn_workers"
|
||||||
ynh_replace_string --match_string="__ADDITIONAL_ENV__" --replace_string="$additional_env" --target_file="../conf/systemd.service"
|
ynh_replace_string --match_string="__ADDITIONAL_ENV__" --replace_string="$additional_env" --target_file="../conf/systemd.service"
|
||||||
ynh_replace_string --match_string="__LIBJEMALLOC__" --replace_string="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" --target_file="../conf/systemd.service"
|
ynh_replace_string --match_string="__LIBJEMALLOC__" --replace_string="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" --target_file="../conf/systemd.service"
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
|
Loading…
Add table
Reference in a new issue