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-02-29 10:11:40 +01:00
|
|
|
ynh_script_progression --message="Installing Ruby..." --weight=5
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
|
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=5
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
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
|
|
|
#=================================================
|
2022-09-26 02:56:12 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
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-02-29 10:33:15 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
2024-02-29 10:11:40 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2015-05-30 23:06:45 +02:00
|
|
|
|
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-02-29 10:11:40 +01:00
|
|
|
ynh_script_progression --message="Adding $app's configuration file..." --weight=1
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-07-01 02:07:18 +02:00
|
|
|
ynh_add_config --template="diaspora.toml" --destination="$install_dir/live/config/diaspora.toml"
|
|
|
|
chmod 400 "$install_dir/live/config/diaspora.toml"
|
|
|
|
chown "$app:$app" "$install_dir/live/config/diaspora.toml"
|
2022-09-26 02:56:12 +02:00
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
ynh_add_config --template="database.yml" --destination="$install_dir/live/config/database.yml"
|
|
|
|
chmod 400 "$install_dir/live/config/database.yml"
|
|
|
|
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
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Building app..." --weight=40
|
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
pushd "$install_dir/live"
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_use_ruby
|
|
|
|
ynh_use_nodejs
|
2024-02-29 10:11:40 +01:00
|
|
|
ynh_gem install "bundler:$bundler_version"
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" script/configure_bundler
|
2024-07-01 02:07:28 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install --full-index
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/rake db:migrate
|
2024-02-29 10:11:40 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/rake assets:precompile
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_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-02-29 10:11:40 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
# Create a dedicated systemd config
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_web" --template="diaspora_web.service"
|
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
# Create target unit
|
|
|
|
_ynh_add_systemd_target
|
2024-07-01 10:20:45 +02:00
|
|
|
yunohost service add "$app.target" --description "Diaspora service (web and sidekiq)" \
|
2024-02-29 10:11:40 +01:00
|
|
|
--log "$install_dir/live/log/production.log" \
|
2024-07-01 10:20:45 +02:00
|
|
|
"$install_dir/live/log/web-stderr.log" \
|
|
|
|
"$install_dir/live/log/web-stdout.log" \
|
2024-02-29 10:11:40 +01:00
|
|
|
"$install_dir/live/log/sidekiq.log"
|
2015-02-17 03:39:33 +01:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
# Create tmpfile
|
|
|
|
ynh_add_config --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf"
|
|
|
|
systemd-tmpfiles --create
|
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-02-29 10:11:40 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
systemctl restart "${app}.target"
|
|
|
|
ynh_systemd_action --service_name="${app}_web.service" --action=restart --log_path="$install_dir/live/log/production.log" --line_match="successfully configured the federation library"
|
|
|
|
ynh_systemd_action --service_name="${app}_sidekiq.service" --action=restart --log_path="systemd" --line_match="Running in ruby"
|
2022-05-29 12:45:09 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
2019-12-16 11:11:02 +01:00
|
|
|
#=================================================
|
|
|
|
|
2022-09-26 02:56:12 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|