2015-02-17 03:39:33 +01:00
#!/bin/bash
2017-08-06 19:56:16 +02:00
#=================================================
2017-06-09 15:45:50 +02:00
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2017-08-06 19:56:16 +02:00
#=================================================
2024-02-29 10:11:40 +01:00
# INITIALIZE AND STORE SETTINGS
2017-08-06 19:56:16 +02:00
#=================================================
2017-06-09 13:06:41 +02:00
2022-09-26 02:56:12 +02:00
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
2017-08-06 19:56:16 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Installing Ruby..."
ynh_ruby_install
2022-05-29 12:45:09 +02:00
2024-08-30 22:47:53 +02:00
ynh_script_progression "Installing NodeJS..."
ynh_nodejs_install
2020-05-17 15:53:04 +02:00
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2017-08-06 19:56:16 +02:00
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Setting up source files..."
2015-02-17 03:39:33 +01:00
2022-05-29 12:45:09 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2024-02-29 10:11:40 +01:00
ynh_setup_source --dest_dir="$install_dir/live"
2023-03-15 20:29:17 +01:00
# create upload folder and link it
2024-02-29 10:11:40 +01:00
mkdir -p "$install_dir/uploads"
ln -s "$install_dir/uploads" "$install_dir/live/public"
2022-05-29 12:45:09 +02:00
2024-08-30 22:47:53 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
# ADD A CONFIGURATION
2019-12-02 21:01:24 +01:00
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Adding $app's configuration file..."
2022-05-29 12:45:09 +02:00
2024-08-30 22:47:53 +02:00
ynh_config_add --template="diaspora.yml" --destination="$install_dir/live/config/diaspora.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/live/config/diaspora.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/live/config/diaspora.yml"
2022-09-26 02:56:12 +02:00
2024-08-30 22:47:53 +02:00
ynh_config_add --template="database.yml" --destination="$install_dir/live/config/database.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/live/config/database.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/live/config/database.yml"
2015-05-30 23:06:45 +02:00
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
# BUILD APP
2019-12-02 21:01:24 +01:00
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Building app..."
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
pushd "$install_dir/live"
2024-08-30 22:47:53 +02:00
gem install "bundler:$bundler_version"
ynh_hide_warnings ynh_exec_as_app ruby_load_path" "$ld_preload" script/configure_bundler
ynh_hide_warnings ynh_exec_as_app ruby_load_path" "$ld_preload" bin/bundle install --full-index --with=postgresql
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" "$ld_preload" bin/bundle exec rake db:migrate
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" "$ld_preload" bin/rake assets:precompile
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" "$ld_preload" bin/bundle exec rails console << END
2022-05-29 12:45:09 +02:00
user = User.build({username: '$admin', email: '$admin_mail', password: '$password', password_confirmation: '$password' })
user.save
user.seed_aspects
Role.add_admin user.person
END
popd
2019-12-02 21:01:24 +01:00
#=================================================
2024-02-29 10:11:40 +01:00
# SYSTEM CONFIGURATION
2019-12-02 21:01:24 +01:00
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Adding system configurations related to $app..."
2024-02-29 10:11:40 +01:00
# Create a dedicated NGINX config
2024-08-30 22:47:53 +02:00
ynh_config_add_nginx
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
# Create a dedicated systemd config
2024-08-30 22:47:53 +02:00
ynh_config_add_systemd --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
ynh_config_add_systemd --service="${app}_web" --template="diaspora_web.service"
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
# Create target unit
_ynh_add_systemd_target
yunohost service add "$app.target" --description "Diaspora service (unicorn web and sidekiq)" \
--log "$install_dir/live/log/production.log" \
"$install_dir/live/log/unicorn-stderr.log" \
"$install_dir/live/log/unicorn-stdout.log" \
"$install_dir/live/log/sidekiq.log"
2015-02-17 03:39:33 +01:00
2024-02-29 10:33:15 +01:00
# Create tmpfile
2024-08-30 22:47:53 +02:00
ynh_config_add --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf"
2024-02-29 10:33:15 +01:00
systemd-tmpfiles --create
2022-05-29 12:45:09 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Starting $app's systemd service..."
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
systemctl restart "${app}.target"
2024-08-30 22:47:53 +02:00
ynh_systemctl --service="${app}_web.service" --action=restart --log_path="$install_dir/live/log/production.log" --wait_until="successfully configured the federation library"
ynh_systemctl --service="${app}_sidekiq.service" --action=restart --log_path="systemd" --wait_until="Running in ruby"
2022-05-29 12:45:09 +02:00
#=================================================
# END OF SCRIPT
2019-12-16 11:11:02 +01:00
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Installation of $app completed"