2018-04-02 16:36:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# GENERIC START
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# 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-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Managing script failure..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2018-05-02 20:00:27 +02:00
|
|
|
# Clean remainings not handled by remove script
|
|
|
|
ynh_clean_check_starting
|
2018-04-02 16:36:02 +02:00
|
|
|
}
|
2020-04-27 13:41:00 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Retrieving arguments from the manifest..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Validating installation parameters..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
2020-04-27 13:41:00 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Register (book) web path
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-30 18:53:20 +02:00
|
|
|
# Check memory requirements
|
|
|
|
check_memory_requirements
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Storing installation settings..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Installing dependencies..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-24 21:27:56 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# CREATE A POSTGRESQL DATABASE
|
2018-04-24 21:27:56 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Creating a PostgreSQL database..."
|
2018-04-24 21:27:56 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
2018-04-02 16:36:02 +02:00
|
|
|
db_pwd=$(ynh_string_random)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
2018-04-02 16:36:02 +02:00
|
|
|
ynh_psql_test_if_first_run
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
2018-04-02 16:36:02 +02:00
|
|
|
# Set extensions
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$db_name
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Setting up source files..."
|
|
|
|
|
2018-12-27 12:50:00 +01:00
|
|
|
# Specific actions on ARM architecture
|
|
|
|
if [ -n "$(uname -m | grep 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
|
|
|
|
fi
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-04-02 16:36:02 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
# Install LDAP plugin
|
|
|
|
mkdir -p "$final_path/plugins/discourse-ldap-auth"
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-24 21:27:56 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL RUBY
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Installing Ruby..."
|
2018-04-24 21:27:56 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
2018-04-24 21:27:56 +02:00
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring nginx web server..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-06-03 17:56:14 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
# Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191
|
|
|
|
if [ "$path_url" != "/" ] ; then
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string='$proxy_add_x_forwarded_for' --replace_string='$http_your_original_ip_header' --target_file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-04-02 16:36:02 +02:00
|
|
|
fi
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# CREATE DEDICATED USER
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE DISCOURSE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring Discourse..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Configure database
|
2018-04-07 11:56:54 +02:00
|
|
|
discourse_config_file="$final_path/config/discourse.conf"
|
|
|
|
cp $final_path/config/discourse_defaults.conf $discourse_config_file
|
2020-04-27 13:41:00 +02:00
|
|
|
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_password =" --replace_string="db_password = $db_pwd" --target_file="$discourse_config_file"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Configure hostname
|
2020-04-27 13:41:00 +02:00
|
|
|
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"
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
# Serve static assets (i.e. images, js, etc.)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="serve_static_assets = false" --replace_string="serve_static_assets = true" --target_file="$discourse_config_file"
|
|
|
|
|
2018-04-07 11:58:39 +02:00
|
|
|
# Don't show miniprofiler
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="load_mini_profiler = true" --replace_string="load_mini_profiler = false" --target_file="$discourse_config_file"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Configure e-mail server
|
|
|
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
2020-04-27 13:41:00 +02:00
|
|
|
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_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"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-07-01 10:06:14 +02:00
|
|
|
# Configure redis
|
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
ynh_replace_string --match_string="redis_db = 0" --replace_string="redis_db = $redis_db" --target_file="$discourse_config_file"
|
2018-07-01 10:06:14 +02:00
|
|
|
|
2018-08-01 23:08:07 +02:00
|
|
|
# Don't notify on new versions (handled by the YunoHost package)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="new_version_emails = true" --replace_string="new_version_emails = false" --target_file="$discourse_config_file"
|
2018-08-01 23:08:07 +02:00
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
# Calculate and store the config file checksum
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_store_file_checksum --file="$discourse_config_file"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-07 11:56:54 +02:00
|
|
|
# Configure LDAP plugin
|
|
|
|
ldap_config_file="$final_path/plugins/discourse-ldap-auth/config/settings.yml"
|
2020-04-27 13:41:00 +02:00
|
|
|
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="sAMAccountName" --replace_string="uid" --target_file="$ldap_config_file"
|
|
|
|
ynh_store_file_checksum --file="$ldap_config_file"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-05-03 07:23:29 +02:00
|
|
|
# Disable svgo worker
|
|
|
|
echo "svgo: false" > $final_path/.image_optim.yml
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
2018-05-04 12:51:16 +02:00
|
|
|
# SETUP UNICORN, A RUBY SERVER
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Setuping Unicorn..."
|
|
|
|
|
2018-05-04 12:51:16 +02:00
|
|
|
unicorn_config_file="$final_path/config/unicorn.conf.rb"
|
|
|
|
# Use socket connection
|
2020-04-27 13:41:00 +02:00
|
|
|
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"
|
2018-04-02 16:36:02 +02:00
|
|
|
# Calculate and store the config file checksum
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_store_file_checksum --file="$unicorn_config_file"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Set a secret value
|
|
|
|
cp ../conf/secrets.yml "$final_path/config/secrets.yml"
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="__SECRET__" --replace_string="$(ynh_string_random)" --target_file="$final_path/config/secrets.yml"
|
2018-04-02 16:36:02 +02:00
|
|
|
# Calculate and store the config file checksum
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_store_file_checksum --file="$final_path/config/secrets.yml"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
pushd "$final_path"
|
|
|
|
# Install bundler, a gems installer
|
|
|
|
gem install bundler
|
|
|
|
# Install without documentation
|
|
|
|
exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
|
|
|
popd
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-08-01 23:08:07 +02:00
|
|
|
# Specific actions on ARM architecture
|
2018-04-29 11:25:32 +02:00
|
|
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
2018-08-01 23:08:07 +02:00
|
|
|
# Define the platform specifically to retrieve binaries
|
|
|
|
# for libv8 because it currently doesn't compile on ARM devices
|
2018-04-29 11:25:32 +02:00
|
|
|
exec_login_as $app bundle config specific_platform arm-linux
|
|
|
|
fi
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2018-04-07 11:56:54 +02:00
|
|
|
# Install dependencies
|
2020-02-15 19:06:13 +01:00
|
|
|
exec_login_as $app bundle config set path 'vendor/bundle'
|
|
|
|
exec_login_as $app bundle config set with 'development'
|
|
|
|
exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-29 11:25:32 +02:00
|
|
|
# On ARM architecture, replace bundled libpsl by system native libpsl
|
|
|
|
# because the provided binary isn't compatible
|
|
|
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
|
|
|
(cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor
|
|
|
|
rm libpsl.so
|
|
|
|
ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so)
|
|
|
|
fi
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# PREPARE THE DATABASE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Preparing the database..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-24 21:27:56 +02:00
|
|
|
rake_exec="exec_login_as $app RAILS_ENV=production bin/rake"
|
2018-04-02 16:36:02 +02:00
|
|
|
$rake_exec db:migrate
|
2018-04-24 21:27:56 +02:00
|
|
|
$rake_exec assets:precompile
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-07 11:59:38 +02:00
|
|
|
#=================================================
|
|
|
|
# POPULATE THE DATABASE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Populating the database..."
|
|
|
|
|
2018-04-07 11:59:38 +02:00
|
|
|
#Set default data (especially to have correct image URLs for subfolder install)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('title', 1, 'YunoHost Forum', 'NOW()', 'NOW()');
|
2018-04-07 11:59:38 +02:00
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('site_description', 1, 'YunoHost Forum', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('contact_email', 14, '$admin_mail', 'NOW()', 'NOW()');
|
2018-04-08 17:23:18 +02:00
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('contact_url', 1, '$domain$path_url', 'NOW()', 'NOW()');
|
2018-04-07 11:59:38 +02:00
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('site_contact_username', 15, '$admin', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('logo_url', 1, '${path_url%/}/images/d-logo-sketch.png', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('long_polling_base_url', 1, '${path_url%/}/', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('logo_small_url', 1, '${path_url%/}/images/d-logo-sketch-small.png', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('favicon_url', 1, '${path_url%/}/images/default-favicon.ico', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('apple_touch_icon_url', 1, '${path_url%/}/images/default-apple-touch-icon.png', 'NOW()', 'NOW()');
|
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('wizard_enabled', 5, 'f', 'NOW()', 'NOW()');
|
2018-06-03 17:24:21 +02:00
|
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('force_https', 5, 't', 'NOW()', 'NOW()');
|
2018-04-07 11:59:38 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FIX INITIAL POSTS LINKS FOR SUBFOLDER INSTALL
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Fixing initial post links..."
|
2018-04-08 17:23:18 +02:00
|
|
|
|
2018-04-07 11:59:38 +02:00
|
|
|
if [ "$path_url" != "/" ] ; then
|
2018-04-24 21:27:56 +02:00
|
|
|
exec_login_as $app RAILS_ENV=production bundle exec script/discourse remap /images/welcome/ $path_url/images/welcome/ <<< "YES
|
|
|
|
"
|
2018-04-07 11:59:38 +02:00
|
|
|
fi
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# CREATE DISCOURSE ADMIN USER
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Creating Discourse admin user..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-03 18:28:04 +02:00
|
|
|
# Create a random password
|
|
|
|
admin_pwd=$(ynh_string_random)
|
2018-04-08 17:23:18 +02:00
|
|
|
$rake_exec admin:create <<< "$admin_mail
|
2018-04-03 18:28:04 +02:00
|
|
|
$admin_pwd
|
|
|
|
$admin_pwd
|
|
|
|
y
|
2018-04-24 21:27:56 +02:00
|
|
|
"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-04-03 18:27:06 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PLUGINS
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring plugins..."
|
2018-04-03 18:27:06 +02:00
|
|
|
|
2018-04-21 15:27:07 +02:00
|
|
|
# Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder
|
2018-04-03 18:27:06 +02:00
|
|
|
# (Can only do that now because we are patching dependencies which have just been downloaded)
|
2018-04-21 15:27:07 +02:00
|
|
|
# Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16
|
2019-02-10 12:14:36 +01:00
|
|
|
(cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/
|
2018-04-03 18:27:06 +02:00
|
|
|
patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch)
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring a systemd service..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service"
|
2018-04-24 21:27:56 +02:00
|
|
|
|
2018-04-29 11:25:32 +02:00
|
|
|
# We assume for the moment that ARM devices are only dual core, so
|
2018-05-04 12:51:16 +02:00
|
|
|
# we restrict the number of workers to 2 (the default is 3)
|
2018-04-29 11:25:32 +02:00
|
|
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
2018-05-04 12:51:16 +02:00
|
|
|
additional_env="UNICORN_WORKERS=2"
|
|
|
|
unicorn_workers=2
|
2018-04-29 11:25:32 +02:00
|
|
|
else
|
|
|
|
additional_env=""
|
2018-05-04 12:51:16 +02:00
|
|
|
unicorn_workers=3
|
2018-04-29 11:25:32 +02:00
|
|
|
fi
|
2020-04-27 13:41:00 +02:00
|
|
|
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"
|
2018-05-04 12:51:16 +02:00
|
|
|
ynh_add_systemd_config
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Securing files and directories..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Add a pids and socket directory for the systemd script.
|
|
|
|
mkdir -p "$final_path/tmp/pids"
|
|
|
|
mkdir "$final_path/tmp/sockets"
|
|
|
|
|
2019-03-15 19:50:18 +01:00
|
|
|
# Create specific folders and links for subfolder compatibility
|
|
|
|
# (see: https://meta.discourse.org/t/subfolder-support-with-docker/30507)
|
|
|
|
(
|
|
|
|
cd $final_path
|
|
|
|
mkdir -p "public/forum"
|
|
|
|
cd public/forum && ln -s ../uploads && ln -s ../backups
|
|
|
|
)
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
# Set permissions to app files
|
|
|
|
chown -R $app: $final_path
|
2020-04-27 13:41:00 +02:00
|
|
|
|
2018-05-23 21:22:00 +02:00
|
|
|
# Restrict rights to log directory (needed by logrotate)
|
|
|
|
chmod g-w $final_path/log
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring log rotation..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_use_logrotate --logfile="$final_path/log/unicorn.stderr.log"
|
|
|
|
ynh_use_logrotate --logfile="$final_path/log/unicorn.stdout.log"
|
|
|
|
ynh_use_logrotate --logfile="$final_path/log/production.log"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Integrating service in YunoHost..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2018-05-23 21:22:00 +02:00
|
|
|
yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log"
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready"
|
|
|
|
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Configuring SSOwat..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
|
2018-04-02 16:36:02 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Reloading nginx web server..."
|
2018-04-02 16:36:02 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-04-02 16:36:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# END OF SCRIPT
|
2018-04-02 16:36:02 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_print_info --message="Installation of $app completed"
|