#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INITIALIZE AND STORE SETTINGS #================================================= admin_mail=$(ynh_user_get_info --username=$admin --key=mail) #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing Ruby..." --weight=5 ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_script_progression --message="Installing NodeJS..." --weight=5 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/live" # create upload folder and link it mkdir -p "$install_dir/uploads" ln -s "$install_dir/uploads" "$install_dir/live/public" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding $app's configuration file..." --weight=1 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" 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" #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building app..." --weight=40 pushd "$install_dir/live" ynh_use_ruby ynh_use_nodejs ynh_gem install "bundler:$bundler_version" ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" script/configure_bundler 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 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 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 #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service" ynh_add_systemd_config --service="${app}_web" --template="diaspora_web.service" # Create target unit _ynh_add_systemd_target yunohost service add "$app.target" --description "Diaspora service (web and sidekiq)" \ --log "$install_dir/live/log/production.log" \ "$install_dir/live/log/web-stderr.log" \ "$install_dir/live/log/web-stdout.log" \ "$install_dir/live/log/sidekiq.log" # Create tmpfile ynh_add_config --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf" systemd-tmpfiles --create #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting $app's systemd service..." --weight=1 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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last