1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/acropolis_ynh.git synced 2024-09-03 18:06:22 +02:00
acropolis_ynh/scripts/install

121 lines
4.6 KiB
Text
Raw Normal View History

2021-11-10 19:58:54 +01:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2024-03-29 13:04:55 +01:00
source ynh_ruby
2021-11-15 20:16:45 +01:00
source ynh_add_swap
2021-11-10 19:58:54 +01:00
source /usr/share/yunohost/helpers
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Installing Ruby..." --weight=1
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION"
2021-11-10 19:58:54 +01:00
#=================================================
2021-11-15 20:16:45 +01:00
# ADD SWAP IF NEEDED
2021-11-10 19:58:54 +01:00
#=================================================
2021-11-15 20:16:45 +01:00
ynh_script_progression --message="Adding swap if needed..."
total_memory=$(ynh_get_ram --total)
swap_needed=0
2023-10-04 12:18:39 +02:00
if (( MEMORY_NEEDED > total_memory )); then
2024-03-29 11:34:46 +01:00
# Need a minimum of 2.5Go of memory
swap_needed=$((MEMORY_NEEDED - total_memory))
2021-11-15 20:16:45 +01:00
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
# CREATE A POSTGRESQL DATABASE
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Setting the PostgreSQL database..."
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01: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"
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Setting up source files..." --weight=1
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
ynh_setup_source --dest_dir="$install_dir"
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
mkdir -p "$install_dir/tmp/pids"
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
# ADD A CONFIGURATION
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
ynh_add_config --template="database.yml.example" --destination="$install_dir/config/database.yml"
ynh_add_config --template="diaspora.toml.example" --destination="$install_dir/config/diaspora.toml"
chmod 400 "$install_dir/config/database.yml"
chmod 400 "$install_dir/config/diaspora.toml"
chown "$app:$app" "$install_dir/config/database.yml"
chown "$app:$app" "$install_dir/config/diaspora.toml"
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
# INSTALLING RUBY AND BUNDLER
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Building $app..."
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
pushd "$install_dir"
2024-03-29 11:34:46 +01:00
ynh_use_ruby
ynh_gem install bundler:1.17.3 --no-document
ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
ynh_exec_as "$app" chmod +x script/server
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" script/configure_bundler
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config set path 'vendor/bundle'
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install --full-index
2021-11-10 19:58:54 +01:00
popd
2021-12-29 19:43:52 +01:00
ynh_script_progression --message="Preparing the database and create initial admin user..."
2021-11-10 19:58:54 +01:00
2023-10-04 12:18:39 +02:00
pushd "$install_dir"
2024-03-29 11:34:46 +01:00
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake db:migrate
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:precompile
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]"
2021-12-27 09:02:57 +01:00
popd
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
# SYSTEM CONFIGURATION
2021-11-10 19:58:54 +01:00
#=================================================
2024-03-29 11:34:46 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
ynh_add_nginx_config
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
ynh_add_systemd_config --service="$app-web" --template="$app-web.service"
2021-11-10 19:58:54 +01:00
yunohost service add "$app-web" --description="$app web service"
2024-03-29 11:34:46 +01:00
ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service"
2021-11-10 19:58:54 +01:00
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
2024-03-29 11:34:46 +01:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
2021-11-10 19:58:54 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-11-10 19:58:54 +01:00
2024-03-29 11:34:46 +01:00
ynh_systemd_action --service_name="${app}-web" --action="start" --log_path=systemd --line_match="listening on"
ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path=systemd --line_match="Booted Rails"
2021-11-10 19:58:54 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last